From c99f5c5f624a612d8be18849af81a4e51c503bf0 Mon Sep 17 00:00:00 2001 From: Patricia Reinoso Date: Wed, 10 Jan 2024 14:34:43 +0100 Subject: [PATCH 1/5] Enable go vet checks in CI Signed-off-by: Patricia Reinoso --- .golangci.yml | 9 +++------ producer/nssaiavailability_store.go | 10 +++++----- producer/nssaiavailability_subscription.go | 4 ++-- producer/subscription_id_document.go | 9 +-------- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 27a210d..5de5f78 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -169,13 +169,10 @@ linters-settings: - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - # enable or disable analyzers by name - enable: - - atomicalign - enable-all: false + # enable all analyzers + enable-all: true disable: - - shadow - disable-all: false + - fieldalignment depguard: list-type: blacklist include-go-root: false diff --git a/producer/nssaiavailability_store.go b/producer/nssaiavailability_store.go index 6c250ad..0431fb6 100644 --- a/producer/nssaiavailability_store.go +++ b/producer/nssaiavailability_store.go @@ -39,7 +39,7 @@ func NSSAIAvailabilityDeleteProcedure(nfId string) *models.ProblemDetails { } } - *problemDetails = models.ProblemDetails{ + problemDetails = &models.ProblemDetails{ Title: util.UNSUPPORTED_RESOURCE, Status: http.StatusNotFound, Detail: fmt.Sprintf("AMF ID '%s' does not exist", nfId), @@ -87,7 +87,7 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc } factory.ConfigLock.RUnlock() if !hitAmf { - *problemDetails = models.ProblemDetails{ + problemDetails = &models.ProblemDetails{ Title: util.UNSUPPORTED_RESOURCE, Status: http.StatusNotFound, Detail: fmt.Sprintf("AMF ID '%s' does not exist", nfId), @@ -114,7 +114,7 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc patch, err := jsonpatch.DecodePatch(patchJSON) if err != nil { - *problemDetails = models.ProblemDetails{ + problemDetails = &models.ProblemDetails{ Title: util.MALFORMED_REQUEST, Status: http.StatusBadRequest, Detail: err.Error(), @@ -124,7 +124,7 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc modified, err := patch.Apply(original) if err != nil { - *problemDetails = models.ProblemDetails{ + problemDetails = &models.ProblemDetails{ Title: util.INVALID_REQUEST, Status: http.StatusConflict, Detail: err.Error(), @@ -136,7 +136,7 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc err = json.Unmarshal(modified, &factory.NssfConfig.Configuration.AmfList[amfIdx].SupportedNssaiAvailabilityData) factory.ConfigLock.Unlock() if err != nil { - *problemDetails = models.ProblemDetails{ + problemDetails = &models.ProblemDetails{ Title: util.INVALID_REQUEST, Status: http.StatusBadRequest, Detail: err.Error(), diff --git a/producer/nssaiavailability_subscription.go b/producer/nssaiavailability_subscription.go index d7443ed..d716839 100644 --- a/producer/nssaiavailability_subscription.go +++ b/producer/nssaiavailability_subscription.go @@ -60,7 +60,7 @@ func NSSAIAvailabilityPostProcedure(createData models.NssfEventSubscriptionCreat if err != nil { logger.Nssaiavailability.Warnf(err.Error()) - *problemDetails = models.ProblemDetails{ + problemDetails = &models.ProblemDetails{ Title: util.UNSUPPORTED_RESOURCE, Status: http.StatusNotFound, Detail: err.Error(), @@ -99,7 +99,7 @@ func NSSAIAvailabilityUnsubscribeProcedure(subscriptionId string) *models.Proble } // No specific subscription ID exists - *problemDetails = models.ProblemDetails{ + problemDetails = &models.ProblemDetails{ Title: util.UNSUPPORTED_RESOURCE, Status: http.StatusNotFound, Detail: fmt.Sprintf("Subscription ID '%s' is not available", subscriptionId), diff --git a/producer/subscription_id_document.go b/producer/subscription_id_document.go index 3b0e070..12f8b93 100644 --- a/producer/subscription_id_document.go +++ b/producer/subscription_id_document.go @@ -19,7 +19,6 @@ import ( "github.com/omec-project/http_wrapper" "github.com/omec-project/nssf/logger" - "github.com/omec-project/openapi/models" ) // HandleNSSAIAvailabilityUnsubscribe - Deletes an already existing NSSAI availability notification subscription @@ -32,12 +31,6 @@ func HandleNSSAIAvailabilityUnsubscribe(request *http_wrapper.Request) *http_wra if problemDetails == nil { return http_wrapper.NewResponse(http.StatusNoContent, nil, nil) - } else if problemDetails != nil { - return http_wrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) } - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: "UNSPECIFIED", - } - return http_wrapper.NewResponse(http.StatusForbidden, nil, problemDetails) + return http_wrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) } From 38f6135375a99fb4bc60872b5861f248467a85e9 Mon Sep 17 00:00:00 2001 From: Patricia Reinoso Date: Fri, 12 Jan 2024 13:43:58 +0100 Subject: [PATCH 2/5] Enable fieldalignment go vet check Signed-off-by: Patricia Reinoso --- .golangci.yml | 2 -- context/context.go | 2 +- factory/config.go | 4 ++-- test/param.go | 6 ++---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5de5f78..1393938 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -171,8 +171,6 @@ linters-settings: - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf # enable all analyzers enable-all: true - disable: - - fieldalignment depguard: list-type: blacklist include-go-root: false diff --git a/context/context.go b/context/context.go index 1d6915a..b3f41c7 100644 --- a/context/context.go +++ b/context/context.go @@ -55,10 +55,10 @@ type NSSFContext struct { RegisterIPv4 string // HttpIpv6Address string BindingIPv4 string - SBIPort int NfService map[models.ServiceName]models.NfService NrfUri string SupportedPlmnList []models.PlmnId + SBIPort int } // Initialize NSSF context with configuration factory diff --git a/factory/config.go b/factory/config.go index edc997d..b9432d0 100644 --- a/factory/config.go +++ b/factory/config.go @@ -26,8 +26,8 @@ const ( type Config struct { Info *Info `yaml:"info"` Configuration *Configuration `yaml:"configuration"` - Subscriptions []Subscription `yaml:"subscriptions,omitempty"` Logger *logger_util.Logger `yaml:"logger"` + Subscriptions []Subscription `yaml:"subscriptions,omitempty"` } type Info struct { @@ -100,8 +100,8 @@ type MappingFromPlmnConfig struct { } type Subscription struct { - SubscriptionId string `yaml:"subscriptionId"` SubscriptionData *models.NssfEventSubscriptionCreateData `yaml:"subscriptionData"` + SubscriptionId string `yaml:"subscriptionId"` } var ConfigPodTrigger chan bool diff --git a/test/param.go b/test/param.go index b6eee8d..7c44c3e 100644 --- a/test/param.go +++ b/test/param.go @@ -26,11 +26,9 @@ type TestingUtil struct { } type TestingNsselection struct { - ConfigFile string - GenerateNonRoamingQueryParameter func() NsselectionQueryParameter - - GenerateRoamingQueryParameter func() NsselectionQueryParameter + GenerateRoamingQueryParameter func() NsselectionQueryParameter + ConfigFile string } type TestingNssaiavailability struct { From e0bcae53b6436da91f5dd3dc29e0b3417e3b1787 Mon Sep 17 00:00:00 2001 From: Patricia Reinoso Date: Mon, 15 Jan 2024 18:22:08 +0100 Subject: [PATCH 3/5] Fix nilness go vet check Signed-off-by: Patricia Reinoso --- producer/subscription_id_document.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/producer/subscription_id_document.go b/producer/subscription_id_document.go index 12f8b93..0dc6885 100644 --- a/producer/subscription_id_document.go +++ b/producer/subscription_id_document.go @@ -19,6 +19,8 @@ import ( "github.com/omec-project/http_wrapper" "github.com/omec-project/nssf/logger" + "github.com/omec-project/openapi/models" + "reflect" ) // HandleNSSAIAvailabilityUnsubscribe - Deletes an already existing NSSAI availability notification subscription @@ -31,6 +33,12 @@ func HandleNSSAIAvailabilityUnsubscribe(request *http_wrapper.Request) *http_wra if problemDetails == nil { return http_wrapper.NewResponse(http.StatusNoContent, nil, nil) + } else if reflect.DeepEqual(*problemDetails, models.ProblemDetails{}) { + problemDetails = &models.ProblemDetails{ + Status: http.StatusForbidden, + Cause: "UNSPECIFIED", + } + return http_wrapper.NewResponse(http.StatusForbidden, nil, problemDetails) } return http_wrapper.NewResponse(int(problemDetails.Status), nil, problemDetails) } From 8b25b32ae1063fc945b263d40eafceb6eb0a0e04 Mon Sep 17 00:00:00 2001 From: Patricia Reinoso Date: Mon, 15 Jan 2024 18:30:53 +0100 Subject: [PATCH 4/5] Update context/context.go Co-authored-by: gab-arrobo --- context/context.go | 1 - 1 file changed, 1 deletion(-) diff --git a/context/context.go b/context/context.go index b3f41c7..6876639 100644 --- a/context/context.go +++ b/context/context.go @@ -53,7 +53,6 @@ type NSSFContext struct { Name string UriScheme models.UriScheme RegisterIPv4 string - // HttpIpv6Address string BindingIPv4 string NfService map[models.ServiceName]models.NfService NrfUri string From d083f759f4304d144581a85606eca739dbe894c9 Mon Sep 17 00:00:00 2001 From: "Arrobo, Gabriel" Date: Mon, 15 Jan 2024 11:50:15 -0800 Subject: [PATCH 5/5] apply gofmt to context.go file --- context/context.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/context/context.go b/context/context.go index 6876639..5858adf 100644 --- a/context/context.go +++ b/context/context.go @@ -49,10 +49,10 @@ func init() { } type NSSFContext struct { - NfId string - Name string - UriScheme models.UriScheme - RegisterIPv4 string + NfId string + Name string + UriScheme models.UriScheme + RegisterIPv4 string BindingIPv4 string NfService map[models.ServiceName]models.NfService NrfUri string