Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update dependencies, fix linting #581

Merged
merged 7 commits into from
Jan 2, 2024
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ifndef HAS_SWAGGER
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
endif
ifndef HAS_GOLANGCI_LINT
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
endif
ifndef HAS_MOCKGEN
go install github.com/golang/mock/mockgen@v1.6.0
Expand Down
73 changes: 36 additions & 37 deletions api/alerting/alerting_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

alertingModels "github.com/equinor/radix-api/api/alerting/models"
"github.com/equinor/radix-api/models"
radixhttp "github.com/equinor/radix-common/net/http"
crdutils "github.com/equinor/radix-operator/pkg/apis/utils"
"github.com/gorilla/mux"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -30,42 +29,42 @@ func (ec *alertingController) GetRoutes() models.Routes {
models.Route{
Path: envPath + "/alerting",
Method: "PUT",
HandlerFunc: EnvironmentRouteAccessCheck(UpdateEnvironmentAlertingConfig),
HandlerFunc: ec.EnvironmentRouteAccessCheck(ec.UpdateEnvironmentAlertingConfig),
},
models.Route{
Path: envPath + "/alerting",
Method: http.MethodGet,
HandlerFunc: EnvironmentRouteAccessCheck(GetEnvironmentAlertingConfig),
HandlerFunc: ec.EnvironmentRouteAccessCheck(ec.GetEnvironmentAlertingConfig),
},
models.Route{
Path: envPath + "/alerting/enable",
Method: http.MethodPost,
HandlerFunc: EnvironmentRouteAccessCheck(EnableEnvironmentAlerting),
HandlerFunc: ec.EnvironmentRouteAccessCheck(ec.EnableEnvironmentAlerting),
},
models.Route{
Path: envPath + "/alerting/disable",
Method: http.MethodPost,
HandlerFunc: EnvironmentRouteAccessCheck(DisableEnvironmentAlerting),
HandlerFunc: ec.EnvironmentRouteAccessCheck(ec.DisableEnvironmentAlerting),
},
models.Route{
Path: appPath + "/alerting",
Method: "PUT",
HandlerFunc: UpdateApplicationAlertingConfig,
HandlerFunc: ec.UpdateApplicationAlertingConfig,
},
models.Route{
Path: appPath + "/alerting",
Method: http.MethodGet,
HandlerFunc: GetApplicationAlertingConfig,
HandlerFunc: ec.GetApplicationAlertingConfig,
},
models.Route{
Path: appPath + "/alerting/enable",
Method: http.MethodPost,
HandlerFunc: EnableApplicationAlerting,
HandlerFunc: ec.EnableApplicationAlerting,
},
models.Route{
Path: appPath + "/alerting/disable",
Method: http.MethodPost,
HandlerFunc: DisableApplicationAlerting,
HandlerFunc: ec.DisableApplicationAlerting,
},
}

Expand All @@ -74,14 +73,14 @@ func (ec *alertingController) GetRoutes() models.Routes {

// EnvironmentRouteAccessCheck gets appName and envName from route and verifies that environment exists
// Returns 404 NotFound if environment is not defined, otherwise calls handler
func EnvironmentRouteAccessCheck(handler models.RadixHandlerFunc) models.RadixHandlerFunc {
func (ec *alertingController) EnvironmentRouteAccessCheck(handler models.RadixHandlerFunc) models.RadixHandlerFunc {
return func(a models.Accounts, rw http.ResponseWriter, r *http.Request) {
appName := mux.Vars(r)["appName"]
envName := mux.Vars(r)["envName"]
envNamespace := crdutils.GetEnvironmentNamespace(appName, envName)

if _, err := a.ServiceAccount.RadixClient.RadixV1().RadixEnvironments().Get(r.Context(), envNamespace, v1.GetOptions{}); err != nil {
radixhttp.ErrorResponse(rw, r, err)
ec.ErrorResponse(rw, r, err)
return
}

Expand All @@ -90,7 +89,7 @@ func EnvironmentRouteAccessCheck(handler models.RadixHandlerFunc) models.RadixHa
}

// UpdateEnvironmentAlertingConfig Configures alert settings
func UpdateEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
func (ec *alertingController) UpdateEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation PUT /applications/{appName}/environments/{envName}/alerting environment updateEnvironmentAlertingConfig
// ---
// summary: Update alerts configuration for an environment
Expand Down Expand Up @@ -142,23 +141,23 @@ func UpdateEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWr

var updateAlertingConfig alertingModels.UpdateAlertingConfig
if err := json.NewDecoder(r.Body).Decode(&updateAlertingConfig); err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

alertHandler := NewEnvironmentHandler(accounts, appName, envName)
alertsConfig, err := alertHandler.UpdateAlertingConfig(r.Context(), updateAlertingConfig)

if err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
ec.JSONResponse(w, r, alertsConfig)
}

// GetEnvironmentAlertingConfig returns alerts configuration
func GetEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
func (ec *alertingController) GetEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /applications/{appName}/environments/{envName}/alerting environment getEnvironmentAlertingConfig
// ---
// summary: Get alerts configuration for an environment
Expand Down Expand Up @@ -203,15 +202,15 @@ func GetEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWrite
alertsConfig, err := alertHandler.GetAlertingConfig(r.Context())

if err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
ec.JSONResponse(w, r, alertsConfig)
}

// EnableEnvironmentAlerting enables alerting for application environment
func EnableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
func (ec *alertingController) EnableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /applications/{appName}/environments/{envName}/alerting/enable environment enableEnvironmentAlerting
// ---
// summary: Enable alerting for an environment
Expand Down Expand Up @@ -258,15 +257,15 @@ func EnableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter,
alertsConfig, err := alertHandler.EnableAlerting(r.Context())

if err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
ec.JSONResponse(w, r, alertsConfig)
}

// DisableEnvironmentAlerting disables alerting for application environment
func DisableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
func (ec *alertingController) DisableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /applications/{appName}/environments/{envName}/alerting/disable environment disableEnvironmentAlerting
// ---
// summary: Disable alerting for an environment
Expand Down Expand Up @@ -312,15 +311,15 @@ func DisableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter,
alertHandler := NewEnvironmentHandler(accounts, appName, envName)
alertsConfig, err := alertHandler.DisableAlerting(r.Context())
if err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
ec.JSONResponse(w, r, alertsConfig)
}

// UpdateApplicationAlertingConfig Configures alert settings
func UpdateApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
func(ec *alertingController) UpdateApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation PUT /applications/{appName}/alerting application updateApplicationAlertingConfig
// ---
// summary: Update alerts configuration for application namespace
Expand Down Expand Up @@ -366,23 +365,23 @@ func UpdateApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWr

var updateAlertingConfig alertingModels.UpdateAlertingConfig
if err := json.NewDecoder(r.Body).Decode(&updateAlertingConfig); err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

alertHandler := NewApplicationHandler(accounts, appName)
alertsConfig, err := alertHandler.UpdateAlertingConfig(r.Context(), updateAlertingConfig)

if err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
ec.JSONResponse(w, r, alertsConfig)
}

// GetApplicationAlertingConfig returns alerts configuration
func GetApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
func(ec *alertingController) GetApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation GET /applications/{appName}/alerting application getApplicationAlertingConfig
// ---
// summary: Get alerts configuration for application namespace
Expand Down Expand Up @@ -421,15 +420,15 @@ func GetApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWrite
alertsConfig, err := alertHandler.GetAlertingConfig(r.Context())

if err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
ec.JSONResponse(w, r, alertsConfig)
}

// EnableApplicationAlerting enables alerting for application
func EnableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
func(ec *alertingController) EnableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /applications/{appName}/alerting/enable application enableApplicationAlerting
// ---
// summary: Enable alerting for application namespace
Expand Down Expand Up @@ -470,15 +469,15 @@ func EnableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter,
alertsConfig, err := alertHandler.EnableAlerting(r.Context())

if err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
ec.JSONResponse(w, r, alertsConfig)
}

// DisableApplicationAlerting disables alerting for application
func DisableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
func(ec *alertingController) DisableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
// swagger:operation POST /applications/{appName}/alerting/disable application disableApplicationAlerting
// ---
// summary: Disable alerting for application namespace
Expand Down Expand Up @@ -518,9 +517,9 @@ func DisableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter,
alertHandler := NewApplicationHandler(accounts, appName)
alertsConfig, err := alertHandler.DisableAlerting(r.Context())
if err != nil {
radixhttp.ErrorResponse(w, r, err)
ec.ErrorResponse(w, r, err)
return
}

radixhttp.JSONResponse(w, r, alertsConfig)
ec.JSONResponse(w, r, alertsConfig)
}
Loading