Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/free5gc/util v1.2.0
github.com/gin-gonic/gin v1.10.0
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/google/uuid v1.3.0
github.com/google/uuid v1.6.0
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.21.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE=
Expand Down
3 changes: 1 addition & 2 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"sync"

"github.com/google/uuid"
"github.com/pkg/errors"

"github.com/free5gc/nrf/internal/logger"
Expand Down Expand Up @@ -48,7 +47,7 @@ func InitNrfContext() error {
config.Info.Version, config.Info.Description)
configuration := config.Configuration

nrfContext.NrfNfProfile.NfInstanceId = uuid.New().String()
nrfContext.NrfNfProfile.NfInstanceId = config.GetNfInstanceId()
nrfContext.NrfNfProfile.NfType = models.NrfNfManagementNfType_NRF
nrfContext.NrfNfProfile.NfStatus = models.NrfNfManagementNfStatus_REGISTERED
nrfContext.NfRegistNum = 0
Expand Down
32 changes: 32 additions & 0 deletions pkg/factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sync"

"github.com/asaskevich/govalidator"
"github.com/google/uuid"

"github.com/free5gc/nrf/internal/logger"
"github.com/free5gc/openapi/models"
Expand All @@ -25,6 +26,7 @@ const (
NrfDefaultRootCertPemPath = "./cert/root.pem"
NrfDefaultRootPrivateKeyPath = "./cert/root.key"
NrfDefaultConfigPath = "./config/nrfcfg.yaml"
NrfDefaultNfInstanceIdEnvVar = "NRF_NF_INSTANCE_ID"
NrfSbiDefaultIPv4 = "127.0.0.10"
NrfSbiDefaultPort = 8000
NrfSbiDefaultScheme = "https"
Expand Down Expand Up @@ -65,6 +67,7 @@ type Info struct {
}

type Configuration struct {
NfInstanceId string `yaml:"nfInstanceId,omitempty" valid:"optional,uuidv4"`
Sbi *Sbi `yaml:"sbi,omitempty" valid:"required"`
Metrics *Metrics `yaml:"metrics,omitempty" valid:"optional"`
MongoDBName string `yaml:"MongoDBName" valid:"required"`
Expand All @@ -80,6 +83,10 @@ type Logger struct {
}

func (c *Configuration) validate() (bool, error) {
if c.NfInstanceId == "" {
c.NfInstanceId = uuid.New().String()
}

if sbi := c.Sbi; sbi != nil {
if result, err := sbi.validate(); err != nil {
return result, err
Expand Down Expand Up @@ -125,6 +132,31 @@ func (c *Configuration) validate() (bool, error) {
return result, appendInvalid(err)
}

func (c *Config) GetNfInstanceId() string {
c.RLock()
defer c.RUnlock()

var nfInstanceId string

logger.CfgLog.Debugf("Fetching nfInstanceId from env var \"%s\"", NrfDefaultNfInstanceIdEnvVar)

if nfInstanceId = os.Getenv(NrfDefaultNfInstanceIdEnvVar); nfInstanceId == "" {
logger.CfgLog.Debugf("No value found for \"%s\" env, fallback on config nfInstanceId : %s",
NrfDefaultNfInstanceIdEnvVar, c.Configuration.NfInstanceId)
return c.Configuration.NfInstanceId
}

if err := uuid.Validate(nfInstanceId); err != nil {
logger.CfgLog.Errorf("Env var \"%s\" is not a valid uuid, "+
"fallback on configuration nfInstanceId : %s", NrfDefaultNfInstanceIdEnvVar, c.Configuration.NfInstanceId)
return c.Configuration.NfInstanceId
}

logger.CfgLog.Debugf("nfInstanceId from %s : %s", NrfDefaultNfInstanceIdEnvVar, nfInstanceId)

return nfInstanceId
}

type Sbi struct {
Scheme string `yaml:"scheme" valid:"scheme,required"`
RegisterIPv4 string `yaml:"registerIPv4,omitempty" valid:"host,optional"`
Expand Down