Skip to content
Snippets Groups Projects
Unverified Commit ba1cd77b authored by Kunihiro Ishiguro's avatar Kunihiro Ishiguro Committed by GitHub
Browse files

Query to NRF for NFProfile instead of getting from mongodb. (#63)

parent 368e72ee
No related branches found
No related tags found
No related merge requests found
......@@ -35,13 +35,14 @@ func (c *Config) Validate() (bool, error) {
}
type Info struct {
Version string `yaml:"version,omitempty" valid:"required,in(1.0.1)"`
Version string `yaml:"version,omitempty" valid:"required,in(1.0.2)"`
Description string `yaml:"description,omitempty" valid:"type(string)"`
}
type Configuration struct {
WebServer *WebServer `yaml:"webServer,omitempty" valid:"optional"`
Mongodb *Mongodb `yaml:"mongodb" valid:"required"`
NrfUri string `yaml:"nrfUri" valid:"required"`
}
type Logger struct {
......
......@@ -4,8 +4,6 @@ import (
"fmt"
"github.com/free5gc/openapi/models"
timedecode "github.com/free5gc/util/mapstruct"
"github.com/free5gc/util/mongoapi"
"github.com/free5gc/webconsole/backend/logger"
)
......@@ -22,19 +20,32 @@ type NfOamInstance struct {
Uri string
}
var NrfUri string
func NrfAmfUri() string {
return NrfUri + "/nnrf-disc/v1/nf-instances?target-nf-type=AMF&requester-nf-type=AMF"
}
func NrfSmfUri() string {
return NrfUri + "/nnrf-disc/v1/nf-instances?target-nf-type=SMF&requester-nf-type=AMF"
}
func (context *WEBUIContext) UpdateNfProfiles() {
nfProfilesRaw, err := mongoapi.RestfulAPIGetMany("NfProfile", nil)
var nfProfiles []models.NfProfile
nfProfiles, err := NrfGetNfProfiles(NrfAmfUri())
if err != nil {
logger.CtxLog.Error(err)
return
}
var nfProfiles []models.NfProfile
if err := timedecode.Decode(nfProfilesRaw, &nfProfiles); err != nil {
context.NFProfiles = append(context.NFProfiles, nfProfiles...)
nfProfiles, err = NrfGetNfProfiles(NrfSmfUri())
if err != nil {
logger.CtxLog.Error(err)
return
}
context.NFProfiles = nfProfiles
context.NFProfiles = append(context.NFProfiles, nfProfiles...)
for _, nfProfile := range context.NFProfiles {
if nfProfile.NfServices == nil || context.NfProfileAlreadyExists(nfProfile) {
......
package webui_context
import (
"context"
"crypto/tls"
"encoding/json"
"io"
"net/http"
"github.com/free5gc/openapi/models"
"github.com/free5gc/webconsole/backend/logger"
)
type NfInstance struct {
ValidityPeriod int `json:"validityPeriod"`
NfInstances []models.NfProfile `json:"nfInstances"`
}
func NrfGetNfProfiles(requestUri string) ([]models.NfProfile, error) {
var nfProfiles []models.NfProfile
httpsClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, requestUri, nil)
if err != nil {
return nfProfiles, err
}
resp, err := httpsClient.Do(req)
if err != nil {
return nfProfiles, err
}
defer func() {
if closeErr := resp.Body.Close(); closeErr != nil {
logger.CtxLog.Error(err)
}
}()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nfProfiles, err
}
var nfInstance NfInstance
err = json.Unmarshal(body, &nfInstance)
if err != nil {
return nfProfiles, err
}
return nfInstance.NfInstances, nil
}
......@@ -78,6 +78,9 @@ func (a *WebuiApp) Start(tlsKeyLogPath string) {
return
}
nrfUri := factory.WebuiConfig.Configuration.NrfUri
webui_context.NrfUri = nrfUri
logger.InitLog.Infoln("Server started")
router := WebUI.NewRouter()
......
info:
version: 1.0.1
version: 1.0.2
description: WebUI initial local configuration
configuration:
mongodb: # the mongodb connected by this webui
name: free5gc # name of the mongodb
url: mongodb://localhost:27017 # a valid URL of the mongodb
nrfUri: http://127.0.0.10:8000 # a valid URI of NRF
logger: # log output setting
enable: true # true or false
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment