Skip to content

Commit

Permalink
replace context to ctx in communication folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tim1207 committed Jan 23, 2024
1 parent 5b4091f commit 5ae8ef9
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 22 deletions.
61 changes: 48 additions & 13 deletions internal/sbi/consumer/subscriber_data_management.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package consumer

import (
"context"

"github.com/antihax/optional"

amf_context "github.com/free5gc/amf/internal/context"
Expand All @@ -17,14 +15,19 @@ 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,
}
upuOpt := Nudm_SubscriberDataManagement.PutUpuAckParamOpts{
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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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, &paramOpt)
GetSmfSelectData(ctx, ue.Supi, &paramOpt)
defer func() {
if httpResp != nil {
if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil {
Expand Down Expand Up @@ -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 {
Expand All @@ -125,15 +144,15 @@ 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
} else {
err = openapi.ReportError("server no response")
}

return
return problemDetails, err
}

func SDMSubscribe(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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, &paramOpt)
GetNssai(ctx, ue.Supi, &paramOpt)
defer func() {
if httpResp != nil {
if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
19 changes: 15 additions & 4 deletions internal/sbi/consumer/ue_authentication.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package consumer

import (
"context"
"encoding/base64"
"fmt"
"net/url"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 12 additions & 5 deletions internal/sbi/consumer/ue_context_management.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package consumer

import (
"context"
"fmt"

amf_context "github.com/free5gc/amf/internal/context"
Expand All @@ -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:
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5ae8ef9

Please sign in to comment.