From 4e578fd2e6e5c4bf4e4357dad4595181a1c43dc5 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 25 Jun 2024 07:50:25 +0000 Subject: [PATCH] fix: fix wrong file name & fix implementation of processor follow standard --- internal/sbi/api_eventexposure.go | 29 +- internal/sbi/api_httpcallback.go | 11 +- internal/sbi/api_parameterprovision.go | 11 +- internal/sbi/api_subscriberdatamanagement.go | 274 +----------- internal/sbi/api_ueauthentication.go | 29 +- internal/sbi/api_uecontextmanagement.go | 131 +----- .../{enent_exposure.go => event_exposure.go} | 46 +- internal/sbi/processor/generate_auth_data.go | 117 ++++-- internal/sbi/processor/notifier.go | 11 +- internal/sbi/processor/parameter_provision.go | 23 +- .../processor/subscriber_data_management.go | 396 ++++++++++-------- .../sbi/processor/ue_context_management.go | 188 +++++---- 12 files changed, 489 insertions(+), 777 deletions(-) rename internal/sbi/processor/{enent_exposure.go => event_exposure.go} (83%) diff --git a/internal/sbi/api_eventexposure.go b/internal/sbi/api_eventexposure.go index 056b0df..1c0290e 100644 --- a/internal/sbi/api_eventexposure.go +++ b/internal/sbi/api_eventexposure.go @@ -78,30 +78,14 @@ func (s *Server) HandleCreateEeSubscription(c *gin.Context) { ueIdentity := c.Params.ByName("ueIdentity") - createdEESubscription, problemDetails := s.Processor().CreateEeSubscriptionProcedure(ueIdentity, eesubscription) - if createdEESubscription != nil { - c.JSON(http.StatusCreated, createdEESubscription) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "UNSPECIFIED_NF_FAILURE", - } - c.JSON(http.StatusInternalServerError, problemDetails) - return - } + s.Processor().CreateEeSubscriptionProcedure(c, ueIdentity, eesubscription) } func (s *Server) HandleDeleteEeSubscription(c *gin.Context) { ueIdentity := c.Params.ByName("ueIdentity") subscriptionID := c.Params.ByName("subscriptionId") - s.Processor().DeleteEeSubscriptionProcedure(ueIdentity, subscriptionID) - // only return 204 no content - c.Status(http.StatusNoContent) + s.Processor().DeleteEeSubscriptionProcedure(c, ueIdentity, subscriptionID) } func (s *Server) HandleUpdateEeSubscription(c *gin.Context) { @@ -139,14 +123,7 @@ func (s *Server) HandleUpdateEeSubscription(c *gin.Context) { logger.EeLog.Infoln("Handle Update EE subscription") logger.EeLog.Warnln("Update EE Subscription is not implemented") - problemDetails := s.Processor().UpdateEeSubscriptionProcedure(ueIdentity, subscriptionID, patchList) - if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().UpdateEeSubscriptionProcedure(c, ueIdentity, subscriptionID, patchList) } func (s *Server) HandleIndex(c *gin.Context) { diff --git a/internal/sbi/api_httpcallback.go b/internal/sbi/api_httpcallback.go index b07e2b1..1f3d558 100644 --- a/internal/sbi/api_httpcallback.go +++ b/internal/sbi/api_httpcallback.go @@ -63,14 +63,5 @@ func (s *Server) HandleDataChangeNotificationToNF(c *gin.Context) { logger.CallbackLog.Infof("Handle DataChangeNotificationToNF") - problemDetails := s.Processor().DataChangeNotificationProcedure(dataChangeNotify.NotifyItems, supi) - - // step 4: process the return value from step 3 - if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().DataChangeNotificationProcedure(c, dataChangeNotify.NotifyItems, supi) } diff --git a/internal/sbi/api_parameterprovision.go b/internal/sbi/api_parameterprovision.go index b272ec6..7badc40 100644 --- a/internal/sbi/api_parameterprovision.go +++ b/internal/sbi/api_parameterprovision.go @@ -65,14 +65,5 @@ func (s *Server) HandleUpdate(c *gin.Context) { logger.PpLog.Infoln("Handle UpdateRequest") // step 3: handle the message - problemDetails := s.Processor().UpdateProcedure(ppDataReq, gpsi) - - // step 4: process the return value from step 3 - if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().UpdateProcedure(c, ppDataReq, gpsi) } diff --git a/internal/sbi/api_subscriberdatamanagement.go b/internal/sbi/api_subscriberdatamanagement.go index 26392ff..547b684 100644 --- a/internal/sbi/api_subscriberdatamanagement.go +++ b/internal/sbi/api_subscriberdatamanagement.go @@ -45,24 +45,7 @@ func (s *Server) HandleGetAmData(c *gin.Context) { supportedFeatures := query.Get("supported-features") // step 3: handle the message - response, problemDetails := s.Processor().GetAmDataProcedure(supi, plmnID, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetAmDataProcedure(c, supi, plmnID, supportedFeatures) } func (s *Server) getPlmnIDStruct( @@ -116,24 +99,7 @@ func (s *Server) HandleGetSmfSelectData(c *gin.Context) { supportedFeatures := query.Get("supported-features") // step 3: handle the message - response, problemDetails := s.Processor().GetSmfSelectDataProcedure(supi, plmnID, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetSmfSelectDataProcedure(c, supi, plmnID, supportedFeatures) } // GetSmsMngData - retrieve a UE's SMS Management Subscription Data @@ -168,24 +134,7 @@ func (s *Server) HandleGetSupi(c *gin.Context) { supportedFeatures := query.Get("supported-features") // step 3: handle the message - response, problemDetails := s.Processor().GetSupiProcedure(supi, plmnID, dataSetNames, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetSupiProcedure(c, supi, plmnID, dataSetNames, supportedFeatures) } // GetSharedData - retrieve shared data @@ -197,24 +146,7 @@ func (s *Server) HandleGetSharedData(c *gin.Context) { sharedDataIds := c.QueryArray("shared-data-ids") supportedFeatures := c.QueryArray("supported-features") // step 3: handle the message - response, problemDetails := s.Processor().GetSharedDataProcedure(sharedDataIds, supportedFeatures[0]) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetSharedDataProcedure(c, sharedDataIds, supportedFeatures[0]) } // SubscribeToSharedData - subscribe to notifications for shared data @@ -254,30 +186,7 @@ func (s *Server) HandleSubscribeToSharedData(c *gin.Context) { // step 2: retrieve request // step 3: handle the message - header, response, problemDetails := s.Processor().SubscribeToSharedDataProcedure(&sharedDataSubsReq) - - // var rsp *httpwrapper.Response - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - // step 5: response - for key, val := range header { // header response is optional - c.Header(key, val[0]) - } - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails := models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "SYSTEM_FAILURE", - Detail: err.Error(), - } - c.JSON(http.StatusInternalServerError, problemDetails) - return - } + s.Processor().SubscribeToSharedDataProcedure(c, &sharedDataSubsReq) } // Subscribe - subscribe to notifications @@ -319,23 +228,7 @@ func (s *Server) HandleSubscribe(c *gin.Context) { supi := c.Params.ByName("supi") // step 3: handle the message - header, response, problemDetails := s.Processor().SubscribeProcedure(&sdmSubscriptionReq, supi) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - for key, val := range header { // header response is optional - c.Header(key, val[0]) - } - c.JSON(http.StatusCreated, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNotFound) - return - } + s.Processor().SubscribeProcedure(c, &sdmSubscriptionReq, supi) } // Unsubscribe - unsubscribe from notifications @@ -347,16 +240,7 @@ func (s *Server) HandleUnsubscribe(c *gin.Context) { subscriptionID := c.Params.ByName("subscriptionId") // step 3: handle the message - problemDetails := s.Processor().UnsubscribeProcedure(supi, subscriptionID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().UnsubscribeProcedure(c, supi, subscriptionID) } // UnsubscribeForSharedData - unsubscribe from notifications for shared data @@ -366,16 +250,7 @@ func (s *Server) HandleUnsubscribeForSharedData(c *gin.Context) { // step 2: retrieve request subscriptionID := c.Params.ByName("subscriptionId") // step 3: handle the message - problemDetails := s.Processor().UnsubscribeForSharedDataProcedure(subscriptionID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().UnsubscribeForSharedDataProcedure(c, subscriptionID) } // Modify - modify the subscription @@ -417,24 +292,7 @@ func (s *Server) HandleModify(c *gin.Context) { subscriptionID := c.Params.ByName("subscriptionId") // step 3: handle the message - response, problemDetails := s.Processor().ModifyProcedure(&sdmSubsModificationReq, supi, subscriptionID) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().ModifyProcedure(c, &sdmSubsModificationReq, supi, subscriptionID) } // ModifyForSharedData - modify the subscription @@ -476,24 +334,7 @@ func (s *Server) HandleModifyForSharedData(c *gin.Context) { subscriptionID := c.Params.ByName("subscriptionId") // step 3: handle the message - response, problemDetails := s.Processor().ModifyForSharedDataProcedure(&sharedDataSubscriptions, supi, subscriptionID) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().ModifyForSharedDataProcedure(c, &sharedDataSubscriptions, supi, subscriptionID) } // GetTraceData - retrieve a UE's Trace Configuration Data @@ -506,24 +347,7 @@ func (s *Server) HandleGetTraceData(c *gin.Context) { plmnID := c.Query("plmn-id") // step 3: handle the message - response, problemDetails := s.Processor().GetTraceDataProcedure(supi, plmnID) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetTraceDataProcedure(c, supi, plmnID) } // GetUeContextInSmfData - retrieve a UE's UE Context In SMF Data @@ -536,24 +360,7 @@ func (s *Server) HandleGetUeContextInSmfData(c *gin.Context) { supportedFeatures := c.Query("supported-features") // step 3: handle the message - response, problemDetails := s.Processor().GetUeContextInSmfDataProcedure(supi, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetUeContextInSmfDataProcedure(c, supi, supportedFeatures) } // GetUeContextInSmsfData - retrieve a UE's UE Context In SMSF Data @@ -581,24 +388,7 @@ func (s *Server) HandleGetNssai(c *gin.Context) { supportedFeatures := query.Get("supported-features") // step 3: handle the message - response, problemDetails := s.Processor().GetNssaiProcedure(supi, plmnID, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetNssaiProcedure(c, supi, plmnID, supportedFeatures) } // GetSmData - retrieve a UE's Session Management Subscription Data @@ -625,24 +415,7 @@ func (s *Server) HandleGetSmData(c *gin.Context) { supportedFeatures := query.Get("supported-features") // step 3: handle the message - response, problemDetails := s.Processor().GetSmDataProcedure(supi, plmnID, Dnn, Snssai, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetSmDataProcedure(c, supi, plmnID, Dnn, Snssai, supportedFeatures) } // GetIdTranslationResult - retrieve a UE's SUPI @@ -656,24 +429,7 @@ func (s *Server) HandleGetIdTranslationResult(c *gin.Context) { gpsi := c.Params.ByName("gpsi") // step 3: handle the message - response, problemDetails := s.Processor().GetIdTranslationResultProcedure(gpsi) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetIdTranslationResultProcedure(c, gpsi) } func (s *Server) OneLayerPathHandlerFunc(c *gin.Context) { diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go index 8fa5017..2f7910e 100644 --- a/internal/sbi/api_ueauthentication.go +++ b/internal/sbi/api_ueauthentication.go @@ -64,15 +64,7 @@ func (s *Server) HandleConfirmAuth(c *gin.Context) { logger.UeauLog.Infoln("Handle ConfirmAuthDataRequest") - problemDetails := s.Processor().ConfirmAuthDataProcedure(authEvent, supi) - - if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusCreated) - return - } + s.Processor().ConfirmAuthDataProcedure(c, authEvent, supi) } // GenerateAuthData - Generate authentication data for the UE @@ -114,24 +106,7 @@ func (s *Server) HandleGenerateAuthData(c *gin.Context) { supiOrSuci := c.Param("supiOrSuci") // step 3: handle the message - response, problemDetails := s.Processor().GenerateAuthDataProcedure(authInfoReq, supiOrSuci) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GenerateAuthDataProcedure(c, authInfoReq, supiOrSuci) } func (s *Server) GenAuthDataHandlerFunc(c *gin.Context) { diff --git a/internal/sbi/api_uecontextmanagement.go b/internal/sbi/api_uecontextmanagement.go index 2b38941..b17a989 100644 --- a/internal/sbi/api_uecontextmanagement.go +++ b/internal/sbi/api_uecontextmanagement.go @@ -135,24 +135,7 @@ func (s *Server) HandleGetAmfNon3gppAccess(c *gin.Context) { queryAmfContextNon3gppParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) // step 3: handle the message - response, problemDetails := s.Processor().GetAmfNon3gppAccessProcedure(queryAmfContextNon3gppParamOpts, ueId) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetAmfNon3gppAccessProcedure(c, queryAmfContextNon3gppParamOpts, ueId) } // Register - register as AMF for non-3GPP access @@ -193,23 +176,7 @@ func (s *Server) HandleRegistrationAmfNon3gppAccess(c *gin.Context) { ueID := c.Param("ueId") // step 3: handle the message - header, response, problemDetails := s.Processor().RegisterAmfNon3gppAccessProcedure(amfNon3GppAccessRegistration, ueID) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - for key, val := range header { // header response is optional - c.Header(key, val[0]) - } - c.JSON(http.StatusCreated, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().RegisterAmfNon3gppAccessProcedure(c, amfNon3GppAccessRegistration, ueID) } // RegistrationAmf3gppAccess - register as AMF for 3GPP access @@ -251,27 +218,7 @@ func (s *Server) HandleRegistrationAmf3gppAccess(c *gin.Context) { logger.UecmLog.Info("UEID: ", ueID) // step 3: handle the message - header, response, problemDetails := s.Processor().RegistrationAmf3gppAccessProcedure(amf3GppAccessRegistration, ueID) - - // step 4: process the return value from step 3 - if response != nil { - if header != nil { - // status code is based on SPEC, and option headers - for key, val := range header { // header response is optional - c.Header(key, val[0]) - } - c.JSON(http.StatusCreated, response) - return - } - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().RegistrationAmf3gppAccessProcedure(c, amf3GppAccessRegistration, ueID) } // UpdateAmfNon3gppAccess - update a parameter in the AMF registration for non-3GPP access @@ -312,16 +259,7 @@ func (s *Server) HandleUpdateAmfNon3gppAccess(c *gin.Context) { ueID := c.Param("ueId") // step 3: handle the message - problemDetails := s.Processor().UpdateAmfNon3gppAccessProcedure(amfNon3GppAccessRegistrationModification, ueID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().UpdateAmfNon3gppAccessProcedure(c, amfNon3GppAccessRegistrationModification, ueID) } // UpdateAmf3gppAccess - Update a parameter in the AMF registration for 3GPP access @@ -363,16 +301,7 @@ func (s *Server) HandleUpdateAmf3gppAccess(c *gin.Context) { ueID := c.Param("ueId") // step 3: handle the message - problemDetails := s.Processor().UpdateAmf3gppAccessProcedure(amf3GppAccessRegistrationModification, ueID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().UpdateAmf3gppAccessProcedure(c, amf3GppAccessRegistrationModification, ueID) } // DeregistrationSmsfNon3gppAccess - delete SMSF registration for non 3GPP access @@ -415,16 +344,7 @@ func (s *Server) HandleDeregistrationSmfRegistrations(c *gin.Context) { pduSessionID := c.Params.ByName("pduSessionId") // step 3: handle the message - problemDetails := s.Processor().DeregistrationSmfRegistrationsProcedure(ueID, pduSessionID) - - // step 4: process the return value from step 3 - if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - c.Status(http.StatusNoContent) - return - } + s.Processor().DeregistrationSmfRegistrationsProcedure(c, ueID, pduSessionID) } // RegistrationSmfRegistrations - register as SMF @@ -467,28 +387,12 @@ func (s *Server) HandleRegistrationSmfRegistrations(c *gin.Context) { pduSessionID := c.Params.ByName("pduSessionId") // step 3: handle the message - header, response, problemDetails := s.Processor().RegistrationSmfRegistrationsProcedure( + s.Processor().RegistrationSmfRegistrationsProcedure( + c, &smfRegistration, ueID, pduSessionID, ) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - for key, val := range header { // header response is optional - c.Header(key, val[0]) - } - c.JSON(http.StatusCreated, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - // all nil - c.Status(http.StatusNoContent) - return - } } // GetAmf3gppAccess - retrieve the AMF registration for 3GPP access information @@ -501,22 +405,5 @@ func (s *Server) HandleGetAmf3gppAccess(c *gin.Context) { supportedFeatures := c.Query("supported-features") // step 3: handle the message - response, problemDetails := s.Processor().GetAmf3gppAccessProcedure(ueID, supportedFeatures) - - // step 4: process the return value from step 3 - if response != nil { - // status code is based on SPEC, and option headers - c.JSON(http.StatusOK, response) - return - } else if problemDetails != nil { - c.JSON(int(problemDetails.Status), problemDetails) - return - } else { - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - c.JSON(http.StatusForbidden, problemDetails) - return - } + s.Processor().GetAmf3gppAccessProcedure(c, ueID, supportedFeatures) } diff --git a/internal/sbi/processor/enent_exposure.go b/internal/sbi/processor/event_exposure.go similarity index 83% rename from internal/sbi/processor/enent_exposure.go rename to internal/sbi/processor/event_exposure.go index 9f8e2b1..19d8105 100644 --- a/internal/sbi/processor/enent_exposure.go +++ b/internal/sbi/processor/event_exposure.go @@ -5,15 +5,17 @@ import ( "strconv" "strings" + "github.com/gin-gonic/gin" + "github.com/free5gc/openapi/models" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" ) // EE service -func (p *Processor) CreateEeSubscriptionProcedure(ueIdentity string, +func (p *Processor) CreateEeSubscriptionProcedure(c *gin.Context, ueIdentity string, eesubscription models.EeSubscription, -) (*models.CreatedEeSubscription, *models.ProblemDetails) { +) { udmSelf := udm_context.GetSelf() logger.EeLog.Debugf("udIdentity: %s", ueIdentity) switch { @@ -29,7 +31,8 @@ func (p *Processor) CreateEeSubscriptionProcedure(ueIdentity string, Status: http.StatusInternalServerError, Cause: "UNSPECIFIED_NF_FAILURE", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } subscriptionID := strconv.Itoa(int(id)) @@ -37,13 +40,13 @@ func (p *Processor) CreateEeSubscriptionProcedure(ueIdentity string, createdEeSubscription := &models.CreatedEeSubscription{ EeSubscription: &eesubscription, } - return createdEeSubscription, nil + c.JSON(http.StatusCreated, createdEeSubscription) } else { problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "USER_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } // external groupID represents a group of UEs case strings.HasPrefix(ueIdentity, "extgroupid-"): @@ -53,7 +56,8 @@ func (p *Processor) CreateEeSubscriptionProcedure(ueIdentity string, Status: http.StatusInternalServerError, Cause: "UNSPECIFIED_NF_FAILURE", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } subscriptionID := strconv.Itoa(int(id)) createdEeSubscription := &models.CreatedEeSubscription{ @@ -67,7 +71,7 @@ func (p *Processor) CreateEeSubscriptionProcedure(ueIdentity string, } return true }) - return createdEeSubscription, nil + c.JSON(http.StatusCreated, createdEeSubscription) // represents any UEs case ueIdentity == "anyUE": id, err := udmSelf.EeSubscriptionIDGenerator.Allocate() @@ -76,7 +80,8 @@ func (p *Processor) CreateEeSubscriptionProcedure(ueIdentity string, Status: http.StatusInternalServerError, Cause: "UNSPECIFIED_NF_FAILURE", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } subscriptionID := strconv.Itoa(int(id)) createdEeSubscription := &models.CreatedEeSubscription{ @@ -87,7 +92,7 @@ func (p *Processor) CreateEeSubscriptionProcedure(ueIdentity string, ue.EeSubscriptions[subscriptionID] = &eesubscription return true }) - return createdEeSubscription, nil + c.JSON(http.StatusCreated, createdEeSubscription) default: problemDetails := &models.ProblemDetails{ Status: http.StatusBadRequest, @@ -99,12 +104,12 @@ func (p *Processor) CreateEeSubscriptionProcedure(ueIdentity string, }, }, } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } // TODO: complete this procedure based on TS 29503 5.5 -func (p *Processor) DeleteEeSubscriptionProcedure(ueIdentity string, subscriptionID string) { +func (p *Processor) DeleteEeSubscriptionProcedure(c *gin.Context, ueIdentity string, subscriptionID string) { udmSelf := udm_context.GetSelf() switch { @@ -134,12 +139,15 @@ func (p *Processor) DeleteEeSubscriptionProcedure(ueIdentity string, subscriptio } else { udmSelf.EeSubscriptionIDGenerator.FreeID(id) } + + // only return 204 no content + c.Status(http.StatusNoContent) } // TODO: complete this procedure based on TS 29503 5.5 -func (p *Processor) UpdateEeSubscriptionProcedure(ueIdentity string, subscriptionID string, +func (p *Processor) UpdateEeSubscriptionProcedure(c *gin.Context, ueIdentity string, subscriptionID string, patchList []models.PatchItem, -) *models.ProblemDetails { +) { udmSelf := udm_context.GetSelf() switch { @@ -152,20 +160,20 @@ func (p *Processor) UpdateEeSubscriptionProcedure(ueIdentity string, subscriptio logger.EeLog.Debugf("patch item: %+v", patchItem) // TODO: patch the Eesubscription } - return nil + c.Status(http.StatusNoContent) } else { problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "SUBSCRIPTION_NOT_FOUND", } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } else { problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "SUBSCRIPTION_NOT_FOUND", } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } case strings.HasPrefix(ueIdentity, "extgroupid-"): udmSelf.UdmUePool.Range(func(key, value interface{}) bool { @@ -180,7 +188,7 @@ func (p *Processor) UpdateEeSubscriptionProcedure(ueIdentity string, subscriptio } return true }) - return nil + c.Status(http.StatusNoContent) case ueIdentity == "anyUE": udmSelf.UdmUePool.Range(func(key, value interface{}) bool { ue := value.(*udm_context.UdmUeContext) @@ -192,7 +200,7 @@ func (p *Processor) UpdateEeSubscriptionProcedure(ueIdentity string, subscriptio } return true }) - return nil + c.Status(http.StatusNoContent) default: problemDetails := &models.ProblemDetails{ Status: http.StatusBadRequest, @@ -204,6 +212,6 @@ func (p *Processor) UpdateEeSubscriptionProcedure(ueIdentity string, subscriptio }, }, } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 87c88fa..44f58db 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -13,6 +13,7 @@ import ( "time" "github.com/antihax/optional" + "github.com/gin-gonic/gin" "github.com/free5gc/openapi" "github.com/free5gc/openapi/Nudr_DataRepository" @@ -76,13 +77,14 @@ func (p *Processor) strictHex(ss string, n int) string { } } -func (p *Processor) ConfirmAuthDataProcedure( +func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, authEvent models.AuthEvent, supi string, -) (problemDetails *models.ProblemDetails) { +) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return pd + c.JSON(int(pd.Status), pd) + return } var createAuthParam Nudr_DataRepository.CreateAuthenticationStatusParamOpts optInterface := optional.NewInterface(authEvent) @@ -90,20 +92,23 @@ func (p *Processor) ConfirmAuthDataProcedure( client, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } resp, err := client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( ctx, supi, &createAuthParam) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(resp.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } logger.UeauLog.Errorln("ConfirmAuth err:", err.Error()) - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { @@ -111,41 +116,47 @@ func (p *Processor) ConfirmAuthDataProcedure( } }() - return nil + c.Status(http.StatusCreated) } -func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.AuthenticationInfoRequest, supiOrSuci string) ( - response *models.AuthenticationInfoResult, problemDetails *models.ProblemDetails, +func (p *Processor) GenerateAuthDataProcedure( + c *gin.Context, + authInfoRequest models.AuthenticationInfoRequest, + supiOrSuci string, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } logger.UeauLog.Traceln("In GenerateAuthDataProcedure") - response = &models.AuthenticationInfoResult{} + response := &models.AuthenticationInfoResult{} rand.New(rand.NewSource(time.Now().UnixNano())) supi, err := suci.ToSupi(supiOrSuci, udm_context.GetSelf().SuciProfiles) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, Detail: err.Error(), } logger.UeauLog.Errorln("suciToSupi error: ", err.Error()) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } logger.UeauLog.Tracef("supi conversion => [%s]", supi) client, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } authSubs, res, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, supi, nil) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, Detail: err.Error(), @@ -157,7 +168,8 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat default: logger.UeauLog.Errorln("Return from UDR QueryAuthSubsData error") } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := res.Body.Close(); rspCloseErr != nil { @@ -185,22 +197,24 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat hasK = true } } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, } logger.UeauLog.Errorln("kStr length is ", len(kStr)) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, } logger.UeauLog.Errorln("Nil PermanentKey") - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } if authSubs.Milenage != nil { @@ -220,13 +234,14 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat logger.UeauLog.Infoln("Nil Op") } } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, } logger.UeauLog.Infoln("Nil Milenage") - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } if authSubs.Opc != nil && authSubs.Opc.OpcValue != "" { @@ -246,12 +261,12 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat } if !hasOPC && !hasOP { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, } - - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } if !hasOPC { @@ -261,13 +276,14 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat logger.UeauLog.Errorln("milenage GenerateOPC err:", err) } } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, } logger.UeauLog.Errorln("Unable to derive OPC") - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } @@ -275,14 +291,15 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat logger.UeauLog.Traceln("sqnStr", sqnStr) sqn, err := hex.DecodeString(sqnStr) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, Detail: err.Error(), } logger.UeauLog.Errorln("err:", err) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } logger.UeauLog.Tracef("K=[%x], sqn=[%x], OP=[%x], OPC=[%x]", k, sqn, op, opc) @@ -290,28 +307,30 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat RAND := make([]byte, 16) _, err = cryptoRand.Read(RAND) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, Detail: err.Error(), } logger.UeauLog.Errorln("err:", err) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } amfStr := p.strictHex(authSubs.AuthenticationManagementField, 4) logger.UeauLog.Traceln("amfStr", amfStr) AMF, err := hex.DecodeString(amfStr) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, Detail: err.Error(), } logger.UeauLog.Errorln("err:", err) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } logger.UeauLog.Tracef("RAND=[%x], AMF=[%x]", RAND, AMF) @@ -322,40 +341,43 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat Auts, deCodeErr := hex.DecodeString(authInfoRequest.ResynchronizationInfo.Auts) if deCodeErr != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, Detail: deCodeErr.Error(), } logger.UeauLog.Errorln("err:", deCodeErr) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } randHex, deCodeErr := hex.DecodeString(authInfoRequest.ResynchronizationInfo.Rand) if deCodeErr != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, Detail: deCodeErr.Error(), } logger.UeauLog.Errorln("err:", deCodeErr) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } SQNms, macS := p.aucSQN(opc, k, Auts, randHex) if reflect.DeepEqual(macS, Auts[6:]) { _, err = cryptoRand.Read(RAND) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, Detail: deCodeErr.Error(), } logger.UeauLog.Errorln("err:", deCodeErr) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } // increment sqn authSubs.SequenceNumber @@ -393,11 +415,12 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat logger.UeauLog.Errorln("MACS ", macS) logger.UeauLog.Errorln("Auts[6:] ", Auts[6:]) logger.UeauLog.Errorln("Sqn ", SQNms) - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: "modification is rejected", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } @@ -405,14 +428,15 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat bigSQN := big.NewInt(0) sqn, err = hex.DecodeString(sqnStr) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, Detail: err.Error(), } logger.UeauLog.Errorln("err:", err) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } bigSQN.SetString(sqnStr, 16) @@ -435,14 +459,15 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat rsp, err = client.AuthenticationDataDocumentApi.ModifyAuthentication( ctx, supi, patchItemArray) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: "modification is rejected ", Detail: err.Error(), } logger.UeauLog.Errorln("update sqn error:", err) - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := rsp.Body.Close(); rspCloseErr != nil { @@ -549,5 +574,5 @@ func (p *Processor) GenerateAuthDataProcedure(authInfoRequest models.Authenticat response.AuthenticationVector = &av response.Supi = supi - return response, nil + c.JSON(http.StatusOK, response) } diff --git a/internal/sbi/processor/notifier.go b/internal/sbi/processor/notifier.go index b2ab1bb..9c09b62 100644 --- a/internal/sbi/processor/notifier.go +++ b/internal/sbi/processor/notifier.go @@ -3,18 +3,21 @@ package processor import ( "net/http" + "github.com/gin-gonic/gin" + "github.com/free5gc/openapi/models" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" ) -func (p *Processor) DataChangeNotificationProcedure( +func (p *Processor) DataChangeNotificationProcedure(c *gin.Context, notifyItems []models.NotifyItem, supi string, -) *models.ProblemDetails { +) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM) if err != nil { - return pd + c.JSON(int(pd.Status), pd) + return } ue, _ := udm_context.GetSelf().UdmUeFindBySupi(supi) @@ -52,7 +55,7 @@ func (p *Processor) DataChangeNotificationProcedure( }() } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } func (p *Processor) SendOnDeregistrationNotification(ueId string, onDeregistrationNotificationUrl string, diff --git a/internal/sbi/processor/parameter_provision.go b/internal/sbi/processor/parameter_provision.go index f6f9fb1..9ed4270 100644 --- a/internal/sbi/processor/parameter_provision.go +++ b/internal/sbi/processor/parameter_provision.go @@ -1,37 +1,46 @@ package processor import ( + "net/http" + + "github.com/gin-gonic/gin" + "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" ) -func (p *Processor) UpdateProcedure( +func (p *Processor) UpdateProcedure(c *gin.Context, updateRequest models.PpData, gpsi string, -) (problemDetails *models.ProblemDetails) { +) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return pd + c.JSON(int(pd.Status), pd) + return } clientAPI, err := p.consumer.CreateUDMClientToUDR(gpsi) if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } + res, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(ctx, gpsi, nil) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := res.Body.Close(); rspCloseErr != nil { logger.PpLog.Errorf("ModifyPpData response body cannot close: %+v", rspCloseErr) } }() - return nil + c.Status(http.StatusNoContent) } diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 0ca3e37..316f016 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -5,6 +5,7 @@ import ( "strconv" "github.com/antihax/optional" + "github.com/gin-gonic/gin" "github.com/free5gc/openapi" "github.com/free5gc/openapi/Nudr_DataRepository" @@ -13,19 +14,20 @@ import ( "github.com/free5gc/udm/internal/logger" ) -func (p *Processor) GetAmDataProcedure(supi string, plmnID string, supportedFeatures string) ( - response *models.AccessAndMobilitySubscriptionData, problemDetails *models.ProblemDetails, -) { +func (p *Processor) GetAmDataProcedure(c *gin.Context, supi string, plmnID string, supportedFeatures string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } var queryAmDataParamOpts Nudr_DataRepository.QueryAmDataParamOpts queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } accessAndMobilitySubscriptionDataResp, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. @@ -36,12 +38,13 @@ func (p *Processor) GetAmDataProcedure(supi string, plmnID string, supportedFeat } else if err.Error() != res.Status { logger.SdmLog.Errorf("Response State: %+v", err.Error()) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -56,29 +59,29 @@ func (p *Processor) GetAmDataProcedure(supi string, plmnID string, supportedFeat udmUe = udm_context.GetSelf().NewUdmUe(supi) } udmUe.SetAMSubsriptionData(&accessAndMobilitySubscriptionDataResp) - return &accessAndMobilitySubscriptionDataResp, nil + c.JSON(http.StatusOK, accessAndMobilitySubscriptionDataResp) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) GetIdTranslationResultProcedure(gpsi string) (response *models.IdTranslationResult, - problemDetails *models.ProblemDetails, -) { +func (p *Processor) GetIdTranslationResultProcedure(c *gin.Context, gpsi string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) } var idTranslationResult models.IdTranslationResult var getIdentityDataParamOpts Nudr_DataRepository.GetIdentityDataParamOpts clientAPI, err := p.consumer.CreateUDMClientToUDR(gpsi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } idTranslationResultResp, res, err := clientAPI.QueryIdentityDataBySUPIOrGPSIDocumentApi.GetIdentityData( @@ -89,13 +92,13 @@ func (p *Processor) GetIdTranslationResultProcedure(gpsi string) (response *mode } else if err.Error() != res.Status { logger.SdmLog.Errorf("Response State: %+v", err.Error()) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -109,45 +112,49 @@ func (p *Processor) GetIdTranslationResultProcedure(gpsi string) (response *mode // GetCorrespondingSupi get corresponding Supi(here IMSI) matching the given Gpsi from the queried SUPI list from UDR idTranslationResult.Supi = udm_context.GetCorrespondingSupi(idList) idTranslationResult.Gpsi = gpsi - - return &idTranslationResult, nil + c.JSON(http.StatusOK, idTranslationResult) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "USER_NOT_FOUND", } - - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames []string, supportedFeatures string) ( - response *models.SubscriptionDataSets, problemDetails *models.ProblemDetails, +func (p *Processor) GetSupiProcedure(c *gin.Context, + supi string, + plmnID string, + dataSetNames []string, + supportedFeatures string, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } if len(dataSetNames) < 2 { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusBadRequest, Cause: "BAD_REQUEST", Detail: "datasetNames must have at least 2 elements", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } var subscriptionDataSets, subsDataSetBody models.SubscriptionDataSets @@ -177,13 +184,14 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] } else if err.Error() != res.Status { logger.SdmLog.Errorf("Response State: %+v", err.Error()) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -199,12 +207,13 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] udmUe.SetAMSubsriptionData(&amData) subscriptionDataSets.AmData = &amData } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } @@ -220,13 +229,14 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] } else if err.Error() != res.Status { logger.SdmLog.Errorln(err.Error()) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -242,12 +252,13 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] udmUe.SetSmfSelectionSubsData(&smfSelData) subscriptionDataSets.SmfSelData = &smfSelData } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } @@ -265,13 +276,14 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] } else if err.Error() != res.Status { logger.SdmLog.Errorf("Response State: %+v", err.Error()) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -329,13 +341,14 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] } else if err.Error() != res.Status { logger.SdmLog.Errorf("Response State: %+v", err.Error()) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -352,12 +365,13 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] udmUe.SetSMSubsData(smData) subscriptionDataSets.SmData = sessionManagementSubscriptionData } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } @@ -373,13 +387,17 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] } else if err.Error() != res.Status { logger.SdmLog.Errorf("Response State: %+v", err.Error()) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } + c.JSON(int(problemDetails.Status), problemDetails) + return } - return nil, problemDetails + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := res.Body.Close(); rspCloseErr != nil { @@ -395,12 +413,13 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] udmUe.TraceDataResponse.TraceData = &traceData subscriptionDataSets.TraceData = &traceData } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } @@ -408,19 +427,20 @@ func (p *Processor) GetSupiProcedure(supi string, plmnID string, dataSetNames [] // if containDataSetName(dataSetNames, string(models.DataSetName_SMS_MNG)) { // } - return &subscriptionDataSets, nil + c.JSON(http.StatusOK, subscriptionDataSets) } -func (p *Processor) GetSharedDataProcedure(sharedDataIds []string, supportedFeatures string) ( - response []models.SharedData, problemDetails *models.ProblemDetails, -) { +func (p *Processor) GetSharedDataProcedure(c *gin.Context, sharedDataIds []string, supportedFeatures string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } clientAPI, err := p.consumer.CreateUDMClientToUDR("") if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } var getSharedDataParamOpts Nudr_DataRepository.GetSharedDataParamOpts @@ -435,13 +455,14 @@ func (p *Processor) GetSharedDataProcedure(sharedDataIds []string, supportedFeat logger.SdmLog.Warnln(err) } else { logger.SdmLog.Warnln(err) - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -453,34 +474,35 @@ func (p *Processor) GetSharedDataProcedure(sharedDataIds []string, supportedFeat if res.StatusCode == http.StatusOK { udm_context.GetSelf().SharedSubsDataMap = udm_context.MappingSharedData(sharedDataResp) sharedData := udm_context.ObtainRequiredSharedData(sharedDataIds, sharedDataResp) - return sharedData, nil + c.JSON(http.StatusOK, sharedData) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } func (p *Processor) GetSmDataProcedure( + c *gin.Context, supi string, plmnID string, Dnn string, Snssai string, supportedFeatures string, -) ( - response interface{}, problemDetails *models.ProblemDetails, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) } logger.SdmLog.Infof("getSmDataProcedure: SUPI[%s] PLMNID[%s] DNN[%s] SNssai[%s]", supi, plmnID, Dnn, Snssai) clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } var querySmDataParamOpts Nudr_DataRepository.QuerySmDataParamOpts @@ -495,13 +517,13 @@ func (p *Processor) GetSmDataProcedure( logger.SdmLog.Warnln(err) } else { logger.SdmLog.Warnln(err) - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -529,43 +551,44 @@ func (p *Processor) GetSmDataProcedure( switch { case Snssai == "" && Dnn == "": - return AllDnns, nil + c.JSON(http.StatusOK, AllDnns) case Snssai != "" && Dnn == "": udmUe.SmSubsDataLock.RLock() defer udmUe.SmSubsDataLock.RUnlock() - return udmUe.SessionManagementSubsData[snssaikey].DnnConfigurations, nil + c.JSON(http.StatusOK, udmUe.SessionManagementSubsData[snssaikey].DnnConfigurations) case Snssai == "" && Dnn != "": - return AllDnnConfigsbyDnn, nil + c.JSON(http.StatusOK, AllDnnConfigsbyDnn) case Snssai != "" && Dnn != "": - return rspSMSubDataList, nil + c.JSON(http.StatusOK, rspSMSubDataList) default: udmUe.SmSubsDataLock.RLock() defer udmUe.SmSubsDataLock.RUnlock() - return udmUe.SessionManagementSubsData, nil + c.JSON(http.StatusOK, udmUe.SessionManagementSubsData) } } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } -func (p *Processor) GetNssaiProcedure(supi string, plmnID string, supportedFeatures string) ( - *models.Nssai, *models.ProblemDetails, -) { +func (p *Processor) GetNssaiProcedure(c *gin.Context, supi string, plmnID string, supportedFeatures string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } var queryAmDataParamOpts Nudr_DataRepository.QueryAmDataParamOpts queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) var nssaiResp models.Nssai clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } accessAndMobilitySubscriptionDataResp, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. @@ -583,7 +606,8 @@ func (p *Processor) GetNssaiProcedure(supi string, plmnID string, supportedFeatu Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -600,22 +624,21 @@ func (p *Processor) GetNssaiProcedure(supi string, plmnID string, supportedFeatu udmUe = udm_context.GetSelf().NewUdmUe(supi) } udmUe.Nssai = &nssaiResp - return udmUe.Nssai, nil + c.JSON(http.StatusOK, udmUe.Nssai) } else { problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) GetSmfSelectDataProcedure(supi string, plmnID string, supportedFeatures string) ( - response *models.SmfSelectionSubscriptionData, problemDetails *models.ProblemDetails, -) { +func (p *Processor) GetSmfSelectDataProcedure(c *gin.Context, supi string, plmnID string, supportedFeatures string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } var querySmfSelectDataParamOpts Nudr_DataRepository.QuerySmfSelectDataParamOpts querySmfSelectDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) @@ -623,7 +646,9 @@ func (p *Processor) GetSmfSelectDataProcedure(supi string, plmnID string, suppor clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } udm_context.GetSelf().CreateSmfSelectionSubsDataforUe(supi, body) @@ -637,14 +662,17 @@ func (p *Processor) GetSmfSelectDataProcedure(supi string, plmnID string, suppor logger.SdmLog.Warnln(err) } else { logger.SdmLog.Warnln(err) - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } - return nil, problemDetails + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := res.Body.Close(); rspCloseErr != nil { @@ -658,22 +686,21 @@ func (p *Processor) GetSmfSelectDataProcedure(supi string, plmnID string, suppor udmUe = udm_context.GetSelf().NewUdmUe(supi) } udmUe.SetSmfSelectionSubsData(&smfSelectionSubscriptionDataResp) - return udmUe.SmfSelSubsData, nil + c.JSON(http.StatusOK, udmUe.SmfSelSubsData) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) SubscribeToSharedDataProcedure(sdmSubscription *models.SdmSubscription) ( - header http.Header, response *models.SdmSubscription, problemDetails *models.ProblemDetails, -) { +func (p *Processor) SubscribeToSharedDataProcedure(c *gin.Context, sdmSubscription *models.SdmSubscription) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM) if err != nil { - return nil, nil, pd + c.JSON(int(pd.Status), pd) + return } udmClientAPI := p.consumer.GetSDMClient("subscribeToSharedData") @@ -686,12 +713,13 @@ func (p *Processor) SubscribeToSharedDataProcedure(sdmSubscription *models.SdmSu } else if err.Error() != res.Status { logger.SdmLog.Warnln(err) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -701,40 +729,44 @@ func (p *Processor) SubscribeToSharedDataProcedure(sdmSubscription *models.SdmSu }() if res.StatusCode == http.StatusCreated { - header = make(http.Header) + header := make(http.Header) udm_context.GetSelf().CreateSubstoNotifSharedData(sdmSubscriptionResp.SubscriptionId, &sdmSubscriptionResp) reourceUri := udm_context.GetSelf(). GetSDMUri() + "//shared-data-subscriptions/" + sdmSubscriptionResp.SubscriptionId header.Set("Location", reourceUri) - return header, &sdmSubscriptionResp, nil + for key, val := range header { // header response is optional + c.Header(key, val[0]) + } + c.JSON(http.StatusOK, sdmSubscriptionResp) } else if res.StatusCode == http.StatusNotFound { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotImplemented, Cause: "UNSUPPORTED_RESOURCE_URI", } - return nil, nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) SubscribeProcedure(sdmSubscription *models.SdmSubscription, supi string) ( - header http.Header, response *models.SdmSubscription, problemDetails *models.ProblemDetails, -) { +func (p *Processor) SubscribeProcedure(c *gin.Context, sdmSubscription *models.SdmSubscription, supi string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, nil, pd + c.JSON(int(pd.Status), pd) + return } clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } sdmSubscriptionResp, res, err := clientAPI.SDMSubscriptionsCollectionApi.CreateSdmSubscriptions( @@ -746,12 +778,13 @@ func (p *Processor) SubscribeProcedure(sdmSubscription *models.SdmSubscription, logger.SdmLog.Warnln(err) } else { logger.SdmLog.Warnln(err) - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -761,33 +794,37 @@ func (p *Processor) SubscribeProcedure(sdmSubscription *models.SdmSubscription, }() if res.StatusCode == http.StatusCreated { - header = make(http.Header) + header := make(http.Header) udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(supi) if udmUe == nil { udmUe = udm_context.GetSelf().NewUdmUe(supi) } udmUe.CreateSubscriptiontoNotifChange(sdmSubscriptionResp.SubscriptionId, &sdmSubscriptionResp) header.Set("Location", udmUe.GetLocationURI2(udm_context.LocationUriSdmSubscription, supi)) - return header, &sdmSubscriptionResp, nil + for key, val := range header { // header response is optional + c.Header(key, val[0]) + } + c.JSON(http.StatusCreated, sdmSubscriptionResp) } else if res.StatusCode == http.StatusNotFound { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotImplemented, Cause: "UNSUPPORTED_RESOURCE_URI", } - return nil, nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) UnsubscribeForSharedDataProcedure(subscriptionID string) *models.ProblemDetails { +func (p *Processor) UnsubscribeForSharedDataProcedure(c *gin.Context, subscriptionID string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM) if err != nil { - return pd + c.JSON(int(pd.Status), pd) + return } udmClientAPI := p.consumer.GetSDMClient("unsubscribeForSharedData") @@ -806,7 +843,8 @@ func (p *Processor) UnsubscribeForSharedDataProcedure(subscriptionID string) *mo Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -816,24 +854,27 @@ func (p *Processor) UnsubscribeForSharedDataProcedure(subscriptionID string) *mo }() if res.StatusCode == http.StatusNoContent { - return nil + c.Status(http.StatusNoContent) } else { problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) UnsubscribeProcedure(supi string, subscriptionID string) *models.ProblemDetails { +func (p *Processor) UnsubscribeProcedure(c *gin.Context, supi string, subscriptionID string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return pd + c.JSON(int(pd.Status), pd) + return } clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } res, err := clientAPI.SDMSubscriptionDocumentApi.RemovesdmSubscriptions(ctx, supi, subscriptionID) @@ -849,7 +890,8 @@ func (p *Processor) UnsubscribeProcedure(supi string, subscriptionID string) *mo Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -859,30 +901,31 @@ func (p *Processor) UnsubscribeProcedure(supi string, subscriptionID string) *mo }() if res.StatusCode == http.StatusNoContent { - return nil + c.Status(http.StatusNoContent) } else { problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "USER_NOT_FOUND", } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) ModifyProcedure( +func (p *Processor) ModifyProcedure(c *gin.Context, sdmSubsModification *models.SdmSubsModification, supi string, subscriptionID string, -) ( - response *models.SdmSubscription, problemDetails *models.ProblemDetails, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } sdmSubscription := models.SdmSubscription{} @@ -898,12 +941,13 @@ func (p *Processor) ModifyProcedure( } else if err.Error() != res.Status { logger.SdmLog.Warnln(err) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -913,29 +957,34 @@ func (p *Processor) ModifyProcedure( }() if res.StatusCode == http.StatusOK { - return &sdmSubscription, nil + c.JSON(http.StatusOK, sdmSubscription) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "USER_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } // TS 29.503 5.2.2.7.3 // Modification of a subscription to notifications of shared data change -func (p *Processor) ModifyForSharedDataProcedure(sdmSubsModification *models.SdmSubsModification, supi string, +func (p *Processor) ModifyForSharedDataProcedure(c *gin.Context, + sdmSubsModification *models.SdmSubsModification, + supi string, subscriptionID string, -) (response *models.SdmSubscription, problemDetails *models.ProblemDetails) { +) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } var sdmSubscription models.SdmSubscription @@ -952,12 +1001,13 @@ func (p *Processor) ModifyForSharedDataProcedure(sdmSubsModification *models.Sdm } else if err.Error() != res.Status { logger.SdmLog.Warnln(err) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -967,30 +1017,30 @@ func (p *Processor) ModifyForSharedDataProcedure(sdmSubsModification *models.Sdm }() if res.StatusCode == http.StatusOK { - return &sdmSubscription, nil + c.JSON(http.StatusOK, sdmSubscription) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "USER_NOT_FOUND", } - - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) GetTraceDataProcedure(supi string, plmnID string) ( - response *models.TraceData, problemDetails *models.ProblemDetails, -) { +func (p *Processor) GetTraceDataProcedure(c *gin.Context, supi string, plmnID string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } var body models.TraceData var queryTraceDataParamOpts Nudr_DataRepository.QueryTraceDataParamOpts clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } udm_context.GetSelf().CreateTraceDataforUe(supi, body) @@ -1003,13 +1053,13 @@ func (p *Processor) GetTraceDataProcedure(supi string, plmnID string) ( } else if err.Error() != res.Status { logger.SdmLog.Warnln(err) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -1026,20 +1076,18 @@ func (p *Processor) GetTraceDataProcedure(supi string, plmnID string) ( udmUe.TraceData = &traceDataRes udmUe.TraceDataResponse.TraceData = &traceDataRes - return udmUe.TraceDataResponse.TraceData, nil + c.JSON(http.StatusOK, udmUe.TraceDataResponse.TraceData) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "USER_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } -func (p *Processor) GetUeContextInSmfDataProcedure(supi string, supportedFeatures string) ( - response *models.UeContextInSmfData, problemDetails *models.ProblemDetails, -) { +func (p *Processor) GetUeContextInSmfDataProcedure(c *gin.Context, supi string, supportedFeatures string) { var body models.UeContextInSmfData var ueContextInSmfData models.UeContextInSmfData var pgwInfoArray []models.PgwInfo @@ -1048,7 +1096,9 @@ func (p *Processor) GetUeContextInSmfDataProcedure(supi string, supportedFeature clientAPI, err := p.consumer.CreateUDMClientToUDR(supi) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } pduSessionMap := make(map[string]models.PduSession) @@ -1056,7 +1106,8 @@ func (p *Processor) GetUeContextInSmfDataProcedure(supi string, supportedFeature ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } pdusess, res, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( @@ -1068,13 +1119,14 @@ func (p *Processor) GetUeContextInSmfDataProcedure(supi string, supportedFeature logger.SdmLog.Infoln(err) } else { logger.SdmLog.Infoln(err) - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(res.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } } defer func() { @@ -1107,13 +1159,13 @@ func (p *Processor) GetUeContextInSmfDataProcedure(supi string, supportedFeature udmUe = udm_context.GetSelf().NewUdmUe(supi) } udmUe.UeCtxtInSmfData = &ueContextInSmfData - return udmUe.UeCtxtInSmfData, nil + c.JSON(http.StatusOK, udmUe.UeCtxtInSmfData) } else { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "DATA_NOT_FOUND", } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) } } diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 2d4b087..9ab1008 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -5,6 +5,7 @@ import ( "strconv" "github.com/antihax/optional" + "github.com/gin-gonic/gin" "github.com/free5gc/openapi" "github.com/free5gc/openapi/Nudr_DataRepository" @@ -14,30 +15,32 @@ import ( ) // ue_context_managemanet_service -func (p *Processor) GetAmf3gppAccessProcedure(ueID string, supportedFeatures string) ( - response *models.Amf3GppAccessRegistration, problemDetails *models.ProblemDetails, -) { +func (p *Processor) GetAmf3gppAccessProcedure(c *gin.Context, ueID string, supportedFeatures string) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) + return } var queryAmfContext3gppParamOpts Nudr_DataRepository.QueryAmfContext3gppParamOpts queryAmfContext3gppParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) clientAPI, err := p.consumer.CreateUDMClientToUDR(ueID) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } amf3GppAccessRegistration, resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi. QueryAmfContext3gpp(ctx, ueID, &queryAmfContext3gppParamOpts) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(resp.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { @@ -45,31 +48,33 @@ func (p *Processor) GetAmf3gppAccessProcedure(ueID string, supportedFeatures str } }() - return &amf3GppAccessRegistration, nil + c.JSON(http.StatusOK, amf3GppAccessRegistration) } -func (p *Processor) GetAmfNon3gppAccessProcedure(queryAmfContextNon3gppParamOpts Nudr_DataRepository. - QueryAmfContextNon3gppParamOpts, ueID string) (response *models.AmfNon3GppAccessRegistration, - problemDetails *models.ProblemDetails, +func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContextNon3gppParamOpts Nudr_DataRepository. + QueryAmfContextNon3gppParamOpts, ueID string, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, pd + c.JSON(int(pd.Status), pd) } clientAPI, err := p.consumer.CreateUDMClientToUDR(ueID) if err != nil { - return nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } amfNon3GppAccessRegistration, resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi. QueryAmfContextNon3gpp(ctx, ueID, &queryAmfContextNon3gppParamOpts) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(resp.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { @@ -77,18 +82,17 @@ func (p *Processor) GetAmfNon3gppAccessProcedure(queryAmfContextNon3gppParamOpts } }() - return &amfNon3GppAccessRegistration, nil + c.JSON(http.StatusOK, amfNon3GppAccessRegistration) } -func (p *Processor) RegistrationAmf3gppAccessProcedure( +func (p *Processor) RegistrationAmf3gppAccessProcedure(c *gin.Context, registerRequest models.Amf3GppAccessRegistration, ueID string, -) ( - header http.Header, response *models.Amf3GppAccessRegistration, problemDetails *models.ProblemDetails, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, nil, pd + c.JSON(int(pd.Status), pd) + return } // TODO: EPS interworking with N26 is not supported yet in this stage var oldAmf3GppAccessRegContext *models.Amf3GppAccessRegistration @@ -103,7 +107,9 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure( clientAPI, err := p.consumer.CreateUDMClientToUDR(ueID) if err != nil { - return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } var createAmfContext3gppParamOpts Nudr_DataRepository.CreateAmfContext3gppParamOpts @@ -113,12 +119,13 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure( ueID, &createAmfContext3gppParamOpts) if err != nil { logger.UecmLog.Errorln("CreateAmfContext3gpp error : ", err) - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(resp.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { @@ -152,24 +159,27 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure( } }() } - return nil, ®isterRequest, nil + + c.JSON(http.StatusOK, registerRequest) } else { - header = make(http.Header) + header := make(http.Header) udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) header.Set("Location", udmUe.GetLocationURI(udm_context.LocationUriAmf3GppAccessRegistration)) - return header, ®isterRequest, nil + for key, val := range header { // header response is optional + c.Header(key, val[0]) + } + c.JSON(http.StatusCreated, registerRequest) } } -func (p *Processor) RegisterAmfNon3gppAccessProcedure( +func (p *Processor) RegisterAmfNon3gppAccessProcedure(c *gin.Context, registerRequest models.AmfNon3GppAccessRegistration, ueID string, -) ( - header http.Header, response *models.AmfNon3GppAccessRegistration, problemDetails *models.ProblemDetails, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, nil, pd + c.JSON(int(pd.Status), pd) + return } var oldAmfNon3GppAccessRegContext *models.AmfNon3GppAccessRegistration if udm_context.GetSelf().UdmAmfNon3gppRegContextExists(ueID) { @@ -181,7 +191,9 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure( clientAPI, err := p.consumer.CreateUDMClientToUDR(ueID) if err != nil { - return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } var createAmfContextNon3gppParamOpts Nudr_DataRepository.CreateAmfContextNon3gppParamOpts @@ -191,12 +203,14 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure( resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.CreateAmfContextNon3gpp( ctx, ueID, &createAmfContextNon3gppParamOpts) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(resp.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, nil, problemDetails + + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { @@ -214,31 +228,37 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure( p.SendOnDeregistrationNotification(ueID, oldAmfNon3GppAccessRegContext.DeregCallbackUri, deregistData) // Deregistration Notify Triggered - return nil, nil, nil + return } else { - header = make(http.Header) + header := make(http.Header) udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) header.Set("Location", udmUe.GetLocationURI(udm_context.LocationUriAmfNon3GppAccessRegistration)) - return header, ®isterRequest, nil + for key, val := range header { // header response is optional + c.Header(key, val[0]) + } + c.JSON(http.StatusCreated, registerRequest) } } -func (p *Processor) UpdateAmf3gppAccessProcedure(request models.Amf3GppAccessRegistrationModification, ueID string) ( - problemDetails *models.ProblemDetails, +func (p *Processor) UpdateAmf3gppAccessProcedure(c *gin.Context, + request models.Amf3GppAccessRegistrationModification, + ueID string, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return pd + c.JSON(int(pd.Status), pd) + return } var patchItemReqArray []models.PatchItem currentContext := udm_context.GetSelf().GetAmf3gppRegContext(ueID) if currentContext == nil { logger.UecmLog.Errorln("[UpdateAmf3gppAccess] Empty Amf3gppRegContext") - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "CONTEXT_NOT_FOUND", } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } if request.Guami != nil { @@ -248,11 +268,12 @@ func (p *Processor) UpdateAmf3gppAccessProcedure(request models.Amf3GppAccessReg request.PurgeFlag = true } else { logger.UecmLog.Errorln("INVALID_GUAMI") - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: "INVALID_GUAMI", } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } var patchItemTmp models.PatchItem @@ -296,19 +317,21 @@ func (p *Processor) UpdateAmf3gppAccessProcedure(request models.Amf3GppAccessReg clientAPI, err := p.consumer.CreateUDMClientToUDR(ueID) if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi.AmfContext3gpp(ctx, ueID, patchItemReqArray) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(resp.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } if request.PurgeFlag { @@ -322,28 +345,28 @@ func (p *Processor) UpdateAmf3gppAccessProcedure(request models.Amf3GppAccessReg } }() - return nil + c.Status(http.StatusNoContent) } -func (p *Processor) UpdateAmfNon3gppAccessProcedure( +func (p *Processor) UpdateAmfNon3gppAccessProcedure(c *gin.Context, request models.AmfNon3GppAccessRegistrationModification, ueID string, -) ( - problemDetails *models.ProblemDetails, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return pd + c.JSON(int(pd.Status), pd) + return } var patchItemReqArray []models.PatchItem currentContext := udm_context.GetSelf().GetAmfNon3gppRegContext(ueID) if currentContext == nil { logger.UecmLog.Errorln("[UpdateAmfNon3gppAccess] Empty AmfNon3gppRegContext") - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, Cause: "CONTEXT_NOT_FOUND", } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } if request.Guami != nil { @@ -353,10 +376,12 @@ func (p *Processor) UpdateAmfNon3gppAccessProcedure( request.PurgeFlag = true } else { logger.UecmLog.Errorln("INVALID_GUAMI") - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: "INVALID_GUAMI", } + c.JSON(int(problemDetails.Status), problemDetails) + return } var patchItemTmp models.PatchItem @@ -400,18 +425,21 @@ func (p *Processor) UpdateAmfNon3gppAccessProcedure( clientAPI, err := p.consumer.CreateUDMClientToUDR(ueID) if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.AmfContextNon3gpp(ctx, ueID, patchItemReqArray) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(resp.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { @@ -419,30 +447,34 @@ func (p *Processor) UpdateAmfNon3gppAccessProcedure( } }() - return problemDetails + c.Status(http.StatusNoContent) } -func (p *Processor) DeregistrationSmfRegistrationsProcedure( +func (p *Processor) DeregistrationSmfRegistrationsProcedure(c *gin.Context, ueID string, pduSessionID string, -) (problemDetails *models.ProblemDetails) { +) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return pd + c.JSON(int(pd.Status), pd) + return } clientAPI, err := p.consumer.CreateUDMClientToUDR(ueID) if err != nil { - return openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } resp, err := clientAPI.SMFRegistrationDocumentApi.DeleteSmfContext(ctx, ueID, pduSessionID) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(resp.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { @@ -450,19 +482,19 @@ func (p *Processor) DeregistrationSmfRegistrationsProcedure( } }() - return nil + c.Status(http.StatusNoContent) } func (p *Processor) RegistrationSmfRegistrationsProcedure( + c *gin.Context, request *models.SmfRegistration, ueID string, pduSessionID string, -) ( - header http.Header, response *models.SmfRegistration, problemDetails *models.ProblemDetails, ) { ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { - return nil, nil, pd + c.JSON(int(pd.Status), pd) + return } contextExisted := false udm_context.GetSelf().CreateSmfRegContext(ueID, pduSessionID) @@ -482,18 +514,21 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( clientAPI, err := p.consumer.CreateUDMClientToUDR(ueID) if err != nil { - return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } resp, err := clientAPI.SMFRegistrationDocumentApi.CreateSmfContextNon3gpp(ctx, ueID, pduID32, &createSmfContextNon3gppParamOpts) if err != nil { - problemDetails = &models.ProblemDetails{ + problemDetails := &models.ProblemDetails{ Status: int32(resp.StatusCode), Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, Detail: err.Error(), } - return nil, nil, problemDetails + c.JSON(int(problemDetails.Status), problemDetails) + return } defer func() { if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { @@ -502,11 +537,14 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( }() if contextExisted { - return nil, nil, nil + c.Status(http.StatusNoContent) } else { - header = make(http.Header) + header := make(http.Header) udmUe, _ := udm_context.GetSelf().UdmUeFindBySupi(ueID) header.Set("Location", udmUe.GetLocationURI(udm_context.LocationUriSmfRegistration)) - return header, request, nil + for key, val := range header { // header response is optional + c.Header(key, val[0]) + } + c.JSON(http.StatusCreated, request) } }