Skip to content

Commit

Permalink
update SendSearchNFInstances & GetTokenCtx
Browse files Browse the repository at this point in the history
  • Loading branch information
ianchen0119 committed Oct 26, 2023
1 parent fc9b532 commit d6ce425
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
7 changes: 5 additions & 2 deletions internal/sbi/consumer/nf_discovery.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package consumer

import (
"context"
"fmt"
"net/http"

Expand All @@ -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, &param)
if rspErr != nil {
return nil, fmt.Errorf("NFInstancesStoreApi Response error: %+w", rspErr)
Expand Down
14 changes: 9 additions & 5 deletions internal/sbi/consumer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/antihax/optional"
ausf_context "github.com/free5gc/ausf/internal/context"

Check failure on line 11 in internal/sbi/consumer/nf_management.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

Expected '"', Found 'a' at internal/sbi/consumer/nf_management.go[line 11,col 2] (gci)
"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"
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d6ce425

Please sign in to comment.