Skip to content

Commit

Permalink
Merge pull request #103 from andy89923/feat/oauth2
Browse files Browse the repository at this point in the history
  • Loading branch information
ianchen0119 authored Jun 25, 2024
2 parents 7f9f631 + 1ac2155 commit 7458449
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
10 changes: 8 additions & 2 deletions backend/WebUI/api_charging.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package WebUI

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -125,7 +124,14 @@ func GetChargingRecord(c *gin.Context) {
if amfUris := webuiSelf.GetOamUris(models.NfType_AMF); amfUris != nil {
requestUri := fmt.Sprintf("%s/namf-oam/v1/registered-ue-context", amfUris[0])

res, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, requestUri, nil)
ctx, pd, tokerErr := webui_context.GetSelf().GetTokenCtx(models.ServiceName_NAMF_OAM, models.NfType_AMF)
if tokerErr != nil {
logger.ProcLog.Errorf("GetTokenCtx error: %+v", tokerErr)
c.JSON(http.StatusInternalServerError, pd)
return
}

res, err := http.NewRequestWithContext(ctx, http.MethodGet, requestUri, nil)
if err != nil {
logger.ProcLog.Error(err)
c.JSON(http.StatusInternalServerError, gin.H{})
Expand Down
12 changes: 7 additions & 5 deletions backend/WebUI/api_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ func GetSmfUserPlaneInfo() (interface{}, error) {
webuiSelf := webui_context.GetSelf()
webuiSelf.UpdateNfProfiles()

ctx, _, err := webuiSelf.GetTokenCtx(models.ServiceName_NSMF_OAM, models.NfType_SMF)
if err != nil {
logger.ConsumerLog.Infof("GetTokenCtx: service %v, err: %+v", models.ServiceName_NSMF_OAM, err)
}

var jsonData interface{}

// TODO: support fetching data from multiple SMF
if smfUris := webuiSelf.GetOamUris(models.NfType_SMF); smfUris != nil {
requestUri := fmt.Sprintf("%s/nsmf-oam/v1/user-plane-info/", smfUris[0])

ctx, pd, err := webuiSelf.GetTokenCtx(models.ServiceName_NSMF_OAM, models.NfType_SMF)
if err != nil {
logger.ConsumerLog.Infof("GetTokenCtx: service %v, err: %+v", models.ServiceName_NSMF_OAM, err)
return pd, err
}

req, err_req := http.NewRequestWithContext(ctx, http.MethodGet, requestUri, nil)
if err_req != nil {
logger.ProcLog.Error(err_req)
Expand Down
20 changes: 17 additions & 3 deletions backend/WebUI/api_webui.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package WebUI

import (
"context"
"crypto/rand"
"crypto/tls"
"encoding/json"
Expand Down Expand Up @@ -1788,7 +1787,14 @@ func GetRegisteredUEContext(c *gin.Context) {
requestUri = fmt.Sprintf("%s/namf-oam/v1/registered-ue-context", amfUris[0])
}

req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, requestUri, nil)
ctx, pd, tokerErr := webui_context.GetSelf().GetTokenCtx(models.ServiceName_NAMF_OAM, models.NfType_AMF)
if tokerErr != nil {
logger.ProcLog.Errorf("GetTokenCtx error: %+v", tokerErr)
c.JSON(http.StatusInternalServerError, pd)
return
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestUri, nil)
if err != nil {
logger.ProcLog.Error(err)
c.JSON(http.StatusInternalServerError, gin.H{})
Expand Down Expand Up @@ -1845,7 +1851,15 @@ func GetUEPDUSessionInfo(c *gin.Context) {
// TODO: support fetching data from multiple SMF
if smfUris := webuiSelf.GetOamUris(models.NfType_SMF); smfUris != nil {
requestUri := fmt.Sprintf("%s/nsmf-oam/v1/ue-pdu-session-info/%s", smfUris[0], smContextRef)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, requestUri, nil)

ctx, pd, tokerErr := webui_context.GetSelf().GetTokenCtx(models.ServiceName_NSMF_OAM, models.NfType_SMF)
if tokerErr != nil {
logger.ProcLog.Errorf("GetTokenCtx error: %+v", tokerErr)
c.JSON(http.StatusInternalServerError, pd)
return
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestUri, nil)
if err != nil {
logger.ProcLog.Error(err)
c.JSON(http.StatusInternalServerError, gin.H{})
Expand Down

0 comments on commit 7458449

Please sign in to comment.