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

feat: db driven platform settings #554

Merged
merged 36 commits into from
May 15, 2024

feat: settings view and update with optionals

a01afd2
Select commit
Loading
Failed to load commit list.
Sign in for the full log view
Merged

feat: db driven platform settings #554

feat: settings view and update with optionals
a01afd2
Select commit
Loading
Failed to load commit list.
GitHub Actions / golangci failed May 3, 2024 in 1s

reviewdog [golangci] report

reported by reviewdog 🐶

Findings (22)

command/settings/update.go|141 col 39| undefined: vela.UInt64 (typecheck)
cmd/vela-cli/compile.go|8 col 2| could not import github.com/go-vela/cli/command/pipeline (-: # github.com/go-vela/cli/command/pipeline
command/pipeline/exec.go|319 col 9| client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)
command/pipeline/exec.go|324 col 10| client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
command/pipeline/exec.go|328 col 10| client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
command/pipeline/validate.go|250 col 9| client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)
command/pipeline/validate.go|255 col 10| client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
command/pipeline/validate.go|259 col 10| client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)) (typecheck)
action/pipeline/compile.go|1| : # github.com/go-vela/cli/action/pipeline [github.com/go-vela/cli/action/pipeline.test]
action/pipeline/validate_test.go|180 col 9| client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth) (typecheck)
action/settings/update.go|34 col 29| client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
action/settings/view.go|20 col 35| client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
command/pipeline/compile.go|1| : # github.com/go-vela/cli/command/pipeline [github.com/go-vela/cli/command/pipeline.test]
command/pipeline/exec.go|319 col 9| client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)
command/pipeline/exec.go|324 col 10| client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
command/pipeline/exec.go|328 col 10| client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
command/pipeline/validate.go|250 col 9| client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)
command/pipeline/validate.go|255 col 10| client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
command/pipeline/validate.go|259 col 10| client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth) (typecheck)
command/secret/add.go|3| 3-215 lines are duplicate of command/secret/update.go:3-215 (dupl)
command/secret/update.go|3| 3-215 lines are duplicate of command/secret/add.go:3-215 (dupl)
internal/output/yaml_test.go|72 col 39| unused-parameter: parameter 'unmarshal' seems to be unused, consider removing or renaming it as _ (revive)

Filtered Findings (0)

Annotations

Check failure on line 141 in command/settings/update.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/settings/update.go#L141

undefined: vela.UInt64 (typecheck)
Raw output
command/settings/update.go:141:39: undefined: vela.UInt64 (typecheck)
		s.Compiler.StarlarkExecLimit = vela.UInt64(c.Uint64(CompilerStarlarkExecLimitKey))
		                                    ^

Check failure on line 8 in cmd/vela-cli/compile.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] cmd/vela-cli/compile.go#L8

could not import github.com/go-vela/cli/command/pipeline (-: # github.com/go-vela/cli/command/pipeline
Raw output
cmd/vela-cli/compile.go:8:2: could not import github.com/go-vela/cli/command/pipeline (-: # github.com/go-vela/cli/command/pipeline

Check failure on line 319 in command/pipeline/exec.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/exec.go#L319

client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)
Raw output
command/pipeline/exec.go:319:9: client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)

Check failure on line 324 in command/pipeline/exec.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/exec.go#L324

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
Raw output
command/pipeline/exec.go:324:10: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)

Check failure on line 328 in command/pipeline/exec.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/exec.go#L328

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
Raw output
command/pipeline/exec.go:328:10: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)

Check failure on line 250 in command/pipeline/validate.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/validate.go#L250

client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)
Raw output
command/pipeline/validate.go:250:9: client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)

Check failure on line 255 in command/pipeline/validate.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/validate.go#L255

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
Raw output
command/pipeline/validate.go:255:10: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)

Check failure on line 259 in command/pipeline/validate.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/validate.go#L259

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)) (typecheck)
Raw output
command/pipeline/validate.go:259:10: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)) (typecheck)
	"github.com/go-vela/cli/command/pipeline"
	^

Check failure on line 1 in action/pipeline/compile.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] action/pipeline/compile.go#L1

: # github.com/go-vela/cli/action/pipeline [github.com/go-vela/cli/action/pipeline.test]
Raw output
action/pipeline/compile.go:1: : # github.com/go-vela/cli/action/pipeline [github.com/go-vela/cli/action/pipeline.test]

Check failure on line 180 in action/pipeline/validate_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] action/pipeline/validate_test.go#L180

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth) (typecheck)
Raw output
action/pipeline/validate_test.go:180:9: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth) (typecheck)
// SPDX-License-Identifier: Apache-2.0

Check failure on line 34 in action/settings/update.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] action/settings/update.go#L34

client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
Raw output
action/settings/update.go:34:29: client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
	s_, _, err := client.Admin.Settings.Update(s)
	                           ^

Check failure on line 20 in action/settings/view.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] action/settings/view.go#L20

client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
Raw output
action/settings/view.go:20:35: client.Admin.Settings undefined (type *vela.AdminService has no field or method Settings) (typecheck)
	response, _, err := client.Admin.Settings.Get()
	                                 ^

Check failure on line 1 in command/pipeline/compile.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/compile.go#L1

: # github.com/go-vela/cli/command/pipeline [github.com/go-vela/cli/command/pipeline.test]
Raw output
command/pipeline/compile.go:1: : # github.com/go-vela/cli/command/pipeline [github.com/go-vela/cli/command/pipeline.test]

Check failure on line 319 in command/pipeline/exec.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/exec.go#L319

client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)
Raw output
command/pipeline/exec.go:319:9: client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)

Check failure on line 324 in command/pipeline/exec.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/exec.go#L324

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
Raw output
command/pipeline/exec.go:324:10: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)

Check failure on line 328 in command/pipeline/exec.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/exec.go#L328

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
Raw output
command/pipeline/exec.go:328:10: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)

Check failure on line 250 in command/pipeline/validate.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/validate.go#L250

client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)
Raw output
command/pipeline/validate.go:250:9: client.SetStarlarkExecLimit undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetStarlarkExecLimit)

Check failure on line 255 in command/pipeline/validate.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/validate.go#L255

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)
Raw output
command/pipeline/validate.go:255:10: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth)

Check failure on line 259 in command/pipeline/validate.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/pipeline/validate.go#L259

client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth) (typecheck)
Raw output
command/pipeline/validate.go:259:10: client.SetTemplateDepth undefined (type *"github.com/go-vela/server/compiler/native".client has no field or method SetTemplateDepth) (typecheck)
// SPDX-License-Identifier: Apache-2.0

Check failure on line 3 in command/secret/add.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/secret/add.go#L3

3-215 lines are duplicate of `command/secret/update.go:3-215` (dupl)
Raw output
command/secret/add.go:3: 3-215 lines are duplicate of `command/secret/update.go:3-215` (dupl)
package secret

import (
	"fmt"
	"slices"

	"github.com/urfave/cli/v2"

	"github.com/go-vela/cli/action"
	"github.com/go-vela/cli/action/secret"
	"github.com/go-vela/cli/internal"
	"github.com/go-vela/cli/internal/client"
	"github.com/go-vela/types/constants"
)

// CommandAdd defines the command for creating a secret.
var CommandAdd = &cli.Command{
	Name:        "secret",
	Description: "Use this command to create a secret.",
	Usage:       "Add a new secret from the provided configuration",
	Action:      add,
	Flags: []cli.Flag{

		// Repo Flags

		&cli.StringFlag{
			EnvVars: []string{"VELA_ORG", "SECRET_ORG"},
			Name:    internal.FlagOrg,
			Aliases: []string{"o"},
			Usage:   "provide the organization for the secret",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_REPO", "SECRET_REPO"},
			Name:    internal.FlagRepo,
			Aliases: []string{"r"},
			Usage:   "provide the repository for the secret",
		},

		// Secret Flags

		&cli.StringFlag{
			EnvVars: []string{"VELA_ENGINE", "SECRET_ENGINE"},
			Name:    internal.FlagSecretEngine,
			Aliases: []string{"e"},
			Usage:   "provide the engine that stores the secret",
			Value:   constants.DriverNative,
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_TYPE", "SECRET_TYPE"},
			Name:    internal.FlagSecretType,
			Aliases: []string{"ty"},
			Usage:   "provide the type of secret being stored",
			Value:   constants.SecretRepo,
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_TEAM", "SECRET_TEAM"},
			Name:    "team",
			Aliases: []string{"t"},
			Usage:   "provide the team for the secret",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_NAME", "SECRET_NAME"},
			Name:    "name",
			Aliases: []string{"n"},
			Usage:   "provide the name of the secret",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_VALUE", "SECRET_VALUE"},
			Name:    "value",
			Aliases: []string{"v"},
			Usage:   "provide the value for the secret",
		},
		&cli.StringSliceFlag{
			EnvVars: []string{"VELA_IMAGES", "SECRET_IMAGES"},
			Name:    "image",
			Aliases: []string{"i"},
			Usage:   "Provide the image(s) that can access this secret",
		},
		&cli.StringSliceFlag{
			EnvVars: []string{"VELA_EVENTS", "SECRET_EVENTS"},
			Name:    "event",
			Aliases: []string{"events", "ev"},
			Usage:   "provide the event(s) that can access this secret",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_COMMAND", "SECRET_COMMAND"},
			Name:    internal.FlagSecretCommands,
			Aliases: []string{"c"},
			Usage:   "enable a secret to be used for a step with commands (default is false for shared secrets)",
			Value:   "true",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_SUBSTITUTION", "SECRET_SUBSTITUTION"},
			Name:    internal.FlagSecretSubstitution,
			Aliases: []string{"s"},
			Usage:   "enable a secret to be substituted (default is false for shared secrets)",
			Value:   "true",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_FILE", "SECRET_FILE"},
			Name:    "file",
			Aliases: []string{"f"},
			Usage:   "provide a file to add the secret(s)",
		},

		// Output Flags

		&cli.StringFlag{
			EnvVars: []string{"VELA_OUTPUT", "SECRET_OUTPUT"},
			Name:    internal.FlagOutput,
			Aliases: []string{"op"},
			Usage:   "format the output in json, spew or yaml",
		},
	},
	CustomHelpTemplate: fmt.Sprintf(`%s
EXAMPLES:
   1. Add a repository secret.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value bar
   2. Add a repository secret and disallow usage in commands.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value bar --commands false
   3. Add an organization secret.
     $ {{.HelpName}} --secret.engine native --secret.type org --org MyOrg --name foo --value bar
   4. Add a shared secret.
     $ {{.HelpName}} --secret.engine native --secret.type shared --org MyOrg --team octokitties --name foo --value bar
   5. Add a repository secret with all event types enabled.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value bar --event comment --event deployment --event pull_request --event push --event tag
   6. Add a repository secret with an image whitelist.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value bar --image alpine --image golang:* --image postgres:latest
   7. Add a secret with value from a file.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value @secret.txt
   8. Add a repository secret with json output.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value bar --output json
   9. Add a secret or secrets from a file.
     $ {{.HelpName}} --file secret.yml
  10. Add a secret when config or environment variables are set.
     $ {{.HelpName}} --org MyOrg --repo MyRepo --name foo --value bar

DOCUMENTATION:

  https://go-vela.github.io/docs/reference/cli/secret/add/
`, cli.CommandHelpTemplate),
}

// helper function to capture the provided input
// and create the object used to create a secret.
//

func add(c *cli.Context) error {
	// load variables from the config file
	err := action.Load(c)
	if err != nil {
		return err
	}

	// parse the Vela client from the context
	//
	// https://pkg.go.dev/github.com/go-vela/cli/internal/client?tab=doc#Parse
	client, err := client.Parse(c)
	if err != nil {
		return err
	}

	// create the secret configuration
	//
	// https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config
	s := &secret.Config{
		Action:      internal.ActionAdd,
		Engine:      c.String(internal.FlagSecretEngine),
		Type:        c.String(internal.FlagSecretType),
		Org:         c.String(internal.FlagOrg),
		Repo:        c.String(internal.FlagRepo),
		Team:        c.String("team"),
		Name:        c.String("name"),
		Value:       c.String("value"),
		Images:      c.StringSlice("image"),
		AllowEvents: c.StringSlice("event"),
		File:        c.String("file"),
		Output:      c.String(internal.FlagOutput),
	}

	// check if allow_command and allow_substitution are provided
	// if they are not, server will not update the fields
	if slices.Contains(c.FlagNames(), internal.FlagSecretCommands) {
		val := c.Bool(internal.FlagSecretCommands)
		s.AllowCommand = &val
	}

	if slices.Contains(c.FlagNames(), internal.FlagSecretSubstitution) {
		val := c.Bool(internal.FlagSecretSubstitution)
		s.AllowSubstitution = &val
	}

	// validate secret configuration
	//
	// https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config.Validate
	err = s.Validate()
	if err != nil {
		return err
	}

	// check if secret file is provided
	if len(s.File) > 0 {
		// execute the add from file call for the secret configuration
		//
		// https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config.AddFromFile
		return s.AddFromFile(client)
	}

	// execute the add call for the secret configuration
	//
	// https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config.Add
	return s.Add(client)
}

Check failure on line 3 in command/secret/update.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] command/secret/update.go#L3

3-215 lines are duplicate of `command/secret/add.go:3-215` (dupl)
Raw output
command/secret/update.go:3: 3-215 lines are duplicate of `command/secret/add.go:3-215` (dupl)
package secret

import (
	"fmt"
	"slices"

	"github.com/urfave/cli/v2"

	"github.com/go-vela/cli/action"
	"github.com/go-vela/cli/action/secret"
	"github.com/go-vela/cli/internal"
	"github.com/go-vela/cli/internal/client"
	"github.com/go-vela/types/constants"
)

// CommandUpdate defines the command for updating a secret.
var CommandUpdate = &cli.Command{
	Name:        "secret",
	Description: "Use this command to update a secret.",
	Usage:       "Update details of the provided secret",
	Action:      update,
	Flags: []cli.Flag{

		// Repo Flags

		&cli.StringFlag{
			EnvVars: []string{"VELA_ORG", "SECRET_ORG"},
			Name:    internal.FlagOrg,
			Aliases: []string{"o"},
			Usage:   "provide the organization for the secret",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_REPO", "SECRET_REPO"},
			Name:    internal.FlagRepo,
			Aliases: []string{"r"},
			Usage:   "provide the repository for the secret",
		},

		// Secret Flags

		&cli.StringFlag{
			EnvVars: []string{"VELA_ENGINE", "SECRET_ENGINE"},
			Name:    internal.FlagSecretEngine,
			Aliases: []string{"e"},
			Usage:   "provide the engine that stores the secret",
			Value:   constants.DriverNative,
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_TYPE", "SECRET_TYPE"},
			Name:    internal.FlagSecretType,
			Aliases: []string{"ty"},
			Usage:   "provide the type of secret being stored",
			Value:   constants.SecretRepo,
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_TEAM", "SECRET_TEAM"},
			Name:    "team",
			Aliases: []string{"t"},
			Usage:   "provide the team for the secret",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_NAME", "SECRET_NAME"},
			Name:    "name",
			Aliases: []string{"n"},
			Usage:   "provide the name of the secret",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_VALUE", "SECRET_VALUE"},
			Name:    "value",
			Aliases: []string{"v"},
			Usage:   "provide the value for the secret",
		},
		&cli.StringSliceFlag{
			EnvVars: []string{"VELA_IMAGES", "SECRET_IMAGES"},
			Name:    "image",
			Aliases: []string{"i"},
			Usage:   "provide the image(s) that can access this secret",
		},
		&cli.StringSliceFlag{
			EnvVars: []string{"VELA_EVENTS", "SECRET_EVENTS"},
			Name:    "event",
			Aliases: []string{"events", "ev"},
			Usage:   "provide the event(s) that can access this secret",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_COMMAND", "SECRET_COMMAND"},
			Name:    internal.FlagSecretCommands,
			Aliases: []string{"c"},
			Usage:   "enable a secret to be used for a step with commands",
			Value:   "true",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_SUBSTITUTION", "SECRET_SUBSTITUTION"},
			Name:    internal.FlagSecretSubstitution,
			Aliases: []string{"s"},
			Usage:   "enable a secret to be substituted",
			Value:   "true",
		},
		&cli.StringFlag{
			EnvVars: []string{"VELA_FILE", "SECRET_FILE"},
			Name:    "file",
			Aliases: []string{"f"},
			Usage:   "provide a file to update the secret(s)",
		},

		// Output Flags

		&cli.StringFlag{
			EnvVars: []string{"VELA_OUTPUT", "SECRET_OUTPUT"},
			Name:    internal.FlagOutput,
			Aliases: []string{"op"},
			Usage:   "Print the output in default, yaml or json format",
		},
	},
	CustomHelpTemplate: fmt.Sprintf(`%s
EXAMPLES:
   1. Update a repository secret.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value bar
   2. Update a repository secret and disallow usage in commands.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value bar --commands false
   3. Update an organization secret.
     $ {{.HelpName}} --secret.engine native --secret.type org --org MyOrg --name foo --value bar
   4. Update a shared secret.
     $ {{.HelpName}} --secret.engine native --secret.type shared --org MyOrg --team octokitties --name foo --value bar
   5. Update a repository secret with all event types enabled.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --event comment --event deployment --event pull_request --event push --event tag
   6. Update a repository secret with an image whitelist.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --image alpine --image golang:* --image postgres:latest
   7. Update a secret with value from a file.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value @secret.txt
   8. Update a repository secret with json output.
     $ {{.HelpName}} --secret.engine native --secret.type repo --org MyOrg --repo MyRepo --name foo --value bar --output json
   9. Update a secret or secrets from a file.
     $ {{.HelpName}} --file secret.yml
  10. Update a secret when config or environment variables are set.
     $ {{.HelpName}} --org MyOrg --repo MyRepo --name foo --value bar

DOCUMENTATION:

  https://go-vela.github.io/docs/reference/cli/secret/update/
`, cli.CommandHelpTemplate),
}

// helper function to capture the provided input
// and create the object used to modify a secret.
//

func update(c *cli.Context) error {
	// load variables from the config file
	err := action.Load(c)
	if err != nil {
		return err
	}

	// parse the Vela client from the context
	//
	// https://pkg.go.dev/github.com/go-vela/cli/internal/client?tab=doc#Parse
	client, err := client.Parse(c)
	if err != nil {
		return err
	}

	// create the secret configuration
	//
	// https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config
	s := &secret.Config{
		Action:      internal.ActionUpdate,
		Engine:      c.String(internal.FlagSecretEngine),
		Type:        c.String(internal.FlagSecretType),
		Org:         c.String(internal.FlagOrg),
		Repo:        c.String(internal.FlagRepo),
		Team:        c.String("team"),
		Name:        c.String("name"),
		Value:       c.String("value"),
		Images:      c.StringSlice("image"),
		AllowEvents: c.StringSlice("event"),
		File:        c.String("file"),
		Output:      c.String(internal.FlagOutput),
	}

	// check if allow_command and allow_substitution are provided
	// if they are not, server will not update the fields
	if slices.Contains(c.FlagNames(), internal.FlagSecretCommands) {
		val := c.Bool(internal.FlagSecretCommands)
		s.AllowCommand = &val
	}

	if slices.Contains(c.FlagNames(), internal.FlagSecretSubstitution) {
		val := c.Bool(internal.FlagSecretSubstitution)
		s.AllowSubstitution = &val
	}

	// validate secret configuration
	//
	// https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config.Validate
	err = s.Validate()
	if err != nil {
		return err
	}

	// check if secret file is provided
	if len(s.File) > 0 {
		// execute the update from file call for the secret configuration
		//
		// https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config.UpdateFromFile
		return s.UpdateFromFile(client)
	}

	// execute the update call for the secret configuration
	//
	// https://pkg.go.dev/github.com/go-vela/cli/action/secret?tab=doc#Config.Update
	return s.Update(client)
}

Check failure on line 72 in internal/output/yaml_test.go

See this annotation in the file changed.

@github-actions github-actions / golangci

[golangci] internal/output/yaml_test.go#L72

unused-parameter: parameter 'unmarshal' seems to be unused, consider removing or renaming it as _ (revive)
Raw output
internal/output/yaml_test.go:72:39: unused-parameter: parameter 'unmarshal' seems to be unused, consider removing or renaming it as _ (revive)
func (f *failMarshaler) UnmarshalYAML(unmarshal func(interface{}) error) error {
                                      ^