diff --git a/internal/sbi/consumer/nf_discovery.go b/internal/sbi/consumer/nf_discovery.go index 59035ec..041bb1b 100644 --- a/internal/sbi/consumer/nf_discovery.go +++ b/internal/sbi/consumer/nf_discovery.go @@ -1,7 +1,6 @@ package consumer import ( - "context" "fmt" "net/http" @@ -16,8 +15,12 @@ func SendSearchNFInstances(nrfUri string, targetNfType, requestNfType models.NfT configuration := Nnrf_NFDiscovery.NewConfiguration() configuration.SetBasePath(nrfUri) client := Nnrf_NFDiscovery.NewAPIClient(configuration) + ctx, _, err := GetTokenCtx("nnrf-disc") + if err != nil { + return nil, err + } - result, rsp, rspErr := client.NFInstancesStoreApi.SearchNFInstances(context.TODO(), + result, rsp, rspErr := client.NFInstancesStoreApi.SearchNFInstances(ctx, targetNfType, requestNfType, ¶m) if rspErr != nil { return nil, fmt.Errorf("NFInstancesStoreApi Response error: %+w", rspErr) diff --git a/internal/sbi/consumer/nf_management.go b/internal/sbi/consumer/nf_management.go index e856911..0a02ca9 100644 --- a/internal/sbi/consumer/nf_management.go +++ b/internal/sbi/consumer/nf_management.go @@ -10,6 +10,7 @@ import ( "github.com/antihax/optional" ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/ausf/internal/logger" + "github.com/free5gc/ausf/pkg/factory" "github.com/free5gc/openapi" "github.com/free5gc/openapi/Nnrf_AccessToken" "github.com/free5gc/openapi/Nnrf_NFManagement" @@ -18,12 +19,15 @@ import ( ) func GetTokenCtx(scope string) (context.Context, *models.ProblemDetails, error) { - tok, pd, err := sendAccTokenReq(scope) - if err != nil { - return nil, pd, err + if factory.AusfConfig.GetOAuth() { + tok, pd, err := sendAccTokenReq(scope) + if err != nil { + return nil, pd, err + } + return context.WithValue(context.Background(), + openapi.ContextOAuth2, tok), pd, nil } - return context.WithValue(context.Background(), - openapi.ContextOAuth2, tok), pd, nil + return context.TODO(), nil, nil } func sendAccTokenReq(scope string) (oauth2.TokenSource, *models.ProblemDetails, error) { diff --git a/pkg/factory/config.go b/pkg/factory/config.go index a24ef32..be0ac0c 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -109,6 +109,13 @@ type Sbi struct { BindingIPv4 string `yaml:"bindingIPv4,omitempty" valid:"host,required"` // IP used to run the server in the node. Port int `yaml:"port,omitempty" valid:"port,required"` Tls *Tls `yaml:"tls,omitempty" valid:"optional"` + OAuth bool `yaml:"oauth,omitempty" valid:"optional"` +} + +func (c *Config) GetOAuth() bool { + c.RLock() + defer c.RUnlock() + return c.Configuration.Sbi.OAuth } func (s *Sbi) validate() (bool, error) {