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===================================
27 "github.com/labstack/echo/v4"
28 log "github.com/sirupsen/logrus"
29 "oransc.org/nonrtric/capifprov/internal/providermanagementapi"
32 func RegistrationHandler(c echo.Context) error {
33 return c.Render(http.StatusOK, "registration.html", map[string]interface{}{
39 func RegistrationFormHandler(server string) echo.HandlerFunc {
40 return func(c echo.Context) error {
42 url := server + "/api-provider-management/v1/registrations"
43 log.Infof("[Register provider] url to capif core %v\n", url)
45 var newProvider providermanagementapi.APIProviderEnrolmentDetails
46 err := json.Unmarshal([]byte(c.FormValue("enrolmentDetails")), &newProvider)
48 log.Error("[Register provider] error unmarshaling parameter enrolmentDetails as JSON")
49 return c.Render(http.StatusBadRequest, "registration.html", map[string]interface{}{
52 "response": "Error unmarshaling parameter enrolmentDetails as JSON",
56 headers := map[string]string{
57 "Content-Type": "application/json",
59 resp, err := makeRequest("POST", url, headers, newProvider)
61 log.Errorf("[Register provider] %v", fmt.Sprintf("error: %v", err))
62 return c.Render(http.StatusBadRequest, "registration.html", map[string]interface{}{
65 "response": fmt.Sprintf("error: %v", err),
69 var resProvider providermanagementapi.APIProviderEnrolmentDetails
70 err = json.Unmarshal(resp, &resProvider)
72 log.Error("[Register provider] error unmarshaling parameter enrolmentDetails as JSON")
73 return c.Render(http.StatusBadRequest, "registration.html", map[string]interface{}{
76 "response": "error unmarshaling parameter enrolmentDetails as JSON",
80 bytes, _ := json.Marshal(resProvider)
81 log.Infof("[Register provider] Api Provider domain %v has been register\n", resProvider.ApiProvDomId)
82 return c.Render(http.StatusOK, "registration.html", map[string]interface{}{
85 "response": string(bytes),