Skip to content

Commit

Permalink
feat: parametrize paths for TLS certificate and private key (#107)
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Faccin <[email protected]>
Co-authored-by: Ajay Lotan Thakur <[email protected]>
  • Loading branch information
dariofaccin and thakurajayL authored Jul 20, 2024
1 parent 7b154a0 commit d88df2c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/google/uuid"
"github.com/omec-project/nssf/factory"
"github.com/omec-project/nssf/logger"
"github.com/omec-project/nssf/util"
"github.com/omec-project/openapi/models"
)

Expand Down Expand Up @@ -53,6 +54,8 @@ type NSSFContext struct {
UriScheme models.UriScheme
RegisterIPv4 string
BindingIPv4 string
Key string
PEM string
NfService map[models.ServiceName]models.NfService
NrfUri string
SupportedPlmnList []models.PlmnId
Expand All @@ -75,6 +78,16 @@ func InitNssfContext() {
nssfContext.RegisterIPv4 = nssfConfig.Configuration.Sbi.RegisterIPv4
nssfContext.SBIPort = nssfConfig.Configuration.Sbi.Port
nssfContext.BindingIPv4 = os.Getenv(nssfConfig.Configuration.Sbi.BindingIPv4)
nssfContext.Key = util.NSSF_KEY_PATH // default key path
nssfContext.PEM = util.NSSF_PEM_PATH // default PEM path
if tls := nssfConfig.Configuration.Sbi.TLS; tls != nil {
if tls.Key != "" {
nssfContext.Key = tls.Key
}
if tls.PEM != "" {
nssfContext.PEM = tls.PEM
}
}
if nssfContext.BindingIPv4 != "" {
logger.ContextLog.Info("Parsing ServerIPv4 address from ENV Variable.")
} else {
Expand Down
6 changes: 6 additions & 0 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,19 @@ type Configuration struct {

type Sbi struct {
Scheme models.UriScheme `yaml:"scheme"`
TLS *TLS `yaml:"tls"`
// Currently only support IPv4 and thus `Ipv4Addr` field shall not be empty
RegisterIPv4 string `yaml:"registerIPv4,omitempty"` // IP that is registered at NRF.
// IPv6Addr string `yaml:"ipv6Addr,omitempty"`
BindingIPv4 string `yaml:"bindingIPv4,omitempty"` // IP used to run the server in the node.
Port int `yaml:"port"`
}

type TLS struct {
PEM string `yaml:"pem,omitempty"`
Key string `yaml:"key,omitempty"`
}

type AmfConfig struct {
NfId string `yaml:"nfId"`
SupportedNssaiAvailabilityData []models.SupportedNssaiAvailabilityData `yaml:"supportedNssaiAvailabilityData"`
Expand Down
2 changes: 1 addition & 1 deletion service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (nssf *NSSF) Start() {
if serverScheme == "http" {
err = server.ListenAndServe()
} else if serverScheme == "https" {
err = server.ListenAndServeTLS(util.NSSF_PEM_PATH, util.NSSF_KEY_PATH)
err = server.ListenAndServeTLS(self.PEM, self.Key)
}

if err != nil {
Expand Down

0 comments on commit d88df2c

Please sign in to comment.