Skip to content

Commit

Permalink
Fix: move GetTokenCtx() and fix minor logic
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Dec 18, 2023
1 parent 2806eb5 commit 73f0765
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 30 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.5-0.20230614030933-c73735898582
github.com/free5gc/nas v1.1.2-0.20230828074825-175b09665828
github.com/free5gc/ngap v1.0.7-0.20230614061954-9c128114ab1f
github.com/free5gc/openapi v1.0.7-0.20231112094355-a96c3450377e
github.com/free5gc/openapi v1.0.7-0.20231216094313-e15a4ff046f6
github.com/free5gc/sctp v0.0.0-20231121085449-400a702ea7f9
github.com/free5gc/util v1.0.5-0.20231001095115-433858e5be94
github.com/gin-contrib/cors v1.3.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/nas v1.1.2-0.20230828074825-175b09665828/go.mod h1:fjWwpyp7/w
github.com/free5gc/ngap v1.0.7-0.20230614061954-9c128114ab1f h1:wgXjoknZ7JJoZ72J15g/f2/0DgdCpfcTg189lnhUPuY=
github.com/free5gc/ngap v1.0.7-0.20230614061954-9c128114ab1f/go.mod h1:lKA1sLTYM3CGEBhZVxkGGJIkai5+Bvy2yHIMhb7Vx/k=
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/sctp v0.0.0-20231121085449-400a702ea7f9 h1:L02UI8oODfXgH1fGzWWuWF4zyze4IScEFm20q3PKZdE=
github.com/free5gc/sctp v0.0.0-20231121085449-400a702ea7f9/go.mod h1:Nr81VlvMkBHZsCbWPXjosBh+SWLdeEyz8o0OrS110Ic=
github.com/free5gc/util v1.0.5-0.20231001095115-433858e5be94 h1:tNylIqH/m5Kq+3KuC+jjXGl06Y6EmM8yq61ZUgNrPBY=
Expand Down
14 changes: 14 additions & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package context

import (
"context"
"fmt"
"math"
"net"
Expand All @@ -18,6 +19,7 @@ import (
"github.com/free5gc/nas/security"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/openapi/oauth"
"github.com/free5gc/util/idgenerator"
)

Expand Down Expand Up @@ -542,9 +544,21 @@ func (context *AMFContext) Reset() {
context.HttpIPv6Address = ""
context.Name = "amf"
context.NrfUri = ""
context.NrfCertPem = ""
context.OAuth2Required = false
}

// Create new AMF context
func GetSelf() *AMFContext {
return &amfContext
}

func (c *AMFContext) GetTokenCtx(scope, targetNF string) (
context.Context, *models.ProblemDetails, error,
) {
if !c.OAuth2Required {
return context.TODO(), nil, nil
}
return oauth.GetTokenCtx(models.NfType_AMF,
c.NfId, c.NrfUri, scope, targetNF)
}
25 changes: 0 additions & 25 deletions internal/sbi/consumer/nf_accesstoken.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/sbi/consumer/nf_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func SendSearchNFInstances(nrfUri string, targetNfType, requestNfType models.NfT
configuration.SetBasePath(nrfUri)
client := Nnrf_NFDiscovery.NewAPIClient(configuration)

ctx, _, err := GetTokenCtx("nnrf-nfm", "NRF")
ctx, _, err := amf_context.GetSelf().GetTokenCtx("nnrf-nfm", "NRF")
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sbi/consumer/nf_mangement.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func SendRegisterNFInstance(nrfUri, nfInstanceId string, profile models.NfProfil
func SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) {
logger.ConsumerLog.Infof("[AMF] Send Deregister NFInstance")

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

0 comments on commit 73f0765

Please sign in to comment.