From 5ae8ef9547ccb6d332e6c390aa3274708d0e976d Mon Sep 17 00:00:00 2001 From: tim1207 Date: Tue, 23 Jan 2024 13:12:56 +0000 Subject: [PATCH] replace context to ctx in communication folder --- .../consumer/subscriber_data_management.go | 61 +++++++++++++++---- internal/sbi/consumer/ue_authentication.go | 19 ++++-- .../sbi/consumer/ue_context_management.go | 17 ++++-- 3 files changed, 75 insertions(+), 22 deletions(-) diff --git a/internal/sbi/consumer/subscriber_data_management.go b/internal/sbi/consumer/subscriber_data_management.go index 95a8e809..4b05062a 100644 --- a/internal/sbi/consumer/subscriber_data_management.go +++ b/internal/sbi/consumer/subscriber_data_management.go @@ -1,8 +1,6 @@ package consumer import ( - "context" - "github.com/antihax/optional" amf_context "github.com/free5gc/amf/internal/context" @@ -17,6 +15,11 @@ func PutUpuAck(ue *amf_context.AmfUe, upuMacIue string) error { configuration.SetBasePath(ue.NudmSDMUri) client := Nudm_SubscriberDataManagement.NewAPIClient(configuration) + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nudm-sdm", models.NfType_UDM) + if err != nil { + return err + } + ackInfo := models.AcknowledgeInfo{ UpuMacIue: upuMacIue, } @@ -24,7 +27,7 @@ func PutUpuAck(ue *amf_context.AmfUe, upuMacIue string) error { AcknowledgeInfo: optional.NewInterface(ackInfo), } httpResp, err := client.ProvidingAcknowledgementOfUEParametersUpdateApi. - PutUpuAck(context.Background(), ue.Supi, &upuOpt) + PutUpuAck(ctx, ue.Supi, &upuOpt) defer func() { if httpResp != nil { if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil { @@ -45,8 +48,13 @@ func SDMGetAmData(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, PlmnId: optional.NewInterface(openapi.MarshToJsonString(ue.PlmnId)), } + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nudm-sdm", models.NfType_UDM) + if err != nil { + return nil, err + } + data, httpResp, localErr := client.AccessAndMobilitySubscriptionDataRetrievalApi.GetAmData( - context.Background(), ue.Supi, &getAmDataParamOpt) + ctx, ue.Supi, &getAmDataParamOpt) defer func() { if httpResp != nil { if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil { @@ -79,8 +87,14 @@ func SDMGetSmfSelectData(ue *amf_context.AmfUe) (problemDetails *models.ProblemD paramOpt := Nudm_SubscriberDataManagement.GetSmfSelectDataParamOpts{ PlmnId: optional.NewInterface(openapi.MarshToJsonString(ue.PlmnId)), } + + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nudm-sdm", models.NfType_UDM) + if err != nil { + return nil, err + } + data, httpResp, localErr := client.SMFSelectionSubscriptionDataRetrievalApi. - GetSmfSelectData(context.Background(), ue.Supi, ¶mOpt) + GetSmfSelectData(ctx, ue.Supi, ¶mOpt) defer func() { if httpResp != nil { if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil { @@ -110,8 +124,13 @@ func SDMGetUeContextInSmfData(ue *amf_context.AmfUe) (problemDetails *models.Pro configuration.SetBasePath(ue.NudmSDMUri) client := Nudm_SubscriberDataManagement.NewAPIClient(configuration) + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nudm-sdm", models.NfType_UDM) + if err != nil { + return nil, err + } + data, httpResp, localErr := client.UEContextInSMFDataRetrievalApi. - GetUeContextInSmfData(context.Background(), ue.Supi, nil) + GetUeContextInSmfData(ctx, ue.Supi, nil) defer func() { if httpResp != nil { if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil { @@ -125,7 +144,7 @@ func SDMGetUeContextInSmfData(ue *amf_context.AmfUe) (problemDetails *models.Pro } else if httpResp != nil { if httpResp.Status != localErr.Error() { err = localErr - return + return nil, err } problem := localErr.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) problemDetails = &problem @@ -133,7 +152,7 @@ func SDMGetUeContextInSmfData(ue *amf_context.AmfUe) (problemDetails *models.Pro err = openapi.ReportError("server no response") } - return + return problemDetails, err } func SDMSubscribe(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) { @@ -147,8 +166,13 @@ func SDMSubscribe(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, PlmnId: &ue.PlmnId, } + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nudm-sdm", models.NfType_UDM) + if err != nil { + return nil, err + } + resSubscription, httpResp, localErr := client.SubscriptionCreationApi.Subscribe( - context.Background(), ue.Supi, sdmSubscription) + ctx, ue.Supi, sdmSubscription) defer func() { if httpResp != nil { if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil { @@ -181,8 +205,14 @@ func SDMGetSliceSelectionSubscriptionData(ue *amf_context.AmfUe) (problemDetails paramOpt := Nudm_SubscriberDataManagement.GetNssaiParamOpts{ PlmnId: optional.NewInterface(openapi.MarshToJsonString(ue.PlmnId)), } + + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nudm-sdm", models.NfType_UDM) + if err != nil { + return nil, err + } + nssai, httpResp, localErr := client.SliceSelectionSubscriptionDataRetrievalApi. - GetNssai(context.Background(), ue.Supi, ¶mOpt) + GetNssai(ctx, ue.Supi, ¶mOpt) defer func() { if httpResp != nil { if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil { @@ -230,7 +260,12 @@ func SDMUnsubscribe(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetail configuration.SetBasePath(ue.NudmSDMUri) client := Nudm_SubscriberDataManagement.NewAPIClient(configuration) - httpResp, localErr := client.SubscriptionDeletionApi.Unsubscribe(context.Background(), ue.Supi, ue.SdmSubscriptionId) + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nudm-sdm", models.NfType_UDM) + if err != nil { + return nil, err + } + + httpResp, localErr := client.SubscriptionDeletionApi.Unsubscribe(ctx, ue.Supi, ue.SdmSubscriptionId) defer func() { if httpResp != nil { if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil { @@ -244,12 +279,12 @@ func SDMUnsubscribe(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetail } else if httpResp != nil { if httpResp.Status != localErr.Error() { err = localErr - return problemDetails, err + return nil, err } problem := localErr.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) problemDetails = &problem } else { err = openapi.ReportError("server no response") } - return + return problemDetails, err } diff --git a/internal/sbi/consumer/ue_authentication.go b/internal/sbi/consumer/ue_authentication.go index 6d41fb22..c7084952 100644 --- a/internal/sbi/consumer/ue_authentication.go +++ b/internal/sbi/consumer/ue_authentication.go @@ -1,7 +1,6 @@ package consumer import ( - "context" "encoding/base64" "fmt" "net/url" @@ -38,8 +37,12 @@ func SendUEAuthenticationAuthenticateRequest(ue *amf_context.AmfUe, if resynchronizationInfo != nil { authInfo.ResynchronizationInfo = resynchronizationInfo } + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nausf-auth", models.NfType_AUSF) + if err != nil { + return nil, nil, err + } - ueAuthenticationCtx, httpResponse, err := client.DefaultApi.UeAuthenticationsPost(context.Background(), authInfo) + ueAuthenticationCtx, httpResponse, err := client.DefaultApi.UeAuthenticationsPost(ctx, authInfo) defer func() { if httpResponse != nil { if rspCloseErr := httpResponse.Body.Close(); rspCloseErr != nil { @@ -80,9 +83,13 @@ func SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resStar string) ( ResStar: resStar, }), } + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nausf-auth", models.NfType_AUSF) + if err != nil { + return nil, nil, err + } confirmResult, httpResponse, err := client.DefaultApi.UeAuthenticationsAuthCtxId5gAkaConfirmationPut( - context.Background(), ue.Suci, confirmData) + ctx, ue.Suci, confirmData) defer func() { if httpResponse != nil { if rspCloseErr := httpResponse.Body.Close(); rspCloseErr != nil { @@ -126,8 +133,12 @@ func SendEapAuthConfirmRequest(ue *amf_context.AmfUe, eapMsg nasType.EAPMessage) EapPayload: base64.StdEncoding.EncodeToString(eapMsg.GetEAPMessage()), }), } + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nausf-auth", models.NfType_AUSF) + if err != nil { + return nil, nil, err + } - eapSession, httpResponse, err := client.DefaultApi.EapAuthMethod(context.Background(), ue.Suci, eapSessionReq) + eapSession, httpResponse, err := client.DefaultApi.EapAuthMethod(ctx, ue.Suci, eapSessionReq) defer func() { if httpResponse != nil { if rspCloseErr := httpResponse.Body.Close(); rspCloseErr != nil { diff --git a/internal/sbi/consumer/ue_context_management.go b/internal/sbi/consumer/ue_context_management.go index d0f58ca4..6738029e 100644 --- a/internal/sbi/consumer/ue_context_management.go +++ b/internal/sbi/consumer/ue_context_management.go @@ -1,7 +1,6 @@ package consumer import ( - "context" "fmt" amf_context "github.com/free5gc/amf/internal/context" @@ -20,6 +19,10 @@ func UeCmRegistration(ue *amf_context.AmfUe, accessType models.AccessType, initi client := Nudm_UEContextManagement.NewAPIClient(configuration) amfSelf := amf_context.GetSelf() + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nudm-uecm", models.NfType_UDM) + if err != nil { + return nil, err + } switch accessType { case models.AccessType__3_GPP_ACCESS: @@ -39,7 +42,7 @@ func UeCmRegistration(ue *amf_context.AmfUe, accessType models.AccessType, initi ImsVoPs: models.ImsVoPs_HOMOGENEOUS_NON_SUPPORT, } - _, httpResp, localErr := client.AMFRegistrationFor3GPPAccessApi.Registration(context.Background(), + _, httpResp, localErr := client.AMFRegistrationFor3GPPAccessApi.Registration(ctx, ue.Supi, registrationData) defer func() { if httpResp != nil { @@ -69,7 +72,7 @@ func UeCmRegistration(ue *amf_context.AmfUe, accessType models.AccessType, initi } _, httpResp, localErr := client.AMFRegistrationForNon3GPPAccessApi. - Register(context.Background(), ue.Supi, registrationData) + Register(ctx, ue.Supi, registrationData) defer func() { if httpResp != nil { if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil { @@ -103,6 +106,10 @@ func UeCmDeregistration(ue *amf_context.AmfUe, accessType models.AccessType) ( client := Nudm_UEContextManagement.NewAPIClient(configuration) amfSelf := amf_context.GetSelf() + ctx, _, err := amf_context.GetSelf().GetTokenCtx("nudm-uecm", models.NfType_UDM) + if err != nil { + return nil, err + } switch accessType { case models.AccessType__3_GPP_ACCESS: @@ -111,7 +118,7 @@ func UeCmDeregistration(ue *amf_context.AmfUe, accessType models.AccessType) ( PurgeFlag: true, } - httpResp, localErr := client.ParameterUpdateInTheAMFRegistrationFor3GPPAccessApi.Update(context.Background(), + httpResp, localErr := client.ParameterUpdateInTheAMFRegistrationFor3GPPAccessApi.Update(ctx, ue.Supi, modificationData) defer func() { if httpResp != nil { @@ -139,7 +146,7 @@ func UeCmDeregistration(ue *amf_context.AmfUe, accessType models.AccessType) ( } httpResp, localErr := client.ParameterUpdateInTheAMFRegistrationForNon3GPPAccessApi.UpdateAmfNon3gppAccess( - context.Background(), ue.Supi, modificationData) + ctx, ue.Supi, modificationData) defer func() { if httpResp != nil { if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil {