diff --git a/api/cmd/portainer/main.go b/api/cmd/portainer/main.go index 265ead4f0..094ef4fda 100644 --- a/api/cmd/portainer/main.go +++ b/api/cmd/portainer/main.go @@ -52,7 +52,6 @@ import ( "github.com/portainer/portainer/pkg/featureflags" "github.com/portainer/portainer/pkg/fips" "github.com/portainer/portainer/pkg/libhelm" - libhelmtypes "github.com/portainer/portainer/pkg/libhelm/types" "github.com/portainer/portainer/pkg/libstack/compose" "github.com/portainer/portainer/pkg/validate" @@ -175,10 +174,6 @@ func initKubernetesDeployer(kubernetesTokenCacheManager *kubeproxy.TokenCacheMan return exec.NewKubernetesDeployer(kubernetesTokenCacheManager, kubernetesClientFactory, dataStore, reverseTunnelService, signatureService, proxyManager) } -func initHelmPackageManager() (libhelmtypes.HelmPackageManager, error) { - return libhelm.NewHelmPackageManager() -} - func initAPIKeyService(datastore dataservices.DataStore) apikey.APIKeyService { return apikey.NewAPIKeyService(datastore.APIKeyRepository(), datastore.User()) } @@ -469,10 +464,7 @@ func buildServer(flags *portainer.CLIFlags, shutdownCtx context.Context, shutdow proxyManager.NewProxyFactory(dataStore, signatureService, reverseTunnelService, dockerClientFactory, kubernetesClientFactory, kubernetesTokenCacheManager, gitService, snapshotService, jwtService) - helmPackageManager, err := initHelmPackageManager() - if err != nil { - log.Fatal().Err(err).Msg("failed initializing helm package manager") - } + helmPackageManager := libhelm.NewHelmPackageManager() applicationStatus := initStatus(instanceID) @@ -538,10 +530,7 @@ func buildServer(flags *portainer.CLIFlags, shutdownCtx context.Context, shutdow log.Fatal().Msg("failed to fetch SSL settings from DB") } - platformService, err := platform.NewService(dataStore) - if err != nil { - log.Fatal().Err(err).Msg("failed initializing platform service") - } + platformService := platform.NewService(dataStore) upgradeService, err := upgrade.NewService( *flags.Assets, diff --git a/api/git/credentials.go b/api/git/credentials.go index d8ed1afc0..3a1fd5c33 100644 --- a/api/git/credentials.go +++ b/api/git/credentials.go @@ -4,10 +4,10 @@ import ( gittypes "github.com/portainer/portainer/api/git/types" ) -func GetCredentials(auth *gittypes.GitAuthentication) (string, string, error) { +func GetCredentials(auth *gittypes.GitAuthentication) (string, string) { if auth == nil { - return "", "", nil + return "", "" } - return auth.Username, auth.Password, nil + return auth.Username, auth.Password } diff --git a/api/git/update/update.go b/api/git/update/update.go index ec8125b09..30899d143 100644 --- a/api/git/update/update.go +++ b/api/git/update/update.go @@ -25,10 +25,7 @@ func UpdateGitObject(ctx context.Context, gitService portainer.GitService, objId Str("object", objId). Msg("the object has a git config, try to poll from git repository") - username, password, err := git.GetCredentials(gitConfig.Authentication) - if err != nil { - return false, "", errors.WithMessagef(err, "failed to get credentials for %v", objId) - } + username, password := git.GetCredentials(gitConfig.Authentication) newHash, err := gitService.LatestCommitID( ctx, diff --git a/api/http/handler/stacks/create_kubernetes_stack.go b/api/http/handler/stacks/create_kubernetes_stack.go index 37dca41e0..7ff431b74 100644 --- a/api/http/handler/stacks/create_kubernetes_stack.go +++ b/api/http/handler/stacks/create_kubernetes_stack.go @@ -307,10 +307,7 @@ func (handler *Handler) deployKubernetesStack(ctx context.Context, userID portai user := &portainer.User{ ID: userID, } - k8sDeploymentConfig, err := deployments.CreateKubernetesStackDeploymentConfig(stack, handler.KubernetesDeployer, appLabels, user, endpoint) - if err != nil { - return "", errors.Wrap(err, "failed to create temp kub deployment files") - } + k8sDeploymentConfig := deployments.CreateKubernetesStackDeploymentConfig(stack, handler.KubernetesDeployer, appLabels, user, endpoint) if err := k8sDeploymentConfig.Deploy(ctx); err != nil { return "", err diff --git a/api/http/handler/stacks/handler.go b/api/http/handler/stacks/handler.go index 33ddb400f..352f64090 100644 --- a/api/http/handler/stacks/handler.go +++ b/api/http/handler/stacks/handler.go @@ -92,7 +92,7 @@ func NewHandler(bouncer security.BouncerService) *Handler { return h } -func (handler *Handler) userCanAccessStack(securityContext *security.RestrictedRequestContext, endpointID portainer.EndpointID, resourceControl *portainer.ResourceControl) (bool, error) { +func (handler *Handler) userCanAccessStack(securityContext *security.RestrictedRequestContext, resourceControl *portainer.ResourceControl) (bool, error) { user, err := handler.DataStore.User().Read(securityContext.UserID) if err != nil { return false, err @@ -104,7 +104,7 @@ func (handler *Handler) userCanAccessStack(securityContext *security.RestrictedR return true, nil } - return stackutils.UserIsAdminOrEndpointAdmin(user, endpointID) + return stackutils.UserIsAdminOrEndpointAdmin(user), nil } func (handler *Handler) userIsAdmin(userID portainer.UserID) (bool, error) { @@ -118,13 +118,13 @@ func (handler *Handler) userIsAdmin(userID portainer.UserID) (bool, error) { return isAdmin, nil } -func (handler *Handler) userCanCreateStack(securityContext *security.RestrictedRequestContext, endpointID portainer.EndpointID) (bool, error) { +func (handler *Handler) userCanCreateStack(securityContext *security.RestrictedRequestContext) (bool, error) { user, err := handler.DataStore.User().Read(securityContext.UserID) if err != nil { return false, err } - return stackutils.UserIsAdminOrEndpointAdmin(user, endpointID) + return stackutils.UserIsAdminOrEndpointAdmin(user), nil } // if stack management is disabled for non admins and the user isn't an admin, then return false. Otherwise return true @@ -136,7 +136,7 @@ func (handler *Handler) userCanManageStacks(securityContext *security.Restricted } if endpointutils.IsDockerEndpoint(endpoint) && !endpoint.SecuritySettings.AllowStackManagementForRegularUsers { - canCreate, err := handler.userCanCreateStack(securityContext, endpoint.ID) + canCreate, err := handler.userCanCreateStack(securityContext) 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 797b4002a..227041de2 100644 --- a/api/http/handler/stacks/stack_delete.go +++ b/api/http/handler/stacks/stack_delete.go @@ -93,7 +93,7 @@ func (handler *Handler) stackDelete(w http.ResponseWriter, r *http.Request) *htt } if stack.Type == portainer.DockerSwarmStack || stack.Type == portainer.DockerComposeStack { - access, err := handler.userCanAccessStack(securityContext, endpoint.ID, resourceControl) + access, err := handler.userCanAccessStack(securityContext, resourceControl) if err != nil { return httperror.InternalServerError("Unable to verify user authorizations to validate stack access", err) } diff --git a/api/http/handler/stacks/stack_file.go b/api/http/handler/stacks/stack_file.go index deeff5f68..72dc70ee7 100644 --- a/api/http/handler/stacks/stack_file.go +++ b/api/http/handler/stacks/stack_file.go @@ -83,7 +83,7 @@ func (handler *Handler) stackFile(w http.ResponseWriter, r *http.Request) *httpe return httperror.InternalServerError("Unable to retrieve a resource control associated to the stack", err) } - access, err := handler.userCanAccessStack(securityContext, endpoint.ID, resourceControl) + access, err := handler.userCanAccessStack(securityContext, resourceControl) if err != nil { return httperror.InternalServerError("Unable to verify user authorizations to validate stack access", err) } diff --git a/api/http/handler/stacks/stack_inspect.go b/api/http/handler/stacks/stack_inspect.go index 40734021b..970c00347 100644 --- a/api/http/handler/stacks/stack_inspect.go +++ b/api/http/handler/stacks/stack_inspect.go @@ -77,7 +77,7 @@ func (handler *Handler) stackInspect(w http.ResponseWriter, r *http.Request) *ht return httperror.InternalServerError("Unable to retrieve a resource control associated to the stack", err) } - access, err := handler.userCanAccessStack(securityContext, endpoint.ID, resourceControl) + access, err := handler.userCanAccessStack(securityContext, resourceControl) if err != nil { return httperror.InternalServerError("Unable to verify user authorizations to validate stack access", err) } diff --git a/api/http/handler/stacks/stack_migrate.go b/api/http/handler/stacks/stack_migrate.go index 633e41b75..276b7e663 100644 --- a/api/http/handler/stacks/stack_migrate.go +++ b/api/http/handler/stacks/stack_migrate.go @@ -102,7 +102,7 @@ func (handler *Handler) stackMigrate(w http.ResponseWriter, r *http.Request) *ht return httperror.InternalServerError("Unable to retrieve a resource control associated to the stack", err) } - access, err := handler.userCanAccessStack(securityContext, endpoint.ID, resourceControl) + access, err := handler.userCanAccessStack(securityContext, resourceControl) if err != nil { return httperror.InternalServerError("Unable to verify user authorizations to validate stack access", err) } @@ -194,10 +194,10 @@ func (handler *Handler) migrateComposeStack(r *http.Request, stack *portainer.St return httperror.InternalServerError("Unable to retrieve info from request context", err) } - composeDeploymentConfig, err := deployments.CreateComposeStackDeploymentConfig(securityContext, + composeDeploymentConfig, err := deployments.CreateComposeStackDeploymentConfigTx(handler.DataStore, + securityContext, stack, next, - handler.DataStore, handler.FileService, handler.StackDeployer, true, @@ -222,10 +222,10 @@ func (handler *Handler) migrateSwarmStack(r *http.Request, stack *portainer.Stac return httperror.InternalServerError("Unable to retrieve info from request context", err) } - swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfig(securityContext, + swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfigTx(handler.DataStore, + securityContext, stack, next, - handler.DataStore, handler.FileService, handler.StackDeployer, true, diff --git a/api/http/handler/stacks/stack_start.go b/api/http/handler/stacks/stack_start.go index 1c96d0461..536fb79e6 100644 --- a/api/http/handler/stacks/stack_start.go +++ b/api/http/handler/stacks/stack_start.go @@ -117,7 +117,7 @@ func (handler *Handler) stackStart(w http.ResponseWriter, r *http.Request) *http return httperror.InternalServerError("Unable to retrieve a resource control associated to the stack", err) } - access, err := handler.userCanAccessStack(securityContext, endpoint.ID, resourceControl) + access, err := handler.userCanAccessStack(securityContext, resourceControl) if err != nil { return httperror.InternalServerError("Unable to verify user authorizations to validate stack access", err) } diff --git a/api/http/handler/stacks/stack_stop.go b/api/http/handler/stacks/stack_stop.go index fbadcf685..f1dcfb174 100644 --- a/api/http/handler/stacks/stack_stop.go +++ b/api/http/handler/stacks/stack_stop.go @@ -75,7 +75,7 @@ func (handler *Handler) stackStop(w http.ResponseWriter, r *http.Request) *httpe return httperror.InternalServerError("Unable to retrieve a resource control associated to the stack", err) } - access, err := handler.userCanAccessStack(securityContext, endpoint.ID, resourceControl) + access, err := handler.userCanAccessStack(securityContext, resourceControl) if err != nil { return httperror.InternalServerError("Unable to verify user authorizations to validate stack access", err) } diff --git a/api/http/handler/stacks/stack_update.go b/api/http/handler/stacks/stack_update.go index a5efd4281..4c5278d61 100644 --- a/api/http/handler/stacks/stack_update.go +++ b/api/http/handler/stacks/stack_update.go @@ -145,7 +145,7 @@ func (handler *Handler) updateStackInTx(tx dataservices.DataStoreTx, r *http.Req return nil, httperror.InternalServerError("Unable to retrieve a resource control associated to the stack", err) } - if access, err := handler.userCanAccessStack(securityContext, endpoint.ID, resourceControl); err != nil { + if access, err := handler.userCanAccessStack(securityContext, resourceControl); err != nil { return nil, httperror.InternalServerError("Unable to verify user authorizations to validate stack access", err) } else if !access { return nil, httperror.Forbidden("Access denied to resource", httperrors.ErrResourceAccessDenied) diff --git a/api/http/handler/stacks/stack_update_git.go b/api/http/handler/stacks/stack_update_git.go index df7c9920c..fa8d0f3d4 100644 --- a/api/http/handler/stacks/stack_update_git.go +++ b/api/http/handler/stacks/stack_update_git.go @@ -124,7 +124,7 @@ func (handler *Handler) stackUpdateGit(w http.ResponseWriter, r *http.Request) * return httperror.InternalServerError("Unable to retrieve a resource control associated to the stack", err) } - if access, err := handler.userCanAccessStack(securityContext, endpoint.ID, resourceControl); err != nil { + if access, err := handler.userCanAccessStack(securityContext, resourceControl); err != nil { return httperror.InternalServerError("Unable to verify user authorizations to validate stack access", err) } else if !access { return httperror.Forbidden("Access denied to resource", httperrors.ErrResourceAccessDenied) diff --git a/api/http/handler/stacks/stack_update_git_redeploy.go b/api/http/handler/stacks/stack_update_git_redeploy.go index db8119fe3..f745477bc 100644 --- a/api/http/handler/stacks/stack_update_git_redeploy.go +++ b/api/http/handler/stacks/stack_update_git_redeploy.go @@ -109,7 +109,7 @@ func (handler *Handler) stackGitRedeploy(w http.ResponseWriter, r *http.Request) return httperror.InternalServerError("Unable to retrieve a resource control associated to the stack", err) } - if access, err := handler.userCanAccessStack(securityContext, endpoint.ID, resourceControl); err != nil { + if access, err := handler.userCanAccessStack(securityContext, resourceControl); err != nil { return httperror.InternalServerError("Unable to verify user authorizations to validate stack access", err) } else if !access { return httperror.Forbidden("Access denied to resource", httperrors.ErrResourceAccessDenied) @@ -226,7 +226,7 @@ func (handler *Handler) deployStack(r *http.Request, stack *portainer.Stack, pul prune := stack.Option != nil && stack.Option.Prune - deploymentConfiger, err = deployments.CreateSwarmStackDeploymentConfig(securityContext, stack, endpoint, handler.DataStore, handler.FileService, handler.StackDeployer, prune, pullImage) + deploymentConfiger, err = deployments.CreateSwarmStackDeploymentConfigTx(handler.DataStore, securityContext, stack, endpoint, handler.FileService, handler.StackDeployer, prune, pullImage) if err != nil { return httperror.InternalServerError(err.Error(), err) } @@ -240,7 +240,7 @@ func (handler *Handler) deployStack(r *http.Request, stack *portainer.Stack, pul prune := stack.Option != nil && stack.Option.Prune - deploymentConfiger, err = deployments.CreateComposeStackDeploymentConfig(securityContext, stack, endpoint, handler.DataStore, handler.FileService, handler.StackDeployer, prune, pullImage, true) + deploymentConfiger, err = deployments.CreateComposeStackDeploymentConfigTx(handler.DataStore, securityContext, stack, endpoint, handler.FileService, handler.StackDeployer, prune, pullImage, true) if err != nil { return httperror.InternalServerError(err.Error(), err) } @@ -266,10 +266,7 @@ func (handler *Handler) deployStack(r *http.Request, stack *portainer.Stack, pul Kind: "git", } - deploymentConfiger, err = deployments.CreateKubernetesStackDeploymentConfig(stack, handler.KubernetesDeployer, appLabel, user, endpoint) - if err != nil { - return httperror.InternalServerError(err.Error(), err) - } + deploymentConfiger = deployments.CreateKubernetesStackDeploymentConfig(stack, handler.KubernetesDeployer, appLabel, user, endpoint) default: return httperror.InternalServerError("Unsupported stack", errors.Errorf("unsupported stack type: %v", stack.Type)) diff --git a/api/platform/service.go b/api/platform/service.go index e74855fb7..5bb1d53f4 100644 --- a/api/platform/service.go +++ b/api/platform/service.go @@ -30,8 +30,8 @@ type service struct { mu sync.Mutex } -func NewService(dataStore dataservices.DataStore) (*service, error) { - return &service{dataStore: dataStore}, nil +func NewService(dataStore dataservices.DataStore) *service { + return &service{dataStore: dataStore} } func (service *service) loadEnvAndPlatform() error { diff --git a/api/stacks/deployments/deployer.go b/api/stacks/deployments/deployer.go index 9cea23444..bddf9a2fb 100644 --- a/api/stacks/deployments/deployer.go +++ b/api/stacks/deployments/deployer.go @@ -97,10 +97,7 @@ func (d *stackDeployer) DeployKubernetesStack(ctx context.Context, stack *portai appLabels.Kind = "git" } - k8sDeploymentConfig, err := CreateKubernetesStackDeploymentConfig(stack, d.kubernetesDeployer, appLabels, user, endpoint) - if err != nil { - return errors.Wrap(err, "failed to create temp kub deployment files") - } + k8sDeploymentConfig := CreateKubernetesStackDeploymentConfig(stack, d.kubernetesDeployer, appLabels, user, endpoint) if err := k8sDeploymentConfig.Deploy(ctx); err != nil { return errors.Wrap(err, "failed to deploy kubernetes application") diff --git a/api/stacks/deployments/deployment_compose_config.go b/api/stacks/deployments/deployment_compose_config.go index 8b16fd58a..cf391d6d8 100644 --- a/api/stacks/deployments/deployment_compose_config.go +++ b/api/stacks/deployments/deployment_compose_config.go @@ -26,13 +26,6 @@ type ComposeStackDeploymentConfig struct { prune bool } -func CreateComposeStackDeploymentConfig(securityContext *security.RestrictedRequestContext, stack *portainer.Stack, endpoint *portainer.Endpoint, dataStore dataservices.DataStore, fileService portainer.FileService, deployer StackDeployer, prune, forcePullImage, forceCreate bool) (*ComposeStackDeploymentConfig, error) { - return CreateComposeStackDeploymentConfigTx(dataStore, securityContext, stack, endpoint, fileService, deployer, prune, forcePullImage, forceCreate) -} - -// Alternate function that works within a transaction -// We didn't update the original function to use a transaction because it would be a breaking change for many other files. -// Let's do this only where necessary for now. This is also planed to be refactored in the future, but not prioritized right now. func CreateComposeStackDeploymentConfigTx(tx dataservices.DataStoreTx, securityContext *security.RestrictedRequestContext, stack *portainer.Stack, endpoint *portainer.Endpoint, fileService portainer.FileService, deployer StackDeployer, prune, forcePullImage, forceCreate bool) (*ComposeStackDeploymentConfig, error) { user, err := tx.User().Read(securityContext.UserID) if err != nil { @@ -75,10 +68,7 @@ func (config *ComposeStackDeploymentConfig) Deploy(ctx context.Context) error { return errors.New("file service or stack deployer cannot be nil") } - isAdminOrEndpointAdmin, err := stackutils.UserIsAdminOrEndpointAdmin(config.user, config.endpoint.ID) - if err != nil { - return errors.Wrap(err, "failed to validate user admin privileges") - } + isAdminOrEndpointAdmin := stackutils.UserIsAdminOrEndpointAdmin(config.user) securitySettings := &config.endpoint.SecuritySettings diff --git a/api/stacks/deployments/deployment_kubernetes_config.go b/api/stacks/deployments/deployment_kubernetes_config.go index 9338c4429..c1d8fd65e 100644 --- a/api/stacks/deployments/deployment_kubernetes_config.go +++ b/api/stacks/deployments/deployment_kubernetes_config.go @@ -22,15 +22,14 @@ type KubernetesStackDeploymentConfig struct { output string } -func CreateKubernetesStackDeploymentConfig(stack *portainer.Stack, kubeDeployer portainer.KubernetesDeployer, appLabels k.KubeAppLabels, user *portainer.User, endpoint *portainer.Endpoint) (*KubernetesStackDeploymentConfig, error) { - +func CreateKubernetesStackDeploymentConfig(stack *portainer.Stack, kubeDeployer portainer.KubernetesDeployer, appLabels k.KubeAppLabels, user *portainer.User, endpoint *portainer.Endpoint) *KubernetesStackDeploymentConfig { return &KubernetesStackDeploymentConfig{ stack: stack, kubernetesDeployer: kubeDeployer, appLabels: appLabels, user: user, endpoint: endpoint, - }, nil + } } func (config *KubernetesStackDeploymentConfig) GetUsername() string { diff --git a/api/stacks/deployments/deployment_swarm_config.go b/api/stacks/deployments/deployment_swarm_config.go index c85e2920a..6e11a0aa0 100644 --- a/api/stacks/deployments/deployment_swarm_config.go +++ b/api/stacks/deployments/deployment_swarm_config.go @@ -24,13 +24,6 @@ type SwarmStackDeploymentConfig struct { StackDeployer StackDeployer } -func CreateSwarmStackDeploymentConfig(securityContext *security.RestrictedRequestContext, stack *portainer.Stack, endpoint *portainer.Endpoint, dataStore dataservices.DataStore, fileService portainer.FileService, deployer StackDeployer, prune bool, pullImage bool) (*SwarmStackDeploymentConfig, error) { - return CreateSwarmStackDeploymentConfigTx(dataStore, securityContext, stack, endpoint, fileService, deployer, prune, pullImage) -} - -// Alternate function that works within a transaction -// We didn't update the original function to use a transaction because it would be a breaking change for many other files. -// Let's do this only where necessary for now. This is also planed to be refactored in the future, but not prioritized right now. func CreateSwarmStackDeploymentConfigTx(tx dataservices.DataStoreTx, securityContext *security.RestrictedRequestContext, stack *portainer.Stack, endpoint *portainer.Endpoint, fileService portainer.FileService, deployer StackDeployer, prune bool, pullImage bool) (*SwarmStackDeploymentConfig, error) { user, err := tx.User().Read(securityContext.UserID) if err != nil { @@ -72,10 +65,7 @@ func (config *SwarmStackDeploymentConfig) Deploy(ctx context.Context) error { return errors.New("file service or stack deployer cannot be nil") } - isAdminOrEndpointAdmin, err := stackutils.UserIsAdminOrEndpointAdmin(config.user, config.endpoint.ID) - if err != nil { - return errors.Wrap(err, "failed to validate user admin privileges") - } + isAdminOrEndpointAdmin := stackutils.UserIsAdminOrEndpointAdmin(config.user) settings := &config.endpoint.SecuritySettings diff --git a/api/stacks/stackbuilders/compose_file_content_builder.go b/api/stacks/stackbuilders/compose_file_content_builder.go index 5ca9bbf2e..67809d595 100644 --- a/api/stacks/stackbuilders/compose_file_content_builder.go +++ b/api/stacks/stackbuilders/compose_file_content_builder.go @@ -69,7 +69,7 @@ func (b *ComposeStackFileContentBuilder) Deploy(ctx context.Context, payload *St return b } - composeDeploymentConfig, err := deployments.CreateComposeStackDeploymentConfig(b.SecurityContext, b.stack, endpoint, b.dataStore, b.fileService, b.stackDeployer, false, false, false) + composeDeploymentConfig, err := deployments.CreateComposeStackDeploymentConfigTx(b.dataStore, b.SecurityContext, b.stack, endpoint, b.fileService, b.stackDeployer, false, false, false) if err != nil { b.err = err return b diff --git a/api/stacks/stackbuilders/compose_file_upload_builder.go b/api/stacks/stackbuilders/compose_file_upload_builder.go index 4e99b4c39..38ffffde7 100644 --- a/api/stacks/stackbuilders/compose_file_upload_builder.go +++ b/api/stacks/stackbuilders/compose_file_upload_builder.go @@ -60,7 +60,7 @@ func (b *ComposeStackFileUploadBuilder) Deploy(ctx context.Context, payload *Sta return b } - composeDeploymentConfig, err := deployments.CreateComposeStackDeploymentConfig(b.SecurityContext, b.stack, endpoint, b.dataStore, b.fileService, b.stackDeployer, false, false, false) + composeDeploymentConfig, err := deployments.CreateComposeStackDeploymentConfigTx(b.dataStore, b.SecurityContext, b.stack, endpoint, b.fileService, b.stackDeployer, false, false, false) if err != nil { b.err = err return b diff --git a/api/stacks/stackbuilders/compose_git_builder.go b/api/stacks/stackbuilders/compose_git_builder.go index bcd7c361a..ee88a5c85 100644 --- a/api/stacks/stackbuilders/compose_git_builder.go +++ b/api/stacks/stackbuilders/compose_git_builder.go @@ -62,7 +62,7 @@ func (b *ComposeStackGitBuilder) Deploy(ctx context.Context, payload *StackPaylo return b } - composeDeploymentConfig, err := deployments.CreateComposeStackDeploymentConfig(b.SecurityContext, b.stack, endpoint, b.dataStore, b.fileService, b.stackDeployer, false, false, false) + composeDeploymentConfig, err := deployments.CreateComposeStackDeploymentConfigTx(b.dataStore, b.SecurityContext, b.stack, endpoint, b.fileService, b.stackDeployer, false, false, false) if err != nil { b.err = err return b diff --git a/api/stacks/stackbuilders/k8s_file_content_builder.go b/api/stacks/stackbuilders/k8s_file_content_builder.go index 421f72b56..c23ab4c12 100644 --- a/api/stacks/stackbuilders/k8s_file_content_builder.go +++ b/api/stacks/stackbuilders/k8s_file_content_builder.go @@ -92,12 +92,7 @@ func (b *K8sStackFileContentBuilder) Deploy(ctx context.Context, payload *StackP Kind: "content", } - k8sDeploymentConfig, err := deployments.CreateKubernetesStackDeploymentConfig(b.stack, b.KuberneteDeployer, k8sAppLabel, b.User, endpoint) - if err != nil { - b.err = fmt.Errorf("failed to create temp kub deployment files: %w", err) - - return b - } + k8sDeploymentConfig := deployments.CreateKubernetesStackDeploymentConfig(b.stack, b.KuberneteDeployer, k8sAppLabel, b.User, endpoint) b.deploymentConfiger = k8sDeploymentConfig diff --git a/api/stacks/stackbuilders/k8s_git_builder.go b/api/stacks/stackbuilders/k8s_git_builder.go index 26af9e2db..520196d6a 100644 --- a/api/stacks/stackbuilders/k8s_git_builder.go +++ b/api/stacks/stackbuilders/k8s_git_builder.go @@ -2,7 +2,6 @@ package stackbuilders import ( "context" - "fmt" "sync" portainer "github.com/portainer/portainer/api" @@ -83,11 +82,7 @@ func (b *KubernetesStackGitBuilder) Deploy(ctx context.Context, payload *StackPa Kind: "git", } - k8sDeploymentConfig, err := deployments.CreateKubernetesStackDeploymentConfig(b.stack, b.KuberneteDeployer, k8sAppLabel, b.user, endpoint) - if err != nil { - b.err = fmt.Errorf("failed to create temp kub deployment files: %w", err) - return b - } + k8sDeploymentConfig := deployments.CreateKubernetesStackDeploymentConfig(b.stack, b.KuberneteDeployer, k8sAppLabel, b.user, endpoint) b.deploymentConfiger = k8sDeploymentConfig diff --git a/api/stacks/stackbuilders/k8s_url_builder.go b/api/stacks/stackbuilders/k8s_url_builder.go index 13f6ca286..462b42a13 100644 --- a/api/stacks/stackbuilders/k8s_url_builder.go +++ b/api/stacks/stackbuilders/k8s_url_builder.go @@ -98,12 +98,7 @@ func (b *KubernetesStackUrlBuilder) Deploy(ctx context.Context, payload *StackPa Kind: "url", } - k8sDeploymentConfig, err := deployments.CreateKubernetesStackDeploymentConfig(b.stack, b.KuberneteDeployer, k8sAppLabel, b.user, endpoint) - if err != nil { - b.err = fmt.Errorf("failed to create temp kub deployment files: %w", err) - - return b - } + k8sDeploymentConfig := deployments.CreateKubernetesStackDeploymentConfig(b.stack, b.KuberneteDeployer, k8sAppLabel, b.user, endpoint) b.deploymentConfiger = k8sDeploymentConfig diff --git a/api/stacks/stackbuilders/swarm_file_content_builder.go b/api/stacks/stackbuilders/swarm_file_content_builder.go index fca780742..424089f88 100644 --- a/api/stacks/stackbuilders/swarm_file_content_builder.go +++ b/api/stacks/stackbuilders/swarm_file_content_builder.go @@ -70,7 +70,7 @@ func (b *SwarmStackFileContentBuilder) Deploy(ctx context.Context, payload *Stac return b } - swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfig(b.SecurityContext, b.stack, endpoint, b.dataStore, b.fileService, b.stackDeployer, false, true) + swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfigTx(b.dataStore, b.SecurityContext, b.stack, endpoint, b.fileService, b.stackDeployer, false, true) if err != nil { b.err = err return b diff --git a/api/stacks/stackbuilders/swarm_file_upload_builder.go b/api/stacks/stackbuilders/swarm_file_upload_builder.go index 60d82f2bc..3fe920c69 100644 --- a/api/stacks/stackbuilders/swarm_file_upload_builder.go +++ b/api/stacks/stackbuilders/swarm_file_upload_builder.go @@ -64,7 +64,7 @@ func (b *SwarmStackFileUploadBuilder) Deploy(ctx context.Context, payload *Stack return b } - swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfig(b.SecurityContext, b.stack, endpoint, b.dataStore, b.fileService, b.stackDeployer, false, true) + swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfigTx(b.dataStore, b.SecurityContext, b.stack, endpoint, b.fileService, b.stackDeployer, false, true) if err != nil { b.err = err return b diff --git a/api/stacks/stackbuilders/swarm_git_builder.go b/api/stacks/stackbuilders/swarm_git_builder.go index 4945f2dd0..ee4199304 100644 --- a/api/stacks/stackbuilders/swarm_git_builder.go +++ b/api/stacks/stackbuilders/swarm_git_builder.go @@ -64,7 +64,7 @@ func (b *SwarmStackGitBuilder) Deploy(ctx context.Context, payload *StackPayload return b } - swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfig(b.SecurityContext, b.stack, endpoint, b.dataStore, b.fileService, b.stackDeployer, false, true) + swarmDeploymentConfig, err := deployments.CreateSwarmStackDeploymentConfigTx(b.dataStore, b.SecurityContext, b.stack, endpoint, b.fileService, b.stackDeployer, false, true) if err != nil { b.err = err return b diff --git a/api/stacks/stackutils/util.go b/api/stacks/stackutils/util.go index 9a4daeae3..1d263d088 100644 --- a/api/stacks/stackutils/util.go +++ b/api/stacks/stackutils/util.go @@ -9,10 +9,8 @@ import ( "github.com/portainer/portainer/api/filesystem" ) -func UserIsAdminOrEndpointAdmin(user *portainer.User, endpointID portainer.EndpointID) (bool, error) { - isAdmin := user.Role == portainer.AdministratorRole - - return isAdmin, nil +func UserIsAdminOrEndpointAdmin(user *portainer.User) bool { + return user.Role == portainer.AdministratorRole } // GetStackFilePaths returns a list of file paths based on stack project path diff --git a/pkg/libhelm/manager.go b/pkg/libhelm/manager.go index 1396195bd..14b894eea 100644 --- a/pkg/libhelm/manager.go +++ b/pkg/libhelm/manager.go @@ -6,6 +6,6 @@ import ( ) // NewHelmPackageManager returns a new instance of HelmPackageManager based on HelmConfig -func NewHelmPackageManager() (types.HelmPackageManager, error) { - return sdk.NewHelmSDKPackageManager(), nil +func NewHelmPackageManager() types.HelmPackageManager { + return sdk.NewHelmSDKPackageManager() }