From 90a19cec5c0caccd399fa35347e3d41c7b1a5318 Mon Sep 17 00:00:00 2001 From: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:32:52 -0300 Subject: [PATCH] chore(code): remove unnecessary type conversions EE-7191 (#11908) --- api/apikey/cache_test.go | 2 +- api/chisel/service.go | 2 +- api/datastore/migrate_legacyversion.go | 2 +- api/datastore/migrator/migrate_dbversion31.go | 2 +- api/datastore/services.go | 2 +- api/http/csrf/csrf.go | 2 +- .../handler/customtemplates/customtemplate_create.go | 2 +- api/http/handler/edgegroups/edgegroup_list.go | 2 +- api/http/handler/edgejobs/edgejob_delete.go | 2 +- api/http/handler/edgejobs/edgejob_tasklogs_clear.go | 2 +- .../handler/edgejobs/edgejob_tasklogs_inspect.go | 2 +- api/http/handler/edgejobs/edgejob_tasks_list.go | 2 +- api/http/handler/edgejobs/edgejob_update.go | 4 ++-- api/http/handler/edgestacks/edgestack_delete.go | 2 +- .../handler/edgestacks/edgestack_status_delete.go | 2 +- .../edgestacks/edgestack_status_update_test.go | 2 +- api/http/handler/edgestacks/edgestack_update.go | 2 +- .../handler/endpointedge/endpointedge_job_logs.go | 2 +- .../handler/endpointgroups/endpointgroup_delete.go | 2 +- .../endpointgroups/endpointgroup_endpoint_add.go | 4 ++-- .../endpointgroups/endpointgroup_endpoint_delete.go | 4 ++-- .../handler/endpointgroups/endpointgroup_update.go | 2 +- api/http/handler/endpoints/endpoint_delete.go | 4 ++-- .../handler/endpoints/endpoint_registries_list.go | 2 +- .../handler/endpoints/endpoint_registry_access.go | 2 +- api/http/handler/endpoints/filter.go | 2 +- api/http/handler/helm/user_helm_repos.go | 4 ++-- api/http/handler/registries/registry_create.go | 2 +- api/http/handler/registries/registry_delete.go | 2 +- api/http/handler/stacks/handler.go | 2 +- api/http/handler/stacks/stack_delete.go | 2 +- api/http/handler/webhooks/webhook_execute.go | 2 +- api/http/handler/webhooks/webhook_list.go | 2 +- api/http/handler/websocket/hijack.go | 2 +- api/http/proxy/factory/docker/transport.go | 2 +- api/http/proxy/factory/kubernetes/token.go | 2 +- api/internal/edge/edgestacks/service.go | 2 +- api/internal/edge/edgestacks/status.go | 2 +- api/internal/endpointutils/endpointutils.go | 10 +++++----- api/kubernetes/cli/nodes_limits_test.go | 12 ++++++------ .../handlers/clean_nap_with_override_policies.go | 2 +- .../deployments/deployment_kubernetes_config.go | 2 +- 42 files changed, 56 insertions(+), 56 deletions(-) diff --git a/api/apikey/cache_test.go b/api/apikey/cache_test.go index d34f260a0..0821bec35 100644 --- a/api/apikey/cache_test.go +++ b/api/apikey/cache_test.go @@ -35,7 +35,7 @@ func Test_apiKeyCacheGet(t *testing.T) { } for _, test := range tests { - t.Run(string(test.digest), func(t *testing.T) { + t.Run(test.digest, func(t *testing.T) { _, _, found := keyCache.Get(test.digest) is.Equal(test.found, found) }) diff --git a/api/chisel/service.go b/api/chisel/service.go index 7aafdb0bd..5644f31ed 100644 --- a/api/chisel/service.go +++ b/api/chisel/service.go @@ -287,7 +287,7 @@ func (service *Service) checkTunnels() { Msg("unable to snapshot Edge environment") } - service.close(portainer.EndpointID(endpointID)) + service.close(endpointID) return } diff --git a/api/datastore/migrate_legacyversion.go b/api/datastore/migrate_legacyversion.go index 8d725ca72..e85b5d276 100644 --- a/api/datastore/migrate_legacyversion.go +++ b/api/datastore/migrate_legacyversion.go @@ -99,7 +99,7 @@ func (store *Store) getOrMigrateLegacyVersion() (*models.Version, error) { return &models.Version{ SchemaVersion: dbVersionToSemanticVersion(dbVersion), Edition: edition, - InstanceID: string(instanceId), + InstanceID: instanceId, }, nil } diff --git a/api/datastore/migrator/migrate_dbversion31.go b/api/datastore/migrator/migrate_dbversion31.go index 6a871435b..267a772fa 100644 --- a/api/datastore/migrator/migrate_dbversion31.go +++ b/api/datastore/migrator/migrate_dbversion31.go @@ -123,7 +123,7 @@ func (m *Migrator) updateDockerhubToDB32() error { migrated = true } else { // delete subsequent duplicates - m.registryService.Delete(portainer.RegistryID(r.ID)) + m.registryService.Delete(r.ID) } } } diff --git a/api/datastore/services.go b/api/datastore/services.go index 802989d3d..dfa590423 100644 --- a/api/datastore/services.go +++ b/api/datastore/services.go @@ -616,7 +616,7 @@ func (store *Store) Import(filename string) (err error) { if err != nil { return err } - err = json.Unmarshal([]byte(s), &backup) + err = json.Unmarshal(s, &backup) if err != nil { return err } diff --git a/api/http/csrf/csrf.go b/api/http/csrf/csrf.go index d7b0516b1..e2e641cef 100644 --- a/api/http/csrf/csrf.go +++ b/api/http/csrf/csrf.go @@ -22,7 +22,7 @@ func WithProtect(handler http.Handler) (http.Handler, error) { } handler = gorillacsrf.Protect( - []byte(token), + token, gorillacsrf.Path("/"), gorillacsrf.Secure(false), )(handler) diff --git a/api/http/handler/customtemplates/customtemplate_create.go b/api/http/handler/customtemplates/customtemplate_create.go index 68b205e5f..eed2d8b7e 100644 --- a/api/http/handler/customtemplates/customtemplate_create.go +++ b/api/http/handler/customtemplates/customtemplate_create.go @@ -482,7 +482,7 @@ func (handler *Handler) createCustomTemplateFromFileUpload(r *http.Request) (*po } templateFolder := strconv.Itoa(customTemplateID) - projectPath, err := handler.FileService.StoreCustomTemplateFileFromBytes(templateFolder, customTemplate.EntryPoint, []byte(payload.FileContent)) + projectPath, err := handler.FileService.StoreCustomTemplateFileFromBytes(templateFolder, customTemplate.EntryPoint, payload.FileContent) if err != nil { return nil, err } diff --git a/api/http/handler/edgegroups/edgegroup_list.go b/api/http/handler/edgegroups/edgegroup_list.go index 785fb551e..bc67176fd 100644 --- a/api/http/handler/edgegroups/edgegroup_list.go +++ b/api/http/handler/edgegroups/edgegroup_list.go @@ -69,7 +69,7 @@ func getEdgeGroupList(tx dataservices.DataStoreTx) ([]decoratedEdgeGroup, error) for _, orgEdgeGroup := range edgeGroups { usedByEdgeJob := false for _, edgeJob := range edgeJobs { - if slices.Contains(edgeJob.EdgeGroups, portainer.EdgeGroupID(orgEdgeGroup.ID)) { + if slices.Contains(edgeJob.EdgeGroups, orgEdgeGroup.ID) { usedByEdgeJob = true break } diff --git a/api/http/handler/edgejobs/edgejob_delete.go b/api/http/handler/edgejobs/edgejob_delete.go index f2211a9de..9472167f8 100644 --- a/api/http/handler/edgejobs/edgejob_delete.go +++ b/api/http/handler/edgejobs/edgejob_delete.go @@ -49,7 +49,7 @@ func (handler *Handler) edgeJobDelete(w http.ResponseWriter, r *http.Request) *h } func (handler *Handler) deleteEdgeJob(tx dataservices.DataStoreTx, edgeJobID portainer.EdgeJobID) error { - edgeJob, err := tx.EdgeJob().Read(portainer.EdgeJobID(edgeJobID)) + edgeJob, err := tx.EdgeJob().Read(edgeJobID) if tx.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an Edge job with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/edgejobs/edgejob_tasklogs_clear.go b/api/http/handler/edgejobs/edgejob_tasklogs_clear.go index 5393efa4d..6594834d9 100644 --- a/api/http/handler/edgejobs/edgejob_tasklogs_clear.go +++ b/api/http/handler/edgejobs/edgejob_tasklogs_clear.go @@ -75,7 +75,7 @@ func (handler *Handler) edgeJobTasksClear(w http.ResponseWriter, r *http.Request } func (handler *Handler) clearEdgeJobTaskLogs(tx dataservices.DataStoreTx, edgeJobID portainer.EdgeJobID, endpointID portainer.EndpointID, updateEdgeJob func(*portainer.EdgeJob, portainer.EndpointID, []portainer.EndpointID) error) error { - edgeJob, err := tx.EdgeJob().Read(portainer.EdgeJobID(edgeJobID)) + edgeJob, err := tx.EdgeJob().Read(edgeJobID) if tx.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an Edge job with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/edgejobs/edgejob_tasklogs_inspect.go b/api/http/handler/edgejobs/edgejob_tasklogs_inspect.go index 1a91fb994..92aad8c0c 100644 --- a/api/http/handler/edgejobs/edgejob_tasklogs_inspect.go +++ b/api/http/handler/edgejobs/edgejob_tasklogs_inspect.go @@ -43,5 +43,5 @@ func (handler *Handler) edgeJobTaskLogsInspect(w http.ResponseWriter, r *http.Re return httperror.InternalServerError("Unable to retrieve log file from disk", err) } - return response.JSON(w, &fileResponse{FileContent: string(logFileContent)}) + return response.JSON(w, &fileResponse{FileContent: logFileContent}) } diff --git a/api/http/handler/edgejobs/edgejob_tasks_list.go b/api/http/handler/edgejobs/edgejob_tasks_list.go index 91669ada5..70918f69d 100644 --- a/api/http/handler/edgejobs/edgejob_tasks_list.go +++ b/api/http/handler/edgejobs/edgejob_tasks_list.go @@ -47,7 +47,7 @@ func (handler *Handler) edgeJobTasksList(w http.ResponseWriter, r *http.Request) } func listEdgeJobTasks(tx dataservices.DataStoreTx, edgeJobID portainer.EdgeJobID) ([]taskContainer, error) { - edgeJob, err := tx.EdgeJob().Read(portainer.EdgeJobID(edgeJobID)) + edgeJob, err := tx.EdgeJob().Read(edgeJobID) if tx.IsErrObjectNotFound(err) { return nil, httperror.NotFound("Unable to find an Edge job with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/edgejobs/edgejob_update.go b/api/http/handler/edgejobs/edgejob_update.go index 3dba17d83..558c80f81 100644 --- a/api/http/handler/edgejobs/edgejob_update.go +++ b/api/http/handler/edgejobs/edgejob_update.go @@ -71,7 +71,7 @@ func (handler *Handler) edgeJobUpdate(w http.ResponseWriter, r *http.Request) *h } func (handler *Handler) updateEdgeJob(tx dataservices.DataStoreTx, edgeJobID portainer.EdgeJobID, payload edgeJobUpdatePayload) (*portainer.EdgeJob, error) { - edgeJob, err := tx.EdgeJob().Read(portainer.EdgeJobID(edgeJobID)) + edgeJob, err := tx.EdgeJob().Read(edgeJobID) if tx.IsErrObjectNotFound(err) { return nil, httperror.NotFound("Unable to find an Edge job with the specified identifier inside the database", err) } else if err != nil { @@ -137,7 +137,7 @@ func (handler *Handler) updateEdgeSchedule(tx dataservices.DataStoreTx, edgeJob } for _, endpointID := range endpoints { - endpointsToRemove[portainer.EndpointID(endpointID)] = true + endpointsToRemove[endpointID] = true } edgeJob.EdgeGroups = nil diff --git a/api/http/handler/edgestacks/edgestack_delete.go b/api/http/handler/edgestacks/edgestack_delete.go index 17d5f4e2d..91fb6927a 100644 --- a/api/http/handler/edgestacks/edgestack_delete.go +++ b/api/http/handler/edgestacks/edgestack_delete.go @@ -45,7 +45,7 @@ func (handler *Handler) edgeStackDelete(w http.ResponseWriter, r *http.Request) } func (handler *Handler) deleteEdgeStack(tx dataservices.DataStoreTx, edgeStackID portainer.EdgeStackID) error { - edgeStack, err := tx.EdgeStack().EdgeStack(portainer.EdgeStackID(edgeStackID)) + edgeStack, err := tx.EdgeStack().EdgeStack(edgeStackID) if handler.DataStore.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an edge stack with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/edgestacks/edgestack_status_delete.go b/api/http/handler/edgestacks/edgestack_status_delete.go index e06861a36..d63d5bb93 100644 --- a/api/http/handler/edgestacks/edgestack_status_delete.go +++ b/api/http/handler/edgestacks/edgestack_status_delete.go @@ -61,7 +61,7 @@ func (handler *Handler) edgeStackStatusDelete(w http.ResponseWriter, r *http.Req } func (handler *Handler) deleteEdgeStackStatus(tx dataservices.DataStoreTx, stackID portainer.EdgeStackID, endpoint *portainer.Endpoint) (*portainer.EdgeStack, error) { - stack, err := tx.EdgeStack().EdgeStack(portainer.EdgeStackID(stackID)) + stack, err := tx.EdgeStack().EdgeStack(stackID) if err != nil { return nil, handler.handlerDBErr(err, "Unable to find a stack with the specified identifier inside the database") } diff --git a/api/http/handler/edgestacks/edgestack_status_update_test.go b/api/http/handler/edgestacks/edgestack_status_update_test.go index 27a6c1d39..50a0863d4 100644 --- a/api/http/handler/edgestacks/edgestack_status_update_test.go +++ b/api/http/handler/edgestacks/edgestack_status_update_test.go @@ -81,7 +81,7 @@ func TestUpdateStatusAndInspect(t *testing.T) { t.Fatalf("expected EdgeStackStatusType %d, found %d", *payload.Status, lastStatus.Type) } - if endpointStatus.EndpointID != portainer.EndpointID(payload.EndpointID) { + if endpointStatus.EndpointID != payload.EndpointID { t.Fatalf("expected EndpointID %d, found %d", payload.EndpointID, endpointStatus.EndpointID) } diff --git a/api/http/handler/edgestacks/edgestack_update.go b/api/http/handler/edgestacks/edgestack_update.go index f36818b76..d9563bf16 100644 --- a/api/http/handler/edgestacks/edgestack_update.go +++ b/api/http/handler/edgestacks/edgestack_update.go @@ -80,7 +80,7 @@ func (handler *Handler) edgeStackUpdate(w http.ResponseWriter, r *http.Request) } func (handler *Handler) updateEdgeStack(tx dataservices.DataStoreTx, stackID portainer.EdgeStackID, payload updateEdgeStackPayload) (*portainer.EdgeStack, error) { - stack, err := tx.EdgeStack().EdgeStack(portainer.EdgeStackID(stackID)) + stack, err := tx.EdgeStack().EdgeStack(stackID) if err != nil { return nil, handler.handlerDBErr(err, "Unable to find a stack with the specified identifier inside the database") } diff --git a/api/http/handler/endpointedge/endpointedge_job_logs.go b/api/http/handler/endpointedge/endpointedge_job_logs.go index 90dba680a..971b5a996 100644 --- a/api/http/handler/endpointedge/endpointedge_job_logs.go +++ b/api/http/handler/endpointedge/endpointedge_job_logs.go @@ -78,7 +78,7 @@ func (handler *Handler) getEdgeJobLobs(tx dataservices.DataStoreTx, endpointID p return httperror.InternalServerError("Unable to find an environment with the specified identifier inside the database", err) } - edgeJob, err := tx.EdgeJob().Read(portainer.EdgeJobID(edgeJobID)) + edgeJob, err := tx.EdgeJob().Read(edgeJobID) if tx.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an edge job with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/endpointgroups/endpointgroup_delete.go b/api/http/handler/endpointgroups/endpointgroup_delete.go index f49c9d0dd..b71778446 100644 --- a/api/http/handler/endpointgroups/endpointgroup_delete.go +++ b/api/http/handler/endpointgroups/endpointgroup_delete.go @@ -68,7 +68,7 @@ func (handler *Handler) deleteEndpointGroup(tx dataservices.DataStoreTx, endpoin } for _, endpoint := range endpoints { - if endpoint.GroupID == portainer.EndpointGroupID(endpointGroupID) { + if endpoint.GroupID == endpointGroupID { endpoint.GroupID = portainer.EndpointGroupID(1) err = tx.Endpoint().UpdateEndpoint(endpoint.ID, &endpoint) if err != nil { diff --git a/api/http/handler/endpointgroups/endpointgroup_endpoint_add.go b/api/http/handler/endpointgroups/endpointgroup_endpoint_add.go index 439d4afff..f64787566 100644 --- a/api/http/handler/endpointgroups/endpointgroup_endpoint_add.go +++ b/api/http/handler/endpointgroups/endpointgroup_endpoint_add.go @@ -52,14 +52,14 @@ func (handler *Handler) endpointGroupAddEndpoint(w http.ResponseWriter, r *http. } func (handler *Handler) addEndpoint(tx dataservices.DataStoreTx, endpointGroupID portainer.EndpointGroupID, endpointID portainer.EndpointID) error { - endpointGroup, err := tx.EndpointGroup().Read(portainer.EndpointGroupID(endpointGroupID)) + endpointGroup, err := tx.EndpointGroup().Read(endpointGroupID) if tx.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an environment group with the specified identifier inside the database", err) } else if err != nil { return httperror.InternalServerError("Unable to find an environment group with the specified identifier inside the database", err) } - endpoint, err := tx.Endpoint().Endpoint(portainer.EndpointID(endpointID)) + endpoint, err := tx.Endpoint().Endpoint(endpointID) if tx.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an environment with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/endpointgroups/endpointgroup_endpoint_delete.go b/api/http/handler/endpointgroups/endpointgroup_endpoint_delete.go index d57592093..e5d4e69d4 100644 --- a/api/http/handler/endpointgroups/endpointgroup_endpoint_delete.go +++ b/api/http/handler/endpointgroups/endpointgroup_endpoint_delete.go @@ -51,14 +51,14 @@ func (handler *Handler) endpointGroupDeleteEndpoint(w http.ResponseWriter, r *ht } func (handler *Handler) removeEndpoint(tx dataservices.DataStoreTx, endpointGroupID portainer.EndpointGroupID, endpointID portainer.EndpointID) error { - _, err := tx.EndpointGroup().Read(portainer.EndpointGroupID(endpointGroupID)) + _, err := tx.EndpointGroup().Read(endpointGroupID) if tx.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an environment group with the specified identifier inside the database", err) } else if err != nil { return httperror.InternalServerError("Unable to find an environment group with the specified identifier inside the database", err) } - endpoint, err := tx.Endpoint().Endpoint(portainer.EndpointID(endpointID)) + endpoint, err := tx.Endpoint().Endpoint(endpointID) if tx.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an environment with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/endpointgroups/endpointgroup_update.go b/api/http/handler/endpointgroups/endpointgroup_update.go index ad125a1b4..446716fb5 100644 --- a/api/http/handler/endpointgroups/endpointgroup_update.go +++ b/api/http/handler/endpointgroups/endpointgroup_update.go @@ -76,7 +76,7 @@ func (handler *Handler) endpointGroupUpdate(w http.ResponseWriter, r *http.Reque } func (handler *Handler) updateEndpointGroup(tx dataservices.DataStoreTx, endpointGroupID portainer.EndpointGroupID, payload endpointGroupUpdatePayload) (*portainer.EndpointGroup, error) { - endpointGroup, err := tx.EndpointGroup().Read(portainer.EndpointGroupID(endpointGroupID)) + endpointGroup, err := tx.EndpointGroup().Read(endpointGroupID) if tx.IsErrObjectNotFound(err) { return nil, httperror.NotFound("Unable to find an environment group with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/endpoints/endpoint_delete.go b/api/http/handler/endpoints/endpoint_delete.go index c9e28303e..54ecd2c91 100644 --- a/api/http/handler/endpoints/endpoint_delete.go +++ b/api/http/handler/endpoints/endpoint_delete.go @@ -130,7 +130,7 @@ func (handler *Handler) endpointDeleteBatch(w http.ResponseWriter, r *http.Reque } func (handler *Handler) deleteEndpoint(tx dataservices.DataStoreTx, endpointID portainer.EndpointID, deleteCluster bool) error { - endpoint, err := tx.Endpoint().Endpoint(portainer.EndpointID(endpointID)) + endpoint, err := tx.Endpoint().Endpoint(endpointID) if tx.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an environment with the specified identifier inside the database", err) } else if err != nil { @@ -252,7 +252,7 @@ func (handler *Handler) deleteEndpoint(tx dataservices.DataStoreTx, endpointID p log.Warn().Err(err).Int("endpointId", int(endpoint.ID)).Msgf("Unable to delete pending actions") } - err = tx.Endpoint().DeleteEndpoint(portainer.EndpointID(endpointID)) + err = tx.Endpoint().DeleteEndpoint(endpointID) if err != nil { return httperror.InternalServerError("Unable to delete the environment from the database", err) } diff --git a/api/http/handler/endpoints/endpoint_registries_list.go b/api/http/handler/endpoints/endpoint_registries_list.go index 039693d17..aad91ecea 100644 --- a/api/http/handler/endpoints/endpoint_registries_list.go +++ b/api/http/handler/endpoints/endpoint_registries_list.go @@ -62,7 +62,7 @@ func (handler *Handler) listRegistries(tx dataservices.DataStoreTx, r *http.Requ return nil, httperror.InternalServerError("Unable to retrieve user from the database", err) } - endpoint, err := tx.Endpoint().Endpoint(portainer.EndpointID(endpointID)) + endpoint, err := tx.Endpoint().Endpoint(endpointID) if tx.IsErrObjectNotFound(err) { return nil, httperror.NotFound("Unable to find an environment with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/endpoints/endpoint_registry_access.go b/api/http/handler/endpoints/endpoint_registry_access.go index aaad283c6..23a24fb69 100644 --- a/api/http/handler/endpoints/endpoint_registry_access.go +++ b/api/http/handler/endpoints/endpoint_registry_access.go @@ -122,7 +122,7 @@ func (handler *Handler) updateRegistryAccess(tx dataservices.DataStoreTx, r *htt registryAccess.TeamAccessPolicies = payload.TeamAccessPolicies } - registry.RegistryAccesses[portainer.EndpointID(endpointID)] = registryAccess + registry.RegistryAccesses[endpointID] = registryAccess return tx.Registry().Update(registry.ID, registry) } diff --git a/api/http/handler/endpoints/filter.go b/api/http/handler/endpoints/filter.go index 6702ef2ae..950780fc1 100644 --- a/api/http/handler/endpoints/filter.go +++ b/api/http/handler/endpoints/filter.go @@ -432,7 +432,7 @@ func edgeGroupMatchSearchCriteria( func filterEndpointsByTypes(endpoints []portainer.Endpoint, endpointTypes []portainer.EndpointType) []portainer.Endpoint { typeSet := map[portainer.EndpointType]bool{} for _, endpointType := range endpointTypes { - typeSet[portainer.EndpointType(endpointType)] = true + typeSet[endpointType] = true } n := 0 diff --git a/api/http/handler/helm/user_helm_repos.go b/api/http/handler/helm/user_helm_repos.go index 886d44530..5197f88f9 100644 --- a/api/http/handler/helm/user_helm_repos.go +++ b/api/http/handler/helm/user_helm_repos.go @@ -49,7 +49,7 @@ func (handler *Handler) userCreateHelmRepo(w http.ResponseWriter, r *http.Reques if err != nil { return httperror.InternalServerError("Unable to retrieve user authentication token", err) } - userID := portainer.UserID(tokenData.ID) + userID := tokenData.ID p := new(addHelmRepoUrlPayload) err = request.DecodeAndValidateJSONPayload(r, p) @@ -106,7 +106,7 @@ func (handler *Handler) userGetHelmRepos(w http.ResponseWriter, r *http.Request) if err != nil { return httperror.InternalServerError("Unable to retrieve user authentication token", err) } - userID := portainer.UserID(tokenData.ID) + userID := tokenData.ID settings, err := handler.dataStore.Settings().Settings() if err != nil { diff --git a/api/http/handler/registries/registry_create.go b/api/http/handler/registries/registry_create.go index fd9c18ffb..1ca316b78 100644 --- a/api/http/handler/registries/registry_create.go +++ b/api/http/handler/registries/registry_create.go @@ -108,7 +108,7 @@ func (handler *Handler) registryCreate(w http.ResponseWriter, r *http.Request) * } registry := &portainer.Registry{ - Type: portainer.RegistryType(payload.Type), + Type: payload.Type, Name: payload.Name, URL: payload.URL, BaseURL: payload.BaseURL, diff --git a/api/http/handler/registries/registry_delete.go b/api/http/handler/registries/registry_delete.go index cb4f4ae1b..814169904 100644 --- a/api/http/handler/registries/registry_delete.go +++ b/api/http/handler/registries/registry_delete.go @@ -90,7 +90,7 @@ func (handler *Handler) deleteKubernetesSecrets(registry *portainer.Registry) er if len(failedNamespaces) > 0 { handler.PendingActionsService.Create( - handlers.NewDeleteK8sRegistrySecrets(portainer.EndpointID(endpointId), registry.ID, failedNamespaces), + handlers.NewDeleteK8sRegistrySecrets(endpointId, registry.ID, failedNamespaces), ) } } diff --git a/api/http/handler/stacks/handler.go b/api/http/handler/stacks/handler.go index ddfa55d27..7e5cce040 100644 --- a/api/http/handler/stacks/handler.go +++ b/api/http/handler/stacks/handler.go @@ -141,7 +141,7 @@ func (handler *Handler) userCanManageStacks(securityContext *security.Restricted } if endpointutils.IsDockerEndpoint(endpoint) && !endpoint.SecuritySettings.AllowStackManagementForRegularUsers { - canCreate, err := handler.userCanCreateStack(securityContext, portainer.EndpointID(endpoint.ID)) + canCreate, err := handler.userCanCreateStack(securityContext, endpoint.ID) if err != nil { return false, fmt.Errorf("failed to get user from the database: %w", err) diff --git a/api/http/handler/stacks/stack_delete.go b/api/http/handler/stacks/stack_delete.go index a70d46cdf..b28237ff5 100644 --- a/api/http/handler/stacks/stack_delete.go +++ b/api/http/handler/stacks/stack_delete.go @@ -234,7 +234,7 @@ func (handler *Handler) deleteStack(userID portainer.UserID, stack *portainer.St return errors.Wrap(err, "failed to convert docker compose file to a kube manifest") } - err = filesystem.WriteToFile(manifestFilePath, []byte(manifestContent)) + err = filesystem.WriteToFile(manifestFilePath, manifestContent) if err != nil { return errors.Wrap(err, "failed to create temp manifest file") } diff --git a/api/http/handler/webhooks/webhook_execute.go b/api/http/handler/webhooks/webhook_execute.go index baf22fc7e..18ecf6182 100644 --- a/api/http/handler/webhooks/webhook_execute.go +++ b/api/http/handler/webhooks/webhook_execute.go @@ -46,7 +46,7 @@ func (handler *Handler) webhookExecute(w http.ResponseWriter, r *http.Request) * registryID := webhook.RegistryID webhookType := webhook.WebhookType - endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID)) + endpoint, err := handler.DataStore.Endpoint().Endpoint(endpointID) if handler.DataStore.IsErrObjectNotFound(err) { return httperror.NotFound("Unable to find an environment with the specified identifier inside the database", err) } else if err != nil { diff --git a/api/http/handler/webhooks/webhook_list.go b/api/http/handler/webhooks/webhook_list.go index faf979b40..00269a251 100644 --- a/api/http/handler/webhooks/webhook_list.go +++ b/api/http/handler/webhooks/webhook_list.go @@ -59,7 +59,7 @@ func filterWebhooks(webhooks []portainer.Webhook, filters *webhookListOperationF filteredWebhooks := make([]portainer.Webhook, 0, len(webhooks)) for _, webhook := range webhooks { - if webhook.EndpointID == portainer.EndpointID(filters.EndpointID) && webhook.ResourceID == string(filters.ResourceID) { + if webhook.EndpointID == portainer.EndpointID(filters.EndpointID) && webhook.ResourceID == filters.ResourceID { filteredWebhooks = append(filteredWebhooks, webhook) } } diff --git a/api/http/handler/websocket/hijack.go b/api/http/handler/websocket/hijack.go index a41eb638a..b080c2095 100644 --- a/api/http/handler/websocket/hijack.go +++ b/api/http/handler/websocket/hijack.go @@ -123,7 +123,7 @@ func writeTCPToWebSocket(websocketConn *websocket.Conn, tcpConn net.Conn, errorC } processedOutput := validString(string(out[:n])) - input <- string(processedOutput) + input <- processedOutput } }() diff --git a/api/http/proxy/factory/docker/transport.go b/api/http/proxy/factory/docker/transport.go index 97e9ddb00..eb8ca09f8 100644 --- a/api/http/proxy/factory/docker/transport.go +++ b/api/http/proxy/factory/docker/transport.go @@ -775,7 +775,7 @@ func (transport *Transport) isAdminOrEndpointAdmin(request *http.Request) (bool, } func (transport *Transport) fetchEndpointSecuritySettings() (*portainer.EndpointSecuritySettings, error) { - endpoint, err := transport.dataStore.Endpoint().Endpoint(portainer.EndpointID(transport.endpoint.ID)) + endpoint, err := transport.dataStore.Endpoint().Endpoint(transport.endpoint.ID) if err != nil { return nil, err } diff --git a/api/http/proxy/factory/kubernetes/token.go b/api/http/proxy/factory/kubernetes/token.go index 24bf09885..e8c09c400 100644 --- a/api/http/proxy/factory/kubernetes/token.go +++ b/api/http/proxy/factory/kubernetes/token.go @@ -77,7 +77,7 @@ func (manager *tokenManager) UpdateUserServiceAccountsForEndpoint(endpointID por userIDs = append(userIDs, u) } for t := range endpoint.TeamAccessPolicies { - memberships, _ := manager.dataStore.TeamMembership().TeamMembershipsByTeamID(portainer.TeamID(t)) + memberships, _ := manager.dataStore.TeamMembership().TeamMembershipsByTeamID(t) for _, membership := range memberships { userIDs = append(userIDs, membership.UserID) } diff --git a/api/internal/edge/edgestacks/service.go b/api/internal/edge/edgestacks/service.go index 0f067f248..a9e8d1a6b 100644 --- a/api/internal/edge/edgestacks/service.go +++ b/api/internal/edge/edgestacks/service.go @@ -161,7 +161,7 @@ func (service *Service) DeleteEdgeStack(tx dataservices.DataStoreTx, edgeStackID } } - err = tx.EdgeStack().DeleteEdgeStack(portainer.EdgeStackID(edgeStackID)) + err = tx.EdgeStack().DeleteEdgeStack(edgeStackID) if err != nil { return errors.WithMessage(err, "Unable to remove the edge stack from the database") } diff --git a/api/internal/edge/edgestacks/status.go b/api/internal/edge/edgestacks/status.go index 4d909c610..da12df394 100644 --- a/api/internal/edge/edgestacks/status.go +++ b/api/internal/edge/edgestacks/status.go @@ -12,7 +12,7 @@ func NewStatus(oldStatus map[portainer.EndpointID]portainer.EdgeStackStatus, rel newEnvStatus := portainer.EdgeStackStatus{ Status: []portainer.EdgeStackDeploymentStatus{}, - EndpointID: portainer.EndpointID(environmentID), + EndpointID: environmentID, } oldEnvStatus, ok := oldStatus[environmentID] diff --git a/api/internal/endpointutils/endpointutils.go b/api/internal/endpointutils/endpointutils.go index c9a181b00..abd6c3b27 100644 --- a/api/internal/endpointutils/endpointutils.go +++ b/api/internal/endpointutils/endpointutils.go @@ -82,7 +82,7 @@ func InitialIngressClassDetection(endpoint *portainer.Endpoint, endpointService defer func() { endpoint.Kubernetes.Flags.IsServerIngressClassDetected = true endpointService.UpdateEndpoint( - portainer.EndpointID(endpoint.ID), + endpoint.ID, endpoint, ) }() @@ -107,7 +107,7 @@ func InitialIngressClassDetection(endpoint *portainer.Endpoint, endpointService endpoint.Kubernetes.Configuration.IngressClasses = updatedClasses err = endpointService.UpdateEndpoint( - portainer.EndpointID(endpoint.ID), + endpoint.ID, endpoint, ) if err != nil { @@ -123,7 +123,7 @@ func InitialMetricsDetection(endpoint *portainer.Endpoint, endpointService datas defer func() { endpoint.Kubernetes.Flags.IsServerMetricsDetected = true endpointService.UpdateEndpoint( - portainer.EndpointID(endpoint.ID), + endpoint.ID, endpoint, ) }() @@ -162,7 +162,7 @@ func storageDetect(endpoint *portainer.Endpoint, endpointService dataservices.En } endpoint.Kubernetes.Configuration.StorageClasses = storage err = endpointService.UpdateEndpoint( - portainer.EndpointID(endpoint.ID), + endpoint.ID, endpoint, ) if err != nil { @@ -179,7 +179,7 @@ func InitialStorageDetection(endpoint *portainer.Endpoint, endpointService datas defer func() { endpoint.Kubernetes.Flags.IsServerStorageDetected = true endpointService.UpdateEndpoint( - portainer.EndpointID(endpoint.ID), + endpoint.ID, endpoint, ) }() diff --git a/api/kubernetes/cli/nodes_limits_test.go b/api/kubernetes/cli/nodes_limits_test.go index b2840fe86..1dc689c96 100644 --- a/api/kubernetes/cli/nodes_limits_test.go +++ b/api/kubernetes/cli/nodes_limits_test.go @@ -22,8 +22,8 @@ func newNodes() *v1.NodeList { }, Status: v1.NodeStatus{ Allocatable: v1.ResourceList{ - v1.ResourceName(v1.ResourceCPU): resource.MustParse("2"), - v1.ResourceName(v1.ResourceMemory): resource.MustParse("4M"), + v1.ResourceCPU: resource.MustParse("2"), + v1.ResourceMemory: resource.MustParse("4M"), }, }, }, @@ -33,8 +33,8 @@ func newNodes() *v1.NodeList { }, Status: v1.NodeStatus{ Allocatable: v1.ResourceList{ - v1.ResourceName(v1.ResourceCPU): resource.MustParse("3"), - v1.ResourceName(v1.ResourceMemory): resource.MustParse("6M"), + v1.ResourceCPU: resource.MustParse("3"), + v1.ResourceMemory: resource.MustParse("6M"), }, }, }, @@ -57,8 +57,8 @@ func newPods() *v1.PodList { Name: "test-container-0", Resources: v1.ResourceRequirements{ Requests: v1.ResourceList{ - v1.ResourceName(v1.ResourceCPU): resource.MustParse("1"), - v1.ResourceName(v1.ResourceMemory): resource.MustParse("2M"), + v1.ResourceCPU: resource.MustParse("1"), + v1.ResourceMemory: resource.MustParse("2M"), }, }, }, diff --git a/api/pendingactions/handlers/clean_nap_with_override_policies.go b/api/pendingactions/handlers/clean_nap_with_override_policies.go index 667f9fe43..eac1b1624 100644 --- a/api/pendingactions/handlers/clean_nap_with_override_policies.go +++ b/api/pendingactions/handlers/clean_nap_with_override_policies.go @@ -66,7 +66,7 @@ func (h *HandlerCleanNAPWithOverridePolicies) Execute(pendingAction portainer.Pe return nil } - endpointGroup, err := h.dataStore.EndpointGroup().Read(portainer.EndpointGroupID(payload.EndpointGroupID)) + endpointGroup, err := h.dataStore.EndpointGroup().Read(payload.EndpointGroupID) if err != nil { log.Error().Err(err).Msgf("Error reading environment group to clean NAP with override policies for environment %d and environment group %d", endpoint.ID, endpointGroup.ID) return fmt.Errorf("failed to retrieve environment group %d: %w", payload.EndpointGroupID, err) diff --git a/api/stacks/deployments/deployment_kubernetes_config.go b/api/stacks/deployments/deployment_kubernetes_config.go index 252870451..ab96bdee7 100644 --- a/api/stacks/deployments/deployment_kubernetes_config.go +++ b/api/stacks/deployments/deployment_kubernetes_config.go @@ -66,7 +66,7 @@ func (config *KubernetesStackDeploymentConfig) Deploy() error { return errors.Wrap(err, "failed to add application labels") } - err = filesystem.WriteToFile(manifestFilePath, []byte(manifestContent)) + err = filesystem.WriteToFile(manifestFilePath, manifestContent) if err != nil { return errors.Wrap(err, "failed to create temp manifest file") }