Commit 31b3e219 authored by Ikram Haq's avatar Ikram Haq
Browse files

Add appProfile attribute functionality in registration endpoint

parent 1aafa095
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import (
	"fmt"
	"net/http"
	"net/url"
	"reflect"
	"strconv"
	"sync"
	"time"
@@ -686,6 +687,25 @@ func appRegistrationPOST(w http.ResponseWriter, r *http.Request) {
		errHandlerProblemDetails(w, "Endpoint shall be present when IsInsByMec is FALSE.", http.StatusBadRequest)
		return
	}
	// Process appProfile if present
	if appInfo.AppProfile != nil {
		// Validate appProvider, endpoint, and other fields as per mapping to EASProfile
		if appInfo.AppProvider != appInfo.AppProfile.ProvId {
			log.Error("appProvider in AppInfo does not match provId in appProfile")
			errHandlerProblemDetails(w, "appProvider and provId must be consistent", http.StatusBadRequest)
			return
		}

		if appInfo.AppProfile != nil {
			if !reflect.DeepEqual(getEndpointUris(appInfo.Endpoint), getProfileEndpointUris(appInfo.AppProfile.EndPt)) {
				log.Error("endpoint in AppInfo does not match endPt in appProfile")
				errHandlerProblemDetails(w, "Endpoint and endPt must be consistent", http.StatusBadRequest)
				return
			}
		}

		// Additional consistency checks for fields like scheds, svcArea, etc., based on appProfile attributes
	}

	// Get App instance
	log.Info("appRegistrationPOST: appInfo.AppInstanceId: ", appInfo.AppInstanceId)
@@ -731,6 +751,24 @@ func appRegistrationPOST(w http.ResponseWriter, r *http.Request) {
	fmt.Fprint(w, jsonResponse)
}

func getEndpointUris(endpoint *OneOfAppInfoEndpoint) []string {
	if endpoint == nil {
		return nil
	}

	// Access the `Uris` field directly from `EndPointInfoUris`
	return endpoint.EndPointInfoUris.Uris
}

func getProfileEndpointUris(endPt *OneOfAppProfileEndPt) []string {
	if endPt == nil {
		return nil
	}

	// Access the `Uris` field directly from `EndPointInfoUris`
	return endPt.EndPointInfoUris.Uris
}

/*
* appRegistrationGET handles retrieving the registration information of an application.
* It fetches the appInstanceId from the URL variables, retrieves the associated application info from Redis, and sends it back in the response. If the appInstanceId is not found or an error occurs, it responds with the appropriate status and error message.