Skip to content

Commit

Permalink
Fix: Rebase & rollback config
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Dec 12, 2023
1 parent dad708a commit c9b5ac6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
21 changes: 8 additions & 13 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type UDMContext struct {
NFDiscoveryClient *Nnrf_NFDiscovery.APIClient
UdmUePool sync.Map // map[supi]*UdmUeContext
NrfUri string
NrfCerPem string
NrfCertPem string
GpsiSupiList models.IdentityData
SharedSubsDataMap map[string]models.SharedData // sharedDataIds as key
SubscriptionOfSharedDataChange sync.Map // subscriptionID as key
Expand Down Expand Up @@ -123,14 +123,14 @@ func InitUdmContext(context *UDMContext) {
}
}
udmContext.NrfUri = configuration.NrfUri
if configuration.NrfCerPem != "" {
context.NrfCerPem = configuration.NrfCerPem
if configuration.NrfCertPem != "" {
context.NrfCertPem = configuration.NrfCertPem
}
servingNameList := configuration.ServiceNameList

serviceList := configuration.ServiceList
udmContext.SuciProfiles = configuration.SuciProfiles

udmContext.InitNFService(serviceList, config.Info.Version)
udmContext.InitNFService(servingNameList, config.Info.Version)
}

func (context *UDMContext) ManageSmData(smDatafromUDR []models.SessionManagementSubscriptionData, snssaiFromReq string,
Expand Down Expand Up @@ -455,15 +455,11 @@ func (context *UDMContext) GetSDMUri() string {
return context.GetIPv4Uri() + factory.UdmSdmResUriPrefix
}

func (context *UDMContext) InitNFService(serviceList []factory.ServiceList, version string) {
func (context *UDMContext) InitNFService(serviceName []string, version string) {
tmpVersion := strings.Split(version, ".")
versionUri := "v" + tmpVersion[0]
for index, service := range serviceList {
name := models.ServiceName(service.ServiceName)
allowNfTypes := make([]models.NfType, len(service.AllowedNfTypes))
for idx, nf := range service.AllowedNfTypes {
allowNfTypes[idx] = models.NfType(nf)
}
for index, nameString := range serviceName {
name := models.ServiceName(nameString)
context.NfService[name] = models.NfService{
ServiceInstanceId: strconv.Itoa(index),
ServiceName: name,
Expand All @@ -483,7 +479,6 @@ func (context *UDMContext) InitNFService(serviceList []factory.ServiceList, vers
Port: int32(context.SBIPort),
},
},
AllowedNfTypes: allowNfTypes,
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions internal/sbi/consumer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ func SendRegisterNFInstance(nrfUri, nfInstanceId string, profile models.NfProfil
resouceNrfUri = resourceUri[:strings.Index(resourceUri, "/nnrf-nfm/")]
retrieveNfInstanceId = resourceUri[strings.LastIndex(resourceUri, "/")+1:]

oauth2 := nf.CustomInfo["oauth2"].(bool)
oauth2 := false
if nf.CustomInfo != nil {
oauth2 = nf.CustomInfo["oauth2"].(bool)
}
udm_context.GetSelf().OAuth2Required = oauth2
logger.MainLog.Infoln("OAuth2 setting receive from NRF:", oauth2)
if oauth2 && udm_context.GetSelf().NrfCerPem == "" {
logger.CfgLog.Error("OAuth2 enable but no nrfCerPem provided in config.")
if oauth2 && udm_context.GetSelf().NrfCertPem == "" {
logger.CfgLog.Error("OAuth2 enable but no nrfCertPem provided in config.")
}
break
} else {
Expand Down
4 changes: 2 additions & 2 deletions internal/util/init_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func InitUDMContext(udmContext *context.UDMContext) {
}
}
udmContext.NrfUri = configuration.NrfUri
serviceList := configuration.ServiceList
servingNameList := configuration.ServiceNameList

udmContext.SuciProfiles = configuration.SuciProfiles

udmContext.InitNFService(serviceList, config.Info.Version)
udmContext.InitNFService(servingNameList, config.Info.Version)
}
2 changes: 1 addition & 1 deletion internal/util/nf_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func AuthorizationCheck(c *gin.Context, serviceName string) error {
if udm_context.GetSelf().OAuth2Required {
oauth_err := oauth.VerifyOAuth(c.Request.Header.Get("Authorization"), serviceName,
udm_context.GetSelf().NrfCerPem)
udm_context.GetSelf().NrfCertPem)
if oauth_err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": oauth_err.Error()})
return oauth_err
Expand Down
20 changes: 7 additions & 13 deletions pkg/factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@ type Info struct {
Description string `yaml:"description,omitempty" valid:"type(string)"`
}

type ServiceList struct {
ServiceName string `yaml:"serviceName" valid:"required"`
AllowedNfTypes []string `yaml:"allowedNfTypes,omitempty" valid:"optional"`
}

type Configuration struct {
Sbi *Sbi `yaml:"sbi,omitempty" valid:"required"`
ServiceList []ServiceList `yaml:"serviceList,omitempty" valid:"required"`
NrfUri string `yaml:"nrfUri,omitempty" valid:"required, url"`
NrfCerPem string `yaml:"nrfCerPem,omitempty" valid:"type(string),minstringlength(1),optional"`
SuciProfiles []suci.SuciProfile `yaml:"SuciProfile,omitempty"`
Sbi *Sbi `yaml:"sbi,omitempty" valid:"required"`
ServiceNameList []string `yaml:"serviceNameList,omitempty" valid:"required"`
NrfUri string `yaml:"nrfUri,omitempty" valid:"required, url"`
NrfCertPem string `yaml:"nrfCertPem,omitempty" valid:"type(string),minstringlength(1),optional"`
SuciProfiles []suci.SuciProfile `yaml:"SuciProfile,omitempty"`
}
type Logger struct {
Enable bool `yaml:"enable" valid:"type(bool)"`
Expand All @@ -83,10 +78,9 @@ func (c *Configuration) validate() (bool, error) {
}
}

if c.ServiceList != nil {
if c.ServiceNameList != nil {
var errs govalidator.Errors
for _, service := range c.ServiceList {
v := service.ServiceName
for _, v := range c.ServiceNameList {
if v != "nudm-sdm" && v != "nudm-uecm" && v != "nudm-ueau" && v != "nudm-ee" && v != "nudm-pp" {
err := fmt.Errorf("Invalid ServiceNameList: [%s],"+
" value should be nudm-sdm or nudm-uecm or nudm-ueau or nudm-ee or nudm-pp", v)
Expand Down

0 comments on commit c9b5ac6

Please sign in to comment.