diff --git a/backend/factory/config.go b/backend/factory/config.go index 5de44c58c72380099cbcb343bd233d535c52f649..7c8d4c7be0f4fff2fd3d9d62dd136de06f50342e 100644 --- a/backend/factory/config.go +++ b/backend/factory/config.go @@ -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 { diff --git a/backend/webui_context/context.go b/backend/webui_context/context.go index 37aa6346a6785d0d06797fd3bff9f094620d08f1..29841cb582ce05adfc79277a9ae6e91c51edf37c 100644 --- a/backend/webui_context/context.go +++ b/backend/webui_context/context.go @@ -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) { diff --git a/backend/webui_context/nrf.go b/backend/webui_context/nrf.go new file mode 100644 index 0000000000000000000000000000000000000000..4519c3d05ffb3695670274bb6a07fafe7009c735 --- /dev/null +++ b/backend/webui_context/nrf.go @@ -0,0 +1,54 @@ +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 +} diff --git a/backend/webui_service/webui_init.go b/backend/webui_service/webui_init.go index 2bf29cb7476dfc50734d0cbd0b95b115dced2e25..c5cf5ef4d7e43043e363125f001cf17f23e8303e 100644 --- a/backend/webui_service/webui_init.go +++ b/backend/webui_service/webui_init.go @@ -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() diff --git a/config/webuicfg.yaml b/config/webuicfg.yaml index ed7aff3453dd8dcbf04cca071e3569062208d1cf..d0c04be25fc09b48acfaf2d3a85aab297924528f 100644 --- a/config/webuicfg.yaml +++ b/config/webuicfg.yaml @@ -1,11 +1,12 @@ 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