Skip to content

Commit

Permalink
Refactor: refactor after openapi refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Nov 9, 2023
1 parent 5ea410d commit 374087e
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 106 deletions.
10 changes: 4 additions & 6 deletions internal/sbi/consumer/nf_accesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ package consumer
import (
"context"

udm_context "github.com/free5gc/udm/internal/context"

"github.com/free5gc/udm/pkg/factory"

"github.com/free5gc/openapi"
"github.com/free5gc/openapi/Send_util"
"github.com/free5gc/openapi/models"
"github.com/free5gc/openapi/oauth"

Check failure on line 8 in internal/sbi/consumer/nf_accesstoken.go

View workflow job for this annotation

GitHub Actions / build (1.18)

no required module provides package github.com/free5gc/openapi/oauth; to add it:
udm_context "github.com/free5gc/udm/internal/context"
"github.com/free5gc/udm/pkg/factory"
)

func GetTokenCtx(scope, targetNF string) (context.Context, *models.ProblemDetails, error) {
if factory.UdmConfig.GetOAuth() {
udmSelf := udm_context.Getself()
tok, pd, err := Send_util.SendAccTokenReq(udmSelf.NfId, models.NfType_UDM, scope, targetNF, udmSelf.NrfUri)
tok, pd, err := oauth.SendAccTokenReq(udmSelf.NfId, models.NfType_UDM, scope, targetNF, udmSelf.NrfUri)
if err != nil {
return nil, pd, err
}
Expand Down
23 changes: 16 additions & 7 deletions internal/sbi/producer/generate_auth_data.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package producer

import (
"context"
cryptoRand "crypto/rand"
"encoding/hex"
"fmt"
Expand All @@ -20,6 +19,7 @@ import (
"github.com/free5gc/openapi/models"
udm_context "github.com/free5gc/udm/internal/context"
"github.com/free5gc/udm/internal/logger"
udm_consumer "github.com/free5gc/udm/internal/sbi/consumer"
"github.com/free5gc/udm/pkg/suci"
"github.com/free5gc/util/httpwrapper"
"github.com/free5gc/util/milenage"
Expand Down Expand Up @@ -127,9 +127,12 @@ func ConfirmAuthDataProcedure(authEvent models.AuthEvent, supi string) (problemD
if err != nil {
return openapi.ProblemDetailsSystemFailure(err.Error())
}
// TODO: [OAUTH2] should call GetTokenCtx("nudr-dr", "UDR")
ctx, pd, err := udm_consumer.GetTokenCtx("nudr-dr", "UDR")
if err != nil {
return pd
}
resp, err := client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus(
context.Background(), supi, &createAuthParam)
ctx, supi, &createAuthParam)
if err != nil {
problemDetails = &models.ProblemDetails{
Status: int32(resp.StatusCode),
Expand Down Expand Up @@ -174,8 +177,11 @@ func GenerateAuthDataProcedure(authInfoRequest models.AuthenticationInfoRequest,
if err != nil {
return nil, openapi.ProblemDetailsSystemFailure(err.Error())
}
// TODO: [OAUTH2] should call GetTokenCtx("nudr-dr", "UDR")
authSubs, res, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(context.Background(), supi, nil)
ctx, pd, err := udm_consumer.GetTokenCtx("nudr-dr", "UDR")
if err != nil {
return nil, pd
}
authSubs, res, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, supi, nil)
if err != nil {
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Expand Down Expand Up @@ -463,9 +469,12 @@ func GenerateAuthDataProcedure(authInfoRequest models.AuthenticationInfoRequest,
}

var rsp *http.Response
// TODO: [OAUTH2] should call GetTokenCtx("nudr-dr", "UDR")
ctx, pd, err = udm_consumer.GetTokenCtx("nudr-dr", "UDR")
if err != nil {
return nil, pd
}
rsp, err = client.AuthenticationDataDocumentApi.ModifyAuthentication(
context.Background(), supi, patchItemArray)
ctx, supi, patchItemArray)
if err != nil {
problemDetails = &models.ProblemDetails{
Status: http.StatusForbidden,
Expand Down
9 changes: 6 additions & 3 deletions internal/sbi/producer/parameter_provision.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package producer

import (
"context"
"net/http"

"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/udm/internal/logger"
udm_consumer "github.com/free5gc/udm/internal/sbi/consumer"
"github.com/free5gc/util/httpwrapper"
)

Expand Down Expand Up @@ -34,8 +34,11 @@ func UpdateProcedure(updateRequest models.PpData, gpsi string) (problemDetails *
if err != nil {
return openapi.ProblemDetailsSystemFailure(err.Error())
}
// TODO: [OAUTH2] should call GetTokenCtx("nudr-dr", "UDR")
res, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(context.Background(), gpsi, nil)
ctx, pd, err := udm_consumer.GetTokenCtx("nudr-dr", "UDR")
if err != nil {
return pd
}
res, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(ctx, gpsi, nil)
if err != nil {
problemDetails = &models.ProblemDetails{
Status: int32(res.StatusCode),
Expand Down
Loading

0 comments on commit 374087e

Please sign in to comment.