Loading examples/demo3/src/server/demo3_service.go +7 −1 Original line number Diff line number Diff line Loading @@ -345,7 +345,13 @@ func amsNotificationPOST(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } notifyUrl := serviceInfo[0].TransportInfo.Endpoint.Uris[0] var notifyUrl string for i := 0; i < len(serviceInfo); i++ { if serviceInfo[i].SerName == serviceName { notifyUrl = serviceInfo[i].TransportInfo.Endpoint.Uris[0] } } sendContextTransfer(notifyUrl, amsNotification.TargetAppInfo.AppInstanceId) Loading go-apps/meep-app-enablement/server/service-mgmt/service-mgmt.go +69 −30 Original line number Diff line number Diff line Loading @@ -203,19 +203,17 @@ func appServicesGET(w http.ResponseWriter, r *http.Request) { mutex.Lock() defer mutex.Unlock() // Validate App Instance ID // Do not validate app instance id in order to find url of ams service on anther mec platform // err, code, problemDetails := validateAppInstanceId(appInstanceId) // if err != nil { // log.Error(err.Error()) // if problemDetails != "" { // w.WriteHeader(code) // fmt.Fprintf(w, problemDetails) // } else { // http.Error(w, err.Error(), code) // } // return // } err, code, problemDetails := validateAppInstanceId(appInstanceId, false) if err != nil { log.Error(err.Error()) if problemDetails != "" { w.WriteHeader(code) fmt.Fprintf(w, problemDetails) } else { http.Error(w, err.Error(), code) } return } getServices(w, r, appInstanceId) } Loading Loading @@ -262,7 +260,7 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -370,7 +368,7 @@ func appServicesByIdDELETE(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -423,7 +421,7 @@ func appServicesByIdGET(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, false) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading @@ -449,7 +447,7 @@ func appServicesByIdPUT(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -548,7 +546,7 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -654,7 +652,7 @@ func applicationsSubscriptionGET(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -689,7 +687,7 @@ func applicationsSubscriptionDELETE(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -728,7 +726,7 @@ func applicationsSubscriptionsGET(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -949,7 +947,7 @@ func getService(w http.ResponseWriter, r *http.Request, appInstanceId string, se if appInstanceId == "" { key = baseKeyGlobal + ":app:*:svc:" + serviceId } else { key = baseKey + ":app:" + appInstanceId + ":svc:" + serviceId key = baseKeyGlobal + ":app:" + appInstanceId + ":svc:" + serviceId } err := rc.ForEachJSONEntry(key, populateServiceInfoList, &sInfoList) Loading @@ -966,7 +964,7 @@ func getService(w http.ResponseWriter, r *http.Request, appInstanceId string, se } // Prepare & send response jsonResponse, err := json.Marshal(sInfoList.Services) jsonResponse, err := json.Marshal(sInfoList.Services[0]) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) Loading Loading @@ -1318,16 +1316,57 @@ func validateServiceQueryParams(serInstanceId []string, serName []string, serCat return nil } func validateAppInstanceId(appInstanceId string) (error, int, string) { // Get application instance func populateAppValues(key string, redisEntry map[string]string, data interface{}) error { appInfoList := data.(*[]map[string]string) appEntries := make(map[string]string) if data == nil { return errors.New("App instance lookup error") } for k := range redisEntry { redisEntryValue := redisEntry[k] appEntries[k] = redisEntryValue } s := *appInfoList *appInfoList = append(s, appEntries) return nil } func validateAppInstanceId(appInstanceId string, localMepOnly bool) (error, int, string) { var appInfoState string // Validate app instance by if app is local to mep or global lookup if localMepOnly { // Get application instance by local base key key := baseKey + ":app:" + appInstanceId + ":info" fields, err := rc.GetEntry(key) if err != nil || len(fields) == 0 { return errors.New("App Instance not found"), http.StatusNotFound, "" } appInfoState = fields[fieldState] } else { // Get application instance by global key with additional wild card key := baseKeyGlobal + ":app:" + appInstanceId + ":info" var appInfoList []map[string]string err := rc.ForEachEntry(key, populateAppValues, &appInfoList) if err != nil { log.Error(err) return err, http.StatusInternalServerError, "" } // There should be one unique app instance found if len(appInfoList) > 1 { return errors.New("App Instance not found"), http.StatusNotFound, "" } appInfos := appInfoList[0] appInfoState = appInfos[fieldState] } // Make sure App is in ready state if fields[fieldState] != APP_STATE_READY { if appInfoState != APP_STATE_READY { var problemDetails ProblemDetails problemDetails.Status = http.StatusForbidden problemDetails.Detail = "App Instance not ready. Waiting for AppReadyConfirmation." Loading Loading
examples/demo3/src/server/demo3_service.go +7 −1 Original line number Diff line number Diff line Loading @@ -345,7 +345,13 @@ func amsNotificationPOST(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } notifyUrl := serviceInfo[0].TransportInfo.Endpoint.Uris[0] var notifyUrl string for i := 0; i < len(serviceInfo); i++ { if serviceInfo[i].SerName == serviceName { notifyUrl = serviceInfo[i].TransportInfo.Endpoint.Uris[0] } } sendContextTransfer(notifyUrl, amsNotification.TargetAppInfo.AppInstanceId) Loading
go-apps/meep-app-enablement/server/service-mgmt/service-mgmt.go +69 −30 Original line number Diff line number Diff line Loading @@ -203,19 +203,17 @@ func appServicesGET(w http.ResponseWriter, r *http.Request) { mutex.Lock() defer mutex.Unlock() // Validate App Instance ID // Do not validate app instance id in order to find url of ams service on anther mec platform // err, code, problemDetails := validateAppInstanceId(appInstanceId) // if err != nil { // log.Error(err.Error()) // if problemDetails != "" { // w.WriteHeader(code) // fmt.Fprintf(w, problemDetails) // } else { // http.Error(w, err.Error(), code) // } // return // } err, code, problemDetails := validateAppInstanceId(appInstanceId, false) if err != nil { log.Error(err.Error()) if problemDetails != "" { w.WriteHeader(code) fmt.Fprintf(w, problemDetails) } else { http.Error(w, err.Error(), code) } return } getServices(w, r, appInstanceId) } Loading Loading @@ -262,7 +260,7 @@ func appServicesPOST(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -370,7 +368,7 @@ func appServicesByIdDELETE(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -423,7 +421,7 @@ func appServicesByIdGET(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, false) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading @@ -449,7 +447,7 @@ func appServicesByIdPUT(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -548,7 +546,7 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -654,7 +652,7 @@ func applicationsSubscriptionGET(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -689,7 +687,7 @@ func applicationsSubscriptionDELETE(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -728,7 +726,7 @@ func applicationsSubscriptionsGET(w http.ResponseWriter, r *http.Request) { defer mutex.Unlock() // Validate App Instance ID err, code, problemDetails := validateAppInstanceId(appInstanceId) err, code, problemDetails := validateAppInstanceId(appInstanceId, true) if err != nil { log.Error(err.Error()) if problemDetails != "" { Loading Loading @@ -949,7 +947,7 @@ func getService(w http.ResponseWriter, r *http.Request, appInstanceId string, se if appInstanceId == "" { key = baseKeyGlobal + ":app:*:svc:" + serviceId } else { key = baseKey + ":app:" + appInstanceId + ":svc:" + serviceId key = baseKeyGlobal + ":app:" + appInstanceId + ":svc:" + serviceId } err := rc.ForEachJSONEntry(key, populateServiceInfoList, &sInfoList) Loading @@ -966,7 +964,7 @@ func getService(w http.ResponseWriter, r *http.Request, appInstanceId string, se } // Prepare & send response jsonResponse, err := json.Marshal(sInfoList.Services) jsonResponse, err := json.Marshal(sInfoList.Services[0]) if err != nil { log.Error(err.Error()) http.Error(w, err.Error(), http.StatusInternalServerError) Loading Loading @@ -1318,16 +1316,57 @@ func validateServiceQueryParams(serInstanceId []string, serName []string, serCat return nil } func validateAppInstanceId(appInstanceId string) (error, int, string) { // Get application instance func populateAppValues(key string, redisEntry map[string]string, data interface{}) error { appInfoList := data.(*[]map[string]string) appEntries := make(map[string]string) if data == nil { return errors.New("App instance lookup error") } for k := range redisEntry { redisEntryValue := redisEntry[k] appEntries[k] = redisEntryValue } s := *appInfoList *appInfoList = append(s, appEntries) return nil } func validateAppInstanceId(appInstanceId string, localMepOnly bool) (error, int, string) { var appInfoState string // Validate app instance by if app is local to mep or global lookup if localMepOnly { // Get application instance by local base key key := baseKey + ":app:" + appInstanceId + ":info" fields, err := rc.GetEntry(key) if err != nil || len(fields) == 0 { return errors.New("App Instance not found"), http.StatusNotFound, "" } appInfoState = fields[fieldState] } else { // Get application instance by global key with additional wild card key := baseKeyGlobal + ":app:" + appInstanceId + ":info" var appInfoList []map[string]string err := rc.ForEachEntry(key, populateAppValues, &appInfoList) if err != nil { log.Error(err) return err, http.StatusInternalServerError, "" } // There should be one unique app instance found if len(appInfoList) > 1 { return errors.New("App Instance not found"), http.StatusNotFound, "" } appInfos := appInfoList[0] appInfoState = appInfos[fieldState] } // Make sure App is in ready state if fields[fieldState] != APP_STATE_READY { if appInfoState != APP_STATE_READY { var problemDetails ProblemDetails problemDetails.Status = http.StatusForbidden problemDetails.Detail = "App Instance not ready. Waiting for AppReadyConfirmation." Loading