3 // ========================LICENSE_START=================================
6 // Copyright (C) 2023: Nordix Foundation
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 // ========================LICENSE_END===================================
28 "github.com/labstack/echo/v4"
29 log "github.com/sirupsen/logrus"
30 invokerapi "oransc.org/nonrtric/capifinvoker/internal/invokermanagementapi"
33 func OnboardingInvokerHandler(c echo.Context) error {
34 return c.Render(http.StatusOK, "onboardinvoker.html", map[string]interface{}{
40 func OnboardInvoker(server string) echo.HandlerFunc {
41 return func(c echo.Context) error {
43 url := server + "/api-invoker-management/v1/onboardedInvokers"
44 log.Infof("[Register invoker] url to capif core %v\n", url)
46 var newInvoker invokerapi.APIInvokerEnrolmentDetails
47 fmt.Printf("Getting enrolment details from UI:: %+v", c.FormValue("enrolmentDetails"))
48 err := json.Unmarshal([]byte(c.FormValue("enrolmentDetails")), &newInvoker)
50 fmt.Printf("error: %+v", err)
51 log.Error("[Register invoker] error unmarshaling parameter enrolmentDetails as JSON")
52 return c.Render(http.StatusBadRequest, "onboardinvoker.html", map[string]interface{}{
55 "response": "Error unmarshaling parameter enrolmentDetails as JSON",
59 headers := map[string]string{
60 "Content-Type": "application/json",
62 jsonBytes, err := json.Marshal(newInvoker)
64 return c.Render(http.StatusBadRequest, "onboardinvoker.html", map[string]interface{}{
67 "response": "Error marshaling parameter enrolmentDetails before doing request",
71 resp, err := makeRequest("POST", url, headers, bytes.NewReader(jsonBytes))
73 log.Errorf("[Register invoker] %v", fmt.Sprintf("error: %v", err))
74 return c.Render(http.StatusBadRequest, "onboardinvoker.html", map[string]interface{}{
77 "response": fmt.Sprintf("error: %v", err),
81 var resInvoker invokerapi.APIInvokerEnrolmentDetails
82 err = json.Unmarshal(resp, &resInvoker)
84 log.Error("[Register invoker] error unmarshaling response enrolmentDetails as JSON")
85 return c.Render(http.StatusBadRequest, "onboardinvoker.html", map[string]interface{}{
88 "response": "error unmarshaling parameter enrolmentDetails as JSON",
92 bytes, _ := json.Marshal(resInvoker)
93 log.Infof("[Register invoker] new invoker register with id %v\n", *resInvoker.ApiInvokerId)
94 return c.Render(http.StatusOK, "onboardinvoker.html", map[string]interface{}{
97 "response": string(bytes),