Skip to content

Commit

Permalink
Fix: move GetTokenCtx() and fix logics
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Dec 18, 2023
1 parent db49353 commit ba44652
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 61 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/free5gc/aper v1.0.4
github.com/free5gc/nas v1.1.0
github.com/free5gc/ngap v1.0.6
github.com/free5gc/openapi v1.0.7-0.20231112094355-a96c3450377e
github.com/free5gc/openapi v1.0.7-0.20231216094313-e15a4ff046f6
github.com/free5gc/pfcp v1.0.6
github.com/free5gc/util v1.0.5-0.20231001095115-433858e5be94
github.com/gin-gonic/gin v1.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ github.com/free5gc/ngap v1.0.6 h1:f9sKqHMNrFZVo9Kp8hAyrCXSoI8l746N5O+DFn7vKHA=
github.com/free5gc/ngap v1.0.6/go.mod h1:TG1kwwU/EyIlJ3bxY591rdxpD5ZeYnLZTzoWjcfvrBM=
github.com/free5gc/openapi v1.0.4/go.mod h1:KRCnnp0GeK0Bl4gnrX79cQAidKXNENf8VRdG0y9R0Fc=
github.com/free5gc/openapi v1.0.6/go.mod h1:iw/N0E+FlX44EEx24IBi2EdZW8v+bkj3ETWPGnlK9DI=
github.com/free5gc/openapi v1.0.7-0.20231112094355-a96c3450377e h1:mXnoioq+fxpChliDl5Uy+m6+Hm7iWrJPZo9mi6BijHE=
github.com/free5gc/openapi v1.0.7-0.20231112094355-a96c3450377e/go.mod h1:qv9KqEucoZSeENPRFGxfTe+33ZWYyiYFx1Rj+H0DoWA=
github.com/free5gc/openapi v1.0.7-0.20231216094313-e15a4ff046f6 h1:8P/wOkTAQMgZJe9pUUNSTE5PWeAdlMrsU9kLsI+VAVE=
github.com/free5gc/openapi v1.0.7-0.20231216094313-e15a4ff046f6/go.mod h1:qv9KqEucoZSeENPRFGxfTe+33ZWYyiYFx1Rj+H0DoWA=
github.com/free5gc/pfcp v1.0.6 h1:dKEVyZWozF1G+yk1JXw/1ggtIRI0v362say/Q6VDZTE=
github.com/free5gc/pfcp v1.0.6/go.mod h1:WzpW7Zxhx5WONMumNKRWbPn7pl/iTYp2FqRLNiOWUjs=
github.com/free5gc/tlv v1.0.2-0.20230131124215-8b6ebd69bf93 h1:QPSSI5zw4goiIfxem9doVyMqTO8iKLQ536pzpET5Y+Q=
Expand Down
15 changes: 12 additions & 3 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/free5gc/openapi/Nnrf_NFManagement"
"github.com/free5gc/openapi/Nudm_SubscriberDataManagement"
"github.com/free5gc/openapi/models"
"github.com/free5gc/openapi/oauth"
"github.com/free5gc/pfcp/pfcpType"
"github.com/free5gc/smf/internal/logger"
"github.com/free5gc/smf/pkg/factory"
Expand Down Expand Up @@ -154,9 +155,7 @@ func InitSmfContext(config *factory.Config) {
logger.CtxLog.Warn("NRF Uri is empty! Using localhost as NRF IPv4 address.")
smfContext.NrfUri = fmt.Sprintf("%s://%s:%d", smfContext.URIScheme, "127.0.0.1", 29510)
}
if configuration.NrfCertPem != "" {
smfContext.NrfCertPem = configuration.NrfCertPem
}
smfContext.NrfCertPem = configuration.NrfCertPem

if pfcp := configuration.PFCP; pfcp != nil {
smfContext.ListenAddr = pfcp.ListenAddr
Expand Down Expand Up @@ -288,3 +287,13 @@ func GetUserPlaneInformation() *UserPlaneInformation {
func GetUEDefaultPathPool(groupName string) *UEDefaultPaths {
return smfContext.UEDefaultPathPool[groupName]
}

func (c *SMFContext) GetTokenCtx(scope, targetNF string) (
context.Context, *models.ProblemDetails, error,
) {
if !c.OAuth2Required {
return context.TODO(), nil, nil
}
return oauth.GetTokenCtx(models.NfType_SMF,
c.NfInstanceID, c.NrfUri, scope, targetNF)
}
24 changes: 0 additions & 24 deletions internal/context/nf_accesstoken.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/context/sm_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func (smContext *SMContext) PDUAddressToNAS() ([12]byte, uint8) {

// PCFSelection will select PCF for this SM Context
func (smContext *SMContext) PCFSelection() error {
ctx, _, err := GetTokenCtx("nnrf-disc", "NRF")
ctx, _, err := GetSelf().GetTokenCtx("nnrf-disc", "NRF")
if err != nil {
return err
}
Expand Down
25 changes: 0 additions & 25 deletions internal/sbi/consumer/nf_accesstoken.go

This file was deleted.

6 changes: 3 additions & 3 deletions internal/sbi/consumer/nf_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func SendNFDiscoveryUDM() (*models.ProblemDetails, error) {
ctx, pd, err := GetTokenCtx("nnrf-disc", "NRF")
ctx, pd, err := smf_context.GetSelf().GetTokenCtx("nnrf-disc", "NRF")
if err != nil {
return pd, err
}
Expand Down Expand Up @@ -61,7 +61,7 @@ func SendNFDiscoveryUDM() (*models.ProblemDetails, error) {
}

func SendNFDiscoveryPCF() (problemDetails *models.ProblemDetails, err error) {
ctx, pd, err := GetTokenCtx("nnrf-disc", "NRF")
ctx, pd, err := smf_context.GetSelf().GetTokenCtx("nnrf-disc", "NRF")
if err != nil {
return pd, err
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func SendNFDiscoveryPCF() (problemDetails *models.ProblemDetails, err error) {
}

func SendNFDiscoveryServingAMF(smContext *smf_context.SMContext) (*models.ProblemDetails, error) {
ctx, pd, err := GetTokenCtx("nnrf-disc", "NRF")
ctx, pd, err := smf_context.GetSelf().GetTokenCtx("nnrf-disc", "NRF")
if err != nil {
return pd, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/sbi/consumer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func RetrySendNFRegistration(MaxRetry int) error {
func SendNFDeregistration() error {
// Check data (Use RESTful DELETE)

ctx, _, err := GetTokenCtx("nnrf-nfm", "NRF")
ctx, _, err := smf_context.GetSelf().GetTokenCtx("nnrf-nfm", "NRF")
if err != nil {
return err
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func SendNFDeregistration() error {
func SendDeregisterNFInstance() (*models.ProblemDetails, error) {
logger.ConsumerLog.Infof("Send Deregister NFInstance")

ctx, pd, err := GetTokenCtx("nnrf-nfm", "NRF")
ctx, pd, err := smf_context.GetSelf().GetTokenCtx("nnrf-nfm", "NRF")
if err != nil {
return pd, err
}
Expand Down

0 comments on commit ba44652

Please sign in to comment.