Skip to content

Commit

Permalink
fix: add type assertion and make the variable in camel case
Browse files Browse the repository at this point in the history
  • Loading branch information
tim1207 committed Nov 27, 2024
1 parent 34bbacd commit 84b6d72
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 79 deletions.
8 changes: 4 additions & 4 deletions internal/sbi/consumer/amf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ func (s *namfService) ReleaseUEContextRequest(ue *amf_context.AmfUe, ngapCause m
ctx, &ueCtxReleaseReq)
if err != nil {
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
releaseerr := apiErr.Model().(Namf_Communication.ReleaseUEContextError)
problemDetails = &releaseerr.ProblemDetails
releaseErr := apiErr.Model().(Namf_Communication.ReleaseUEContextError)
problemDetails = &releaseErr.ProblemDetails
return problemDetails, nil
}
return nil, err
Expand Down Expand Up @@ -311,8 +311,8 @@ func (s *namfService) RegistrationStatusUpdate(ue *amf_context.AmfUe, request mo
regStatusTransferComplete = res.UeRegStatusUpdateRspData.RegStatusTransferComplete
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
updateerr := apiErr.Model().(Namf_Communication.RegistrationStatusUpdateError)
problemDetails = &updateerr.ProblemDetails
updateErr := apiErr.Model().(Namf_Communication.RegistrationStatusUpdateError)
problemDetails = &updateErr.ProblemDetails
return regStatusTransferComplete, problemDetails, nil
}
return regStatusTransferComplete, nil, localErr
Expand Down
8 changes: 4 additions & 4 deletions internal/sbi/consumer/ausf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ func (s *nausfService) SendUEAuthenticationAuthenticateRequest(ue *amf_context.A
return nil, nil, err
}

authreq := Nausf_UEAuthentication.UeAuthenticationsPostRequest{
authReq := Nausf_UEAuthentication.UeAuthenticationsPostRequest{
AuthenticationInfo: &authInfo,
}

res, localErr := client.DefaultApi.UeAuthenticationsPost(ctx, &authreq)
res, localErr := client.DefaultApi.UeAuthenticationsPost(ctx, &authReq)
if localErr == nil {
return &res.UeAuthenticationCtx, nil, nil
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
// API error
posterr := apiErr.Model().(Nausf_UEAuthentication.UeAuthenticationsPostError)
return nil, &posterr.ProblemDetails, localErr
postErr := apiErr.Model().(Nausf_UEAuthentication.UeAuthenticationsPostError)
return nil, &postErr.ProblemDetails, localErr
}
return nil, nil, err
}
Expand Down
79 changes: 56 additions & 23 deletions internal/sbi/consumer/pcf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,23 @@ func (s *npcfService) AMPolicyControlCreate(
logger.ConsumerLog.Debugf("UE AM Policy Association ID: %s", ue.PolicyAssociationId)
logger.ConsumerLog.Debugf("AmPolicyAssociation: %+v", ue.AmPolicyAssociation)
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
switch apiErr := localErr.(type) {
case openapi.GenericOpenAPIError:
// API error
createrr := apiErr.Model().(Npcf_AMPolicy.CreateIndividualAMPolicyAssociationError)
return &createrr.ProblemDetails, localErr
switch errorModel := apiErr.Model().(type) {
case Npcf_AMPolicy.CreateIndividualAMPolicyAssociationError:
return &errorModel.ProblemDetails, localErr
case error:
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr
default:
return nil, openapi.ReportError("openapi error")
}
return nil, localErr

Check failure on line 122 in internal/sbi/consumer/pcf_service.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

File is not `gofumpt`-ed (gofumpt)
}

Check failure on line 123 in internal/sbi/consumer/pcf_service.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

unnecessary trailing newline (whitespace)
return nil, nil
}
Expand All @@ -127,13 +138,13 @@ func (s *npcfService) AMPolicyControlUpdate(
return nil, err
}

var policyUpdatereq Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationRequest
var policyUpdateReq Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationRequest

policyUpdatereq.SetPolAssoId(ue.PolicyAssociationId)
policyUpdatereq.SetPcfAmPolicyControlPolicyAssociationUpdateRequest(updateRequest)
policyUpdateReq.SetPolAssoId(ue.PolicyAssociationId)
policyUpdateReq.SetPcfAmPolicyControlPolicyAssociationUpdateRequest(updateRequest)

res, localErr := client.IndividualAMPolicyAssociationDocumentApi.
ReportObservedEventTriggersForIndividualAMPolicyAssociation(ctx, &policyUpdatereq)
ReportObservedEventTriggersForIndividualAMPolicyAssociation(ctx, &policyUpdateReq)
if localErr == nil {
if res.PcfAmPolicyControlPolicyUpdate.ServAreaRes != nil {
ue.AmPolicyAssociation.ServAreaRes = res.PcfAmPolicyControlPolicyUpdate.ServAreaRes
Expand All @@ -152,13 +163,24 @@ func (s *npcfService) AMPolicyControlUpdate(
// }
}
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
switch apiErr := localErr.(type) {
case openapi.GenericOpenAPIError:
// API error
reporterr := apiErr.Model().(Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationError)
problemDetails = &reporterr.ProblemDetails
switch errorModel := apiErr.Model().(type) {
case Npcf_AMPolicy.ReportObservedEventTriggersForIndividualAMPolicyAssociationError:
return &errorModel.ProblemDetails, localErr
case error:
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr
default:
return nil, openapi.ReportError("openapi error")
}
}
return problemDetails, err
return nil, err
}

func (s *npcfService) AMPolicyControlDelete(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) {
Expand All @@ -167,24 +189,35 @@ func (s *npcfService) AMPolicyControlDelete(ue *amf_context.AmfUe) (problemDetai
return nil, openapi.ReportError("pcf not found")
}

ctx, _, ctxerr := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NPCF_AM_POLICY_CONTROL,
ctx, _, ctxErr := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NPCF_AM_POLICY_CONTROL,
models.NrfNfManagementNfType_PCF)
if ctxerr != nil {
return nil, ctxerr
if ctxErr != nil {
return nil, ctxErr
}

var deletereq Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationRequest
deletereq.SetPolAssoId(ue.PolicyAssociationId)
var deleteReq Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationRequest
deleteReq.SetPolAssoId(ue.PolicyAssociationId)

_, err = client.IndividualAMPolicyAssociationDocumentApi.DeleteIndividualAMPolicyAssociation(ctx, &deletereq)
_, err = client.IndividualAMPolicyAssociationDocumentApi.DeleteIndividualAMPolicyAssociation(ctx, &deleteReq)
if err == nil {
ue.RemoveAmPolicyAssociation()
} else {
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
// API error
deleteerr := apiErr.Model().(Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationError)
problemDetails = &deleteerr.ProblemDetails
switch apiErr := err.(type) {
case openapi.GenericOpenAPIError:

Check failure on line 206 in internal/sbi/consumer/pcf_service.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/free5gc) --custom-order (gci)
// API error
switch errorModel := apiErr.Model().(type) {
case Npcf_AMPolicy.DeleteIndividualAMPolicyAssociationError:
return &errorModel.ProblemDetails, err
case error:
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), err
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr

Check failure on line 217 in internal/sbi/consumer/pcf_service.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/free5gc) --custom-order (gci)
default:
return nil, openapi.ReportError("openapi error")
}
}
return problemDetails, err
return nil, err
}
63 changes: 52 additions & 11 deletions internal/sbi/consumer/smf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,26 @@ func (s *nsmfService) SendCreateSmContextRequest(ue *amf_context.AmfUe, smContex
smContextRef = postSmContextReponse.Location
} else {
err1 = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
switch errType := localErr.(type) {
case openapi.GenericOpenAPIError:
// API error
posterr := apiErr.Model().(Nsmf_PDUSession.PostSmContextsError)
problemDetail = &posterr.ProblemDetails
errorResponse = &posterr.PostSmContextsError
switch errModel := errType.Model().(type) {
case Nsmf_PDUSession.PostSmContextsError:
problemDetail = &errModel.ProblemDetails
errorResponse = &errModel.PostSmContextsError
case error:
err1 = errModel
default:
err1 = openapi.ReportError("openapi error")
}
case error:
problemDetail = openapi.ProblemDetailsSystemFailure(err1.Error())
default:
problemDetail = &models.ProblemDetails{
Title: "Service Error",
Status: 500,
Detail: "An error occurred while processing the request",
}
}
}
return smContextRef, errorResponse, problemDetail, err1
Expand Down Expand Up @@ -472,11 +487,26 @@ func (s *nsmfService) SendUpdateSmContextRequest(smContext *amf_context.SmContex
response = &updateSmContextReponse.UpdateSmContextResponse200
} else {
err1 = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
switch errType := localErr.(type) {
case openapi.GenericOpenAPIError:
// API error
updateerr := apiErr.Model().(Nsmf_PDUSession.UpdateSmContextError)
problemDetail = &updateerr.ProblemDetails
errorResponse = &updateerr.UpdateSmContextResponse400
switch errModel := errType.Model().(type) {
case Nsmf_PDUSession.UpdateSmContextError:
problemDetail = &errModel.ProblemDetails
errorResponse = &errModel.UpdateSmContextResponse400
case error:
err1 = errModel
default:
err1 = openapi.ReportError("openapi error")
}
case error:
problemDetail = openapi.ProblemDetailsSystemFailure(err1.Error())
default:
problemDetail = &models.ProblemDetails{
Title: "Service Error",
Status: 500,
Detail: "An error occurred while processing the request",
}
}
}
return response, errorResponse, problemDetail, err1
Expand Down Expand Up @@ -514,10 +544,21 @@ func (s *nsmfService) SendReleaseSmContextRequest(ue *amf_context.AmfUe, smConte
ue.SmContextList.Delete(smContext.PduSessionID())
} else {
err = localErr
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
switch apiErr := localErr.(type) {
case openapi.GenericOpenAPIError:
// API error
releaseerr := apiErr.Model().(Nsmf_PDUSession.ReleaseSmContextError)
detail = &releaseerr.ProblemDetails
switch errorModel := apiErr.Model().(type) {
case Nsmf_PDUSession.ReleaseSmContextError:
detail = &errorModel.ProblemDetails
case error:
return openapi.ProblemDetailsSystemFailure(errorModel.Error()), localErr
default:
return nil, openapi.ReportError("openapi error")
}
case error:
return openapi.ProblemDetailsSystemFailure(apiErr.Error()), apiErr
default:
return nil, openapi.ReportError("openapi error")
}
}
return detail, err
Expand Down
Loading

0 comments on commit 84b6d72

Please sign in to comment.