Skip to content

Commit

Permalink
fix: adjust linter and fix linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Jun 20, 2024
1 parent e20205e commit 5b28214
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 247 deletions.
366 changes: 210 additions & 156 deletions .golangci.yml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type NRFContext struct {
NrfCert *x509.Certificate
}

const (
NfProfileCollName string = "NfProfile"
)

type NFContext interface {
AuthorizationCheck(token string, serviceName models.ServiceName) error
}
Expand Down
13 changes: 6 additions & 7 deletions internal/context/dataconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// Ipv6ToInt - Convert Ipv6 string to *bigInt
func Ipv6ToInt(ipv6 string) *big.Int {
ipv6 = ipv6 + "/32"
ipv6 += "/32"
ip, _, err := net.ParseCIDR(ipv6)
if err != nil {
fmt.Println("Error", ip, err)
Expand All @@ -24,7 +24,7 @@ func Ipv6ToInt(ipv6 string) *big.Int {

// Ipv4ToInt - Convert Ipv4 string to int64
func Ipv4ToInt(ipv4 string) int64 {
ipv4 = ipv4 + "/24"
ipv4 += "/24"
ip, _, err := net.ParseCIDR(ipv4)
if err != nil {
fmt.Println("Error", ip, err)
Expand Down Expand Up @@ -70,14 +70,13 @@ func EncodeGroupId(groupId string) string {
for i := 0; i < (10 - len(externalGroupIdentitySplit[0])); i++ {
groupServiceIdentifierPadding += "0"
}
encodedGroupId = encodedGroupId + groupServiceIdentifierPadding + strconv.Itoa(encodedGroupServiceIdentifier)

encodedGroupId = encodedGroupId + externalGroupIdentitySplit[1]
encodedGroupId += groupServiceIdentifierPadding + strconv.Itoa(encodedGroupServiceIdentifier)
encodedGroupId += externalGroupIdentitySplit[1]

if len(externalGroupIdentitySplit[2]) == 2 {
encodedGroupId = encodedGroupId + "0" + externalGroupIdentitySplit[2]
encodedGroupId += "0" + externalGroupIdentitySplit[2]
} else {
encodedGroupId = encodedGroupId + externalGroupIdentitySplit[2]
encodedGroupId += externalGroupIdentitySplit[2]
}

var encodedLocalGroupId int
Expand Down
24 changes: 13 additions & 11 deletions internal/context/management_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func NnrfNFManagementDataModel(nf *models.NfProfile, nfprofile models.NfProfile)
}

func SetsubscriptionId() (string, error) {
buffer := make([]byte, 16)
subscriptionIdSize := 16

buffer := make([]byte, subscriptionIdSize)
_, err := rand.Read(buffer)
if err != nil {
return "", err
Expand Down Expand Up @@ -454,7 +456,7 @@ func setUriListByFilter(filter bson.M, uriList *[]string) {
}

var filterNfTypeResults []models.NrfSubscriptionData
if err := openapi.Convert(filterNfTypeResultsRaw, &filterNfTypeResults); err != nil {
if err = openapi.Convert(filterNfTypeResultsRaw, &filterNfTypeResults); err != nil {
logger.NfmLog.Errorf("setUriListByFilter err: %+v", err)
}

Expand All @@ -463,7 +465,7 @@ func setUriListByFilter(filter bson.M, uriList *[]string) {
}
}

func nnrfUriList(originalUL *UriList, UL *UriList, location []string) {
func nnrfUriList(originalUL *UriList, ul *UriList, location []string) {
var i int
var b *Links
var flag bool
Expand Down Expand Up @@ -495,7 +497,7 @@ func nnrfUriList(originalUL *UriList, UL *UriList, location []string) {
}

b.Item = c
UL.Link = *b
ul.Link = *b
}

func GetNofificationUri(nfProfile models.NfProfile) []string {
Expand Down Expand Up @@ -536,8 +538,8 @@ func GetNofificationUri(nfProfile models.NfProfile) []string {
if nfProfile.AmfInfo != nil {
amfCond := bson.M{
"subscrCond": bson.M{
"amfSetId": (*nfProfile.AmfInfo).AmfSetId,
"amfRegionId": (*nfProfile.AmfInfo).AmfRegionId,
"amfSetId": nfProfile.AmfInfo.AmfSetId,
"amfRegionId": nfProfile.AmfInfo.AmfRegionId,
},
}
setUriListByFilter(amfCond, &uriList)
Expand All @@ -546,9 +548,9 @@ func GetNofificationUri(nfProfile models.NfProfile) []string {
// GuamiListCond
if nfProfile.AmfInfo != nil {
var guamiListFilter bson.M
if (*nfProfile.AmfInfo).GuamiList != nil {
if nfProfile.AmfInfo.GuamiList != nil {
var guamiListBsonArray bson.A
for _, guami := range *(*nfProfile.AmfInfo).GuamiList {
for _, guami := range *nfProfile.AmfInfo.GuamiList {
tmp, err := json.Marshal(guami)
if err != nil {
logger.NfmLog.Error(err)
Expand Down Expand Up @@ -623,23 +625,23 @@ func GetNofificationUri(nfProfile models.NfProfile) []string {
nfGroupCond := bson.M{
"subscrCond": bson.M{
"nfType": nfProfile.NfType,
"nfGroupId": (*nfProfile.UdrInfo).GroupId,
"nfGroupId": nfProfile.UdrInfo.GroupId,
},
}
setUriListByFilter(nfGroupCond, &uriList)
} else if nfProfile.UdmInfo != nil {
nfGroupCond := bson.M{
"subscrCond": bson.M{
"nfType": nfProfile.NfType,
"nfGroupId": (*nfProfile.UdmInfo).GroupId,
"nfGroupId": nfProfile.UdmInfo.GroupId,
},
}
setUriListByFilter(nfGroupCond, &uriList)
} else if nfProfile.AusfInfo != nil {
nfGroupCond := bson.M{
"subscrCond": bson.M{
"nfType": nfProfile.NfType,
"nfGroupId": (*nfProfile.AusfInfo).GroupId,
"nfGroupId": nfProfile.AusfInfo.GroupId,
},
}
setUriListByFilter(nfGroupCond, &uriList)
Expand Down
55 changes: 28 additions & 27 deletions internal/sbi/api_nfmanagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/mitchellh/mapstructure"
"go.mongodb.org/mongo-driver/bson"

nrf_context "github.com/free5gc/nrf/internal/context"
"github.com/free5gc/nrf/internal/logger"
"github.com/free5gc/nrf/internal/util"
"github.com/free5gc/openapi"
Expand Down Expand Up @@ -332,7 +333,7 @@ func (s *Server) getUdrInfo() map[string]models.UdrInfo {
servedUdrInfo := make(map[string]models.UdrInfo)
var UDRProfile models.NfProfile

collName := "NfProfile"
collName := nrf_context.NfProfileCollName
filter := bson.M{"nfType": "UDR"}

UDR, err := mongoapi.RestfulAPIGetMany(collName, filter)
Expand All @@ -341,12 +342,12 @@ func (s *Server) getUdrInfo() map[string]models.UdrInfo {
}

var UDRStruct []models.NfProfile
if err := timedecode.Decode(UDR, &UDRStruct); err != nil {
if err = timedecode.Decode(UDR, &UDRStruct); err != nil {
logger.NfmLog.Errorf("getUdrInfo err: %+v", err)
}

for i := 0; i < len(UDRStruct); i++ {
err := mapstructure.Decode(UDRStruct[i], &UDRProfile)
err = mapstructure.Decode(UDRStruct[i], &UDRProfile)
if err != nil {
panic(err)
}
Expand All @@ -360,7 +361,7 @@ func (s *Server) getUdmInfo() map[string]models.UdmInfo {
servedUdmInfo := make(map[string]models.UdmInfo)
var UDMProfile models.NfProfile

collName := "NfProfile"
collName := nrf_context.NfProfileCollName
filter := bson.M{"nfType": "UDM"}

UDM, err := mongoapi.RestfulAPIGetMany(collName, filter)
Expand All @@ -369,12 +370,12 @@ func (s *Server) getUdmInfo() map[string]models.UdmInfo {
}

var UDMStruct []models.NfProfile
if err := timedecode.Decode(UDM, &UDMStruct); err != nil {
if err = timedecode.Decode(UDM, &UDMStruct); err != nil {
logger.NfmLog.Errorf("getUdmInfo err: %+v", err)
}

for i := 0; i < len(UDMStruct); i++ {
err := mapstructure.Decode(UDMStruct[i], &UDMProfile)
err = mapstructure.Decode(UDMStruct[i], &UDMProfile)
if err != nil {
panic(err)
}
Expand All @@ -388,7 +389,7 @@ func (s *Server) getAusfInfo() map[string]models.AusfInfo {
servedAusfInfo := make(map[string]models.AusfInfo)
var AUSFProfile models.NfProfile

collName := "NfProfile"
collName := nrf_context.NfProfileCollName
filter := bson.M{"nfType": "AUSF"}

AUSF, err := mongoapi.RestfulAPIGetMany(collName, filter)
Expand All @@ -397,11 +398,11 @@ func (s *Server) getAusfInfo() map[string]models.AusfInfo {
}

var AUSFStruct []models.NfProfile
if err := timedecode.Decode(AUSF, &AUSFStruct); err != nil {
if err = timedecode.Decode(AUSF, &AUSFStruct); err != nil {
logger.NfmLog.Errorf("getAusfInfo err: %+v", err)
}
for i := 0; i < len(AUSFStruct); i++ {
err := mapstructure.Decode(AUSFStruct[i], &AUSFProfile)
err = mapstructure.Decode(AUSFStruct[i], &AUSFProfile)
if err != nil {
panic(err)
}
Expand All @@ -415,7 +416,7 @@ func (s *Server) getAmfInfo() map[string]models.AmfInfo {
servedAmfinfo := make(map[string]models.AmfInfo)
var AMFProfile models.NfProfile

collName := "NfProfile"
collName := nrf_context.NfProfileCollName
filter := bson.M{"nfType": "AMF"}

AMF, err := mongoapi.RestfulAPIGetMany(collName, filter)
Expand All @@ -424,11 +425,11 @@ func (s *Server) getAmfInfo() map[string]models.AmfInfo {
}

var AMFStruct []models.NfProfile
if err := timedecode.Decode(AMF, &AMFStruct); err != nil {
if err = timedecode.Decode(AMF, &AMFStruct); err != nil {
logger.NfmLog.Errorf("getAmfInfo err: %+v", err)
}
for i := 0; i < len(AMFStruct); i++ {
err := mapstructure.Decode(AMFStruct[i], &AMFProfile)
err = mapstructure.Decode(AMFStruct[i], &AMFProfile)
if err != nil {
panic(err)
}
Expand All @@ -442,7 +443,7 @@ func (s *Server) getSmfInfo() map[string]models.SmfInfo {
servedSmfInfo := make(map[string]models.SmfInfo)
var SMFProfile models.NfProfile

collName := "NfProfile"
collName := nrf_context.NfProfileCollName
filter := bson.M{"nfType": "SMF"}

SMF, err := mongoapi.RestfulAPIGetMany(collName, filter)
Expand All @@ -451,11 +452,11 @@ func (s *Server) getSmfInfo() map[string]models.SmfInfo {
}

var SMFStruct []models.NfProfile
if err := timedecode.Decode(SMF, &SMFStruct); err != nil {
if err = timedecode.Decode(SMF, &SMFStruct); err != nil {
logger.NfmLog.Errorf("getSmfInfo err: %+v", err)
}
for i := 0; i < len(SMFStruct); i++ {
err := mapstructure.Decode(SMFStruct[i], &SMFProfile)
err = mapstructure.Decode(SMFStruct[i], &SMFProfile)
if err != nil {
panic(err)
}
Expand All @@ -469,7 +470,7 @@ func (s *Server) getUpfInfo() map[string]models.UpfInfo {
servedUpfInfo := make(map[string]models.UpfInfo)
var UPFProfile models.NfProfile

collName := "NfProfile"
collName := nrf_context.NfProfileCollName
filter := bson.M{"nfType": "UPF"}

UPF, err := mongoapi.RestfulAPIGetMany(collName, filter)
Expand All @@ -478,11 +479,11 @@ func (s *Server) getUpfInfo() map[string]models.UpfInfo {
}

var UPFStruct []models.NfProfile
if err := timedecode.Decode(UPF, &UPFStruct); err != nil {
if err = timedecode.Decode(UPF, &UPFStruct); err != nil {
logger.NfmLog.Errorf("getUpfInfo err: %+v", err)
}
for i := 0; i < len(UPFStruct); i++ {
err := mapstructure.Decode(UPFStruct[i], &UPFProfile)
err = mapstructure.Decode(UPFStruct[i], &UPFProfile)
if err != nil {
panic(err)
}
Expand All @@ -496,7 +497,7 @@ func (s *Server) getPcfInfo() map[string]models.PcfInfo {
servedPcfInfo := make(map[string]models.PcfInfo)
var PCFProfile models.NfProfile

collName := "NfProfile"
collName := nrf_context.NfProfileCollName
filter := bson.M{"nfType": "PCF"}

PCF, err := mongoapi.RestfulAPIGetMany(collName, filter)
Expand All @@ -505,11 +506,11 @@ func (s *Server) getPcfInfo() map[string]models.PcfInfo {
}

var PCFStruct []models.NfProfile
if err := timedecode.Decode(PCF, &PCFStruct); err != nil {
if err = timedecode.Decode(PCF, &PCFStruct); err != nil {
logger.NfmLog.Errorf("getPcfInfo err: %+v", err)
}
for i := 0; i < len(PCFStruct); i++ {
err := mapstructure.Decode(PCFStruct[i], &PCFProfile)
err = mapstructure.Decode(PCFStruct[i], &PCFProfile)
if err != nil {
panic(err)
}
Expand All @@ -523,7 +524,7 @@ func (s *Server) getBsfInfo() map[string]models.BsfInfo {
servedBsfInfo := make(map[string]models.BsfInfo)
var BSFProfile models.NfProfile

collName := "NfProfile"
collName := nrf_context.NfProfileCollName
filter := bson.M{"nfType": "BSF"}

BSF, err := mongoapi.RestfulAPIGetMany(collName, filter)
Expand All @@ -532,11 +533,11 @@ func (s *Server) getBsfInfo() map[string]models.BsfInfo {
}

var BSFStruct []models.NfProfile
if err := timedecode.Decode(BSF, &BSFStruct); err != nil {
if err = timedecode.Decode(BSF, &BSFStruct); err != nil {
logger.NfmLog.Errorf("getBsfInfo err: %+v", err)
}
for i := 0; i < len(BSFStruct); i++ {
err := mapstructure.Decode(BSFStruct[i], &BSFProfile)
err = mapstructure.Decode(BSFStruct[i], &BSFProfile)
if err != nil {
panic(err)
}
Expand All @@ -550,7 +551,7 @@ func (s *Server) getChfInfo() map[string]models.ChfInfo {
servedChfInfo := make(map[string]models.ChfInfo)
var CHFProfile models.NfProfile

collName := "NfProfile"
collName := nrf_context.NfProfileCollName
filter := bson.M{"nfType": "CHF"}

CHF, err := mongoapi.RestfulAPIGetMany(collName, filter)
Expand All @@ -559,11 +560,11 @@ func (s *Server) getChfInfo() map[string]models.ChfInfo {
}

var CHFStruct []models.NfProfile
if err := timedecode.Decode(CHF, &CHFStruct); err != nil {
if err = timedecode.Decode(CHF, &CHFStruct); err != nil {
logger.NfmLog.Errorf("getChfInfo err: %+v", err)
}
for i := 0; i < len(CHFStruct); i++ {
err := mapstructure.Decode(CHFStruct[i], &CHFProfile)
err = mapstructure.Decode(CHFStruct[i], &CHFProfile)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *nnrfService) getNFManagementClient(uri string) *Nnrf_NFManagement.APICl
}

func (s *nnrfService) SendNFStatusNotify(
Notification_event models.NotificationEventType,
notification_event models.NotificationEventType,
nfInstanceUri string,
url string,
nfProfile *models.NfProfile,
Expand All @@ -61,7 +61,7 @@ func (s *nnrfService) SendNFStatusNotify(
defer s.nfMngmntMu.RUnlock()

notifcationData := models.NotificationData{
Event: Notification_event,
Event: notification_event,
NfInstanceUri: nfInstanceUri,
}
if nfProfile != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/sbi/processor/access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (p *Processor) AccessTokenProcedure(request models.AccessTokenReq) (

func (p *Processor) AccessTokenScopeCheck(req models.AccessTokenReq) *models.AccessTokenErr {
// Check with nf profile
collName := "NfProfile"
collName := nrf_context.NfProfileCollName
reqGrantType := req.GrantType
reqNfType := strings.ToUpper(string(req.NfType))
reqTargetNfType := strings.ToUpper(string(req.TargetNfType))
Expand Down
Loading

0 comments on commit 5b28214

Please sign in to comment.