Skip to content

Commit

Permalink
Merge pull request #4 from free5gc/feat/nef-nfs-oauth-support
Browse files Browse the repository at this point in the history
feat: Add NF Consumers Support OAuth2
  • Loading branch information
tim-ywliu authored Apr 23, 2024
2 parents 1b4ca0d + 9c22a2c commit 6e29dc5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 17 deletions.
38 changes: 31 additions & 7 deletions internal/sbi/consumer/pcf_service.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package consumer

import (
"context"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -65,8 +64,13 @@ func (s *npcfService) GetAppSession(appSessionId string) (int, interface{}) {
}
client := s.getClient(uri)

ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NPCF_POLICYAUTHORIZATION, models.NfType_PCF)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.IndividualApplicationSessionContextDocumentApi.
GetAppSession(context.Background(), appSessionId)
GetAppSession(ctx, appSessionId)

if rsp != nil {
defer func() {
Expand Down Expand Up @@ -108,7 +112,12 @@ func (s *npcfService) PostAppSessions(asc *models.AppSessionContext) (int, inter
}
client := s.getClient(uri)

result, rsp, err = client.ApplicationSessionsCollectionApi.PostAppSessions(context.TODO(), *asc)
ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NPCF_POLICYAUTHORIZATION, models.NfType_PCF)
if err != nil {
return rspCode, rspBody, appSessID
}

result, rsp, err = client.ApplicationSessionsCollectionApi.PostAppSessions(ctx, *asc)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -155,9 +164,14 @@ func (s *npcfService) PutAppSession(
}
client := s.getClient(uri)

ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NPCF_POLICYAUTHORIZATION, models.NfType_PCF)
if err != nil {
return rspCode, rspBody, appSessID
}

appSessID = appSessionId
result, rsp, err = client.IndividualApplicationSessionContextDocumentApi.
GetAppSession(context.Background(), appSessionId)
GetAppSession(ctx, appSessionId)
if rsp != nil {
if rsp.Body != nil {
if bodyCloseErr := rsp.Body.Close(); bodyCloseErr != nil {
Expand All @@ -169,7 +183,7 @@ func (s *npcfService) PutAppSession(
if rsp.StatusCode == http.StatusOK {
// Patch
result, rsp, err = client.IndividualApplicationSessionContextDocumentApi.ModAppSession(
context.Background(), appSessionId, *ascUpdateData)
ctx, appSessionId, *ascUpdateData)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -224,8 +238,13 @@ func (s *npcfService) PatchAppSession(appSessionId string,
}
client := s.getClient(uri)

ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NPCF_POLICYAUTHORIZATION, models.NfType_PCF)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.IndividualApplicationSessionContextDocumentApi.ModAppSession(
context.Background(), appSessionId, *ascUpdateData)
ctx, appSessionId, *ascUpdateData)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -270,8 +289,13 @@ func (s *npcfService) DeleteAppSession(appSessionId string) (int, interface{}) {
EventsSubscReqData: optional.NewInterface(models.EventsSubscReqData{}),
}

ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NPCF_POLICYAUTHORIZATION, models.NfType_PCF)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.IndividualApplicationSessionContextDocumentApi.DeleteAppSession(
context.Background(), appSessionId, param)
ctx, appSessionId, param)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down
64 changes: 54 additions & 10 deletions internal/sbi/consumer/udr_service.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package consumer

import (
"context"
"net/http"
"sync"

Expand Down Expand Up @@ -68,8 +67,13 @@ func (s *nudrService) AppDataInfluenceDataGet(influenceIDs []string) (int, inter
InfluenceIds: optional.NewInterface(influenceIDs),
}

ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.InfluenceDataApi.
ApplicationDataInfluenceDataGet(context.Background(), param)
ApplicationDataInfluenceDataGet(ctx, param)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -113,8 +117,13 @@ func (s *nudrService) AppDataInfluenceDataIdGet(influenceID string) (int, interf
InfluenceIds: optional.NewInterface(influenceID),
}

ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.InfluenceDataApi.
ApplicationDataInfluenceDataGet(context.Background(), param)
ApplicationDataInfluenceDataGet(ctx, param)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -156,8 +165,13 @@ func (s *nudrService) AppDataInfluenceDataPut(influenceID string,
}
client := s.getClient(uri)

ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.IndividualInfluenceDataDocumentApi.
ApplicationDataInfluenceDataInfluenceIdPut(context.TODO(), influenceID, *tiData)
ApplicationDataInfluenceDataInfluenceIdPut(ctx, influenceID, *tiData)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -202,7 +216,12 @@ func (s *nudrService) AppDataPfdsGet(appIDs []string) (int, interface{}) {
AppId: optional.NewInterface(appIDs),
}

result, rsp, err = client.DefaultApi.ApplicationDataPfdsGet(context.TODO(), param)
ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.DefaultApi.ApplicationDataPfdsGet(ctx, param)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -243,7 +262,12 @@ func (s *nudrService) AppDataPfdsAppIdPut(appID string, pfdDataForApp *models.Pf
}
client := s.getClient(uri)

result, rsp, err = client.DefaultApi.ApplicationDataPfdsAppIdPut(context.TODO(), appID, *pfdDataForApp)
ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.DefaultApi.ApplicationDataPfdsAppIdPut(ctx, appID, *pfdDataForApp)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -283,7 +307,12 @@ func (s *nudrService) AppDataPfdsAppIdDelete(appID string) (int, interface{}) {
}
client := s.getClient(uri)

rsp, err = client.DefaultApi.ApplicationDataPfdsAppIdDelete(context.TODO(), appID)
ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
if err != nil {
return rspCode, rspBody
}

rsp, err = client.DefaultApi.ApplicationDataPfdsAppIdDelete(ctx, appID)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -322,7 +351,12 @@ func (s *nudrService) AppDataPfdsAppIdGet(appID string) (int, interface{}) {
}
client := s.getClient(uri)

result, rsp, err = client.DefaultApi.ApplicationDataPfdsAppIdGet(context.TODO(), appID)
ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.DefaultApi.ApplicationDataPfdsAppIdGet(ctx, appID)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -364,8 +398,13 @@ func (s *nudrService) AppDataInfluenceDataPatch(
}
client := s.getClient(uri)

ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
if err != nil {
return rspCode, rspBody
}

result, rsp, err = client.IndividualInfluenceDataDocumentApi.
ApplicationDataInfluenceDataInfluenceIdPatch(context.Background(), influenceID, *tiSubPatch)
ApplicationDataInfluenceDataInfluenceIdPatch(ctx, influenceID, *tiSubPatch)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down Expand Up @@ -404,8 +443,13 @@ func (s *nudrService) AppDataInfluenceDataDelete(influenceID string) (int, inter
}
client := s.getClient(uri)

ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR)
if err != nil {
return rspCode, rspBody
}

rsp, err = client.IndividualInfluenceDataDocumentApi.
ApplicationDataInfluenceDataInfluenceIdDelete(context.Background(), influenceID)
ApplicationDataInfluenceDataInfluenceIdDelete(ctx, influenceID)
if rsp != nil {
defer func() {
if rsp.Request.Response != nil {
Expand Down

0 comments on commit 6e29dc5

Please sign in to comment.