diff --git a/api/.golangci.yaml b/api/.golangci.yaml index ea3923749..76fb543b2 100644 --- a/api/.golangci.yaml +++ b/api/.golangci.yaml @@ -4,6 +4,7 @@ linters: # Enable these for now enable: + - unused - depguard - gosimple - govet diff --git a/api/datastore/helpers_test.go b/api/datastore/helpers_test.go index c35d76b6d..1419d3133 100644 --- a/api/datastore/helpers_test.go +++ b/api/datastore/helpers_test.go @@ -56,13 +56,3 @@ func testVersion(store *Store, versionWant string, t *testing.T) { t.Errorf("Expect store version to be %s but was %s", versionWant, v.SchemaVersion) } } - -func testEdition(store *Store, editionWant portainer.SoftwareEdition, t *testing.T) { - v, err := store.VersionService.Version() - if err != nil { - log.Fatal().Err(err).Msg("") - } - if portainer.SoftwareEdition(v.Edition) != editionWant { - t.Errorf("Expect store edition to be %s but was %s", editionWant.GetEditionLabel(), portainer.SoftwareEdition(v.Edition).GetEditionLabel()) - } -} diff --git a/api/http/handler/edgestacks/edgestack_update.go b/api/http/handler/edgestacks/edgestack_update.go index 6b3efc9d9..f36818b76 100644 --- a/api/http/handler/edgestacks/edgestack_update.go +++ b/api/http/handler/edgestacks/edgestack_update.go @@ -2,7 +2,6 @@ package edgestacks import ( "net/http" - "time" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/dataservices" @@ -190,26 +189,3 @@ func (handler *Handler) handleChangeEdgeGroups(tx dataservices.DataStoreTx, edge return newRelatedEnvironmentIDs, endpointsToAdd, nil } - -func newStatus(oldStatus map[portainer.EndpointID]portainer.EdgeStackStatus, relatedEnvironmentIds []portainer.EndpointID) map[portainer.EndpointID]portainer.EdgeStackStatus { - newStatus := make(map[portainer.EndpointID]portainer.EdgeStackStatus) - for _, endpointID := range relatedEnvironmentIds { - newEnvStatus := portainer.EdgeStackStatus{} - - oldEnvStatus, ok := oldStatus[endpointID] - if ok { - newEnvStatus = oldEnvStatus - } - - newEnvStatus.Status = []portainer.EdgeStackDeploymentStatus{ - { - Time: time.Now().Unix(), - Type: portainer.EdgeStackStatusPending, - }, - } - - newStatus[endpointID] = newEnvStatus - } - - return newStatus -} diff --git a/api/http/handler/edgestacks/handler.go b/api/http/handler/edgestacks/handler.go index b084726f3..ad9bff3b8 100644 --- a/api/http/handler/edgestacks/handler.go +++ b/api/http/handler/edgestacks/handler.go @@ -1,12 +1,10 @@ package edgestacks import ( - "fmt" "net/http" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/dataservices" - "github.com/portainer/portainer/api/filesystem" "github.com/portainer/portainer/api/http/middlewares" "github.com/portainer/portainer/api/http/security" edgestackservice "github.com/portainer/portainer/api/internal/edge/edgestacks" @@ -26,8 +24,6 @@ type Handler struct { KubernetesDeployer portainer.KubernetesDeployer } -const contextKey = "edgeStack_item" - // NewHandler creates a handler to manage environment(endpoint) group operations. func NewHandler(bouncer security.BouncerService, dataStore dataservices.DataStore, edgeStacksService *edgestackservice.Service) *Handler { h := &Handler{ @@ -62,35 +58,6 @@ func NewHandler(bouncer security.BouncerService, dataStore dataservices.DataStor return h } -func (handler *Handler) convertAndStoreKubeManifestIfNeeded(stackFolder string, projectPath, composePath string, relatedEndpointIds []portainer.EndpointID) (manifestPath string, err error) { - hasKubeEndpoint, err := hasKubeEndpoint(handler.DataStore.Endpoint(), relatedEndpointIds) - if err != nil { - return "", fmt.Errorf("unable to check if edge stack has kube environments: %w", err) - } - - if !hasKubeEndpoint { - return "", nil - } - - composeConfig, err := handler.FileService.GetFileContent(projectPath, composePath) - if err != nil { - return "", fmt.Errorf("unable to retrieve Compose file from disk: %w", err) - } - - kompose, err := handler.KubernetesDeployer.ConvertCompose(composeConfig) - if err != nil { - return "", fmt.Errorf("failed converting compose file to kubernetes manifest: %w", err) - } - - komposeFileName := filesystem.ManifestFileDefaultName - _, err = handler.FileService.StoreEdgeStackFileFromBytes(stackFolder, komposeFileName, kompose) - if err != nil { - return "", fmt.Errorf("failed to store kube manifest file: %w", err) - } - - return komposeFileName, nil -} - func (handler *Handler) handlerDBErr(err error, msg string) *httperror.HandlerError { httpErr := httperror.InternalServerError(msg, err) diff --git a/api/http/handler/endpoints/endpoint_agent_browse_docs.go b/api/http/handler/endpoints/endpoint_agent_browse_docs.go index c8d642644..cb22f718b 100644 --- a/api/http/handler/endpoints/endpoint_agent_browse_docs.go +++ b/api/http/handler/endpoints/endpoint_agent_browse_docs.go @@ -19,6 +19,8 @@ package endpoints // @failure 400 "Invalid request" // @failure 500 "Server error" // @router /endpoints/{id}/docker/v2/browse/put [post] +// +//lint:ignore U1000 Ignore unused code, for documentation purposes func _fileBrowseFileUploadV2() { // dummy function to make swag pick up the above docs for the following REST call // POST request on /browse/put?volumeID=:id diff --git a/api/http/handler/users/handler.go b/api/http/handler/users/handler.go index 41e1b0f24..269c7cfbc 100644 --- a/api/http/handler/users/handler.go +++ b/api/http/handler/users/handler.go @@ -20,7 +20,6 @@ var ( errAdminCannotRemoveSelf = errors.New("Cannot remove your own user account. Contact another administrator") errCannotRemoveLastLocalAdmin = errors.New("Cannot remove the last local administrator account") errCryptoHashFailure = errors.New("Unable to hash data") - errWrongPassword = errors.New("Wrong password") ) func hideFields(user *portainer.User) { diff --git a/api/kubernetes/cli/client.go b/api/kubernetes/cli/client.go index cf6993097..9ce5366c7 100644 --- a/api/kubernetes/cli/client.go +++ b/api/kubernetes/cli/client.go @@ -257,32 +257,6 @@ func (factory *ClientFactory) buildEdgeConfig(endpoint *portainer.Endpoint) (*re return config, nil } -func (factory *ClientFactory) createRemoteClient(endpointURL string) (*kubernetes.Clientset, error) { - signature, err := factory.signatureService.CreateSignature(portainer.PortainerAgentSignatureMessage) - if err != nil { - return nil, err - } - - config, err := clientcmd.BuildConfigFromFlags(endpointURL, "") - if err != nil { - return nil, err - } - - config.Insecure = true - config.QPS = DefaultKubeClientQPS - config.Burst = DefaultKubeClientBurst - - config.Wrap(func(rt http.RoundTripper) http.RoundTripper { - return &agentHeaderRoundTripper{ - signatureHeader: signature, - publicKeyHeader: factory.signatureService.EncodedPublicKey(), - roundTripper: rt, - } - }) - - return kubernetes.NewForConfig(config) -} - func (factory *ClientFactory) CreateRemoteMetricsClient(endpoint *portainer.Endpoint) (*metricsv.Clientset, error) { config, err := factory.CreateConfig(endpoint) if err != nil {