Skip to content

Commit

Permalink
Remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Nov 8, 2023
1 parent c6b5341 commit 61c552d
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 200 deletions.
2 changes: 0 additions & 2 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ type UDRContext struct {
InfluenceDataSubscriptions sync.Map
appDataInfluDataSubscriptionIdGenerator uint64
mtx sync.RWMutex
ClientMap sync.Map
TokenMap sync.Map
}

type UESubsData struct {
Expand Down
72 changes: 4 additions & 68 deletions internal/sbi/consumer/nf_accesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package consumer

import (
"context"
"time"

"github.com/antihax/optional"
"golang.org/x/oauth2"

"github.com/free5gc/openapi"
"github.com/free5gc/openapi/Nnrf_AccessToken"
"github.com/free5gc/openapi/Send_util"
"github.com/free5gc/openapi/models"
udr_context "github.com/free5gc/udr/internal/context"
"github.com/free5gc/udr/internal/logger"
Expand All @@ -17,10 +13,9 @@ import (

func GetTokenCtx(scope, targetNF string) (context.Context, *models.ProblemDetails, error) {
if factory.UdrConfig.GetOAuth() {
tok, pd, err := sendAccTokenReq(scope, targetNF)
// udrSelf := udr_context.GetSelf()
// tok, pd, err := util.SendAccTokenReq
// (udrSelf.NfId, models.NfType_UDR, &udrSelf.TokenMap, &udrSelf.ClientMap, scope, targetNF, udrSelf.NrfUri)
logger.ConsumerLog.Infof("GetToekenCtx")
udrSelf := udr_context.GetSelf()
tok, pd, err := Send_util.SendAccTokenReq(udrSelf.NfId, models.NfType_UDR, scope, targetNF, udrSelf.NrfUri)
if err != nil {
return nil, pd, err
}
Expand All @@ -29,62 +24,3 @@ func GetTokenCtx(scope, targetNF string) (context.Context, *models.ProblemDetail
}
return context.TODO(), nil, nil
}

func sendAccTokenReq(scope, targetNF string) (oauth2.TokenSource, *models.ProblemDetails, error) {
logger.ConsumerLog.Infof("Send Access Token Request")
var client *Nnrf_AccessToken.APIClient
udrSelf := udr_context.GetSelf()
// Set client and set url
configuration := Nnrf_AccessToken.NewConfiguration()
configuration.SetBasePath(udrSelf.NrfUri)
if val, ok := udrSelf.ClientMap.Load(configuration); ok {
client = val.(*Nnrf_AccessToken.APIClient)
} else {
client = Nnrf_AccessToken.NewAPIClient(configuration)
udrSelf.ClientMap.Store(configuration, client)
}

var tok models.AccessTokenRsp

if val, ok := udrSelf.TokenMap.Load(scope); ok {
tok = val.(models.AccessTokenRsp)
if int32(time.Now().Unix()) < tok.ExpiresIn {
logger.ConsumerLog.Infof("Token is not expired")
token := &oauth2.Token{
AccessToken: tok.AccessToken,
TokenType: tok.TokenType,
Expiry: time.Unix(int64(tok.ExpiresIn), 0),
}
return oauth2.StaticTokenSource(token), nil, nil
}
}

tok, res, err := client.AccessTokenRequestApi.AccessTokenRequest(context.Background(), "client_credentials",
udrSelf.NfId, scope, &Nnrf_AccessToken.AccessTokenRequestParamOpts{
NfType: optional.NewInterface(models.NfType_UDR),
TargetNfType: optional.NewInterface(targetNF),
})
if err == nil {
udrSelf.TokenMap.Store(scope, tok)
token := &oauth2.Token{
AccessToken: tok.AccessToken,
TokenType: tok.TokenType,
Expiry: time.Unix(int64(tok.ExpiresIn), 0),
}
return oauth2.StaticTokenSource(token), nil, err
} else if res != nil {
defer func() {
if resCloseErr := res.Body.Close(); resCloseErr != nil {
logger.ConsumerLog.Errorf("AccessTokenRequestApi response body cannot close: %+v", resCloseErr)
}
}()
if res.Status != err.Error() {
return nil, nil, err
}
problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
// problem := err.(openapi.GenericOpenAPIError).Model().(models.AccessTokenErr)
return nil, &problem, err
} else {
return nil, nil, openapi.ReportError("server no response")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPQueryEEData - Retrieves the ee profile data of a UE
func HTTPQueryEEData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPRemoveEeGroupSubscriptions - Deletes a eeSubscription for a group of UEs or any UE
func HTTPRemoveEeGroupSubscriptions(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueGroupId"] = c.Params.ByName("ueGroupId")
req.Params["subsId"] = c.Params.ByName("subsId")
Expand All @@ -50,11 +45,6 @@ func HTTPRemoveEeGroupSubscriptions(c *gin.Context) {

// HTTPUpdateEeGroupSubscriptions - Stores an individual ee subscription of a group of UEs or any UE
func HTTPUpdateEeGroupSubscriptions(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

var eeSubscription models.EeSubscription

requestBody, err := c.GetRawData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPCreateEeGroupSubscriptions - Create individual EE subscription for a group of UEs or any UE
func HTTPCreateEeGroupSubscriptions(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

var eeSubscription models.EeSubscription
requestBody, err := c.GetRawData()
if err != nil {
Expand Down Expand Up @@ -76,11 +71,6 @@ func HTTPCreateEeGroupSubscriptions(c *gin.Context) {

// HTTPQueryEeGroupSubscriptions - Retrieves the ee subscriptions of a group of UEs or any UE
func HTTPQueryEeGroupSubscriptions(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueGroupId"] = c.Params.ByName("ueGroupId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPRemoveeeSubscriptions - Deletes a eeSubscription
func HTTPRemoveeeSubscriptions(c *gin.Context) {
auth_arr := authorizationCheck(c)
if auth_arr != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")
req.Params["subsId"] = c.Params.ByName("subsId")
Expand All @@ -50,11 +45,6 @@ func HTTPRemoveeeSubscriptions(c *gin.Context) {

// HTTPUpdateEesubscriptions - Stores an individual ee subscriptions of a UE
func HTTPUpdateEesubscriptions(c *gin.Context) {
auth_arr := authorizationCheck(c)
if auth_arr != nil {
return
}

var eeSubscription models.EeSubscription

requestBody, err := c.GetRawData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPCreateEeSubscriptions - Create individual EE subscription
func HTTPCreateEeSubscriptions(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

var eeSubscription models.EeSubscription

requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -77,11 +72,6 @@ func HTTPCreateEeSubscriptions(c *gin.Context) {

// HTTPQueryeesubscriptions - Retrieves the ee subscriptions of a UE
func HTTPQueryeesubscriptions(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueGroupId"] = c.Params.ByName("ueGroupId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPApplicationDataInfluenceDataInfluenceIdDelete - Delete an individual Influence Data resource
func HTTPApplicationDataInfluenceDataInfluenceIdDelete(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

// New HTTP request
req := httpwrapper.NewRequest(c.Request, nil)
req.Params["influenceId"] = c.Params.ByName("influenceId")
Expand Down Expand Up @@ -62,11 +57,6 @@ func HTTPApplicationDataInfluenceDataInfluenceIdPatch(c *gin.Context) {

// HTTPApplicationDataInfluenceDataInfluenceIdPut - Create or update an individual Influence Data resource
func HTTPApplicationDataInfluenceDataInfluenceIdPut(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

// Get HTTP request body
requestBody, err := c.GetRawData()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPApplicationDataInfluenceDataSubsToNotifyGet -
func HTTPApplicationDataInfluenceDataSubsToNotifyGet(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

// New HTTP request
req := httpwrapper.NewRequest(c.Request, nil)
req.Query["dnn"] = c.QueryArray("dnn")
Expand Down Expand Up @@ -55,11 +50,6 @@ func HTTPApplicationDataInfluenceDataSubsToNotifyGet(c *gin.Context) {

// HTTPApplicationDataInfluenceDataSubsToNotifyPost -
func HTTPApplicationDataInfluenceDataSubsToNotifyPost(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

// Get HTTP request body
requestBody, err := c.GetRawData()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPAmfContext3gpp - To modify operator specific data of a UE
func HTTPPatchOperSpecData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

var patchItemArray []models.PatchItem

requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -77,11 +72,6 @@ func HTTPPatchOperSpecData(c *gin.Context) {

// HTTPQueryOperSpecData - Retrieves the operator specific data of a UE
func HTTPQueryOperSpecData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPGetppData - Read the profile of a given UE
func HTTPGetppData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPModifyPpData - modify the provisioned parameter data
func HTTPModifyPpData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

var patchItemArray []models.PatchItem

requestBody, err := c.GetRawData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPGetIdentityData - Retrieve identity data by SUPI or GPSI
func HTTPGetIdentityData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPGetOdbData - Retrieve ODB Data data by SUPI or GPSI
func HTTPGetOdbData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
5 changes: 0 additions & 5 deletions internal/sbi/datarepository/api_retrieval_of_shared_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPGetSharedData - retrieve shared data
func HTTPGetSharedData(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

sharedDataIdArray := c.QueryArray("shared-data-ids")
req := httpwrapper.NewRequest(c.Request, nil)
req.Query["sharedDataIds"] = sharedDataIdArray
Expand Down
5 changes: 0 additions & 5 deletions internal/sbi/datarepository/api_subs_to_notify_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPPostSubscriptionDataSubscriptions - Subscription data subscriptions
func HTTPPostSubscriptionDataSubscriptions(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

var subscriptionDataSubscriptions models.SubscriptionDataSubscriptions

requestBody, err := c.GetRawData()
Expand Down
5 changes: 0 additions & 5 deletions internal/sbi/datarepository/api_subs_to_notify_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (

// HTTPRemovesubscriptionDataSubscriptions - Deletes a subscriptionDataSubscriptions
func HTTPRemovesubscriptionDataSubscriptions(c *gin.Context) {
auth_err := authorizationCheck(c)
if auth_err != nil {
return
}

req := httpwrapper.NewRequest(c.Request, nil)
req.Params["ueId"] = c.Params.ByName("ueId")

Expand Down
Loading

0 comments on commit 61c552d

Please sign in to comment.