"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/secret/set/set.go" between
gh-cli-1.10.3.tar.gz and gh-cli-1.11.0.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

set.go  (gh-cli-1.10.3):set.go  (gh-cli-1.11.0)
skipping to change at line 36 skipping to change at line 36
type SetOptions struct { type SetOptions struct {
HttpClient func() (*http.Client, error) HttpClient func() (*http.Client, error)
IO *iostreams.IOStreams IO *iostreams.IOStreams
Config func() (config.Config, error) Config func() (config.Config, error)
BaseRepo func() (ghrepo.Interface, error) BaseRepo func() (ghrepo.Interface, error)
RandomOverride io.Reader RandomOverride io.Reader
SecretName string SecretName string
OrgName string OrgName string
EnvName string
Body string Body string
Visibility string Visibility string
RepositoryNames []string RepositoryNames []string
} }
func NewCmdSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command { func NewCmdSet(f *cmdutil.Factory, runF func(*SetOptions) error) *cobra.Command {
opts := &SetOptions{ opts := &SetOptions{
IO: f.IOStreams, IO: f.IOStreams,
Config: f.Config, Config: f.Config,
HttpClient: f.HttpClient, HttpClient: f.HttpClient,
} }
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "set <secret-name>", Use: "set <secret-name>",
Short: "Create or update secrets", Short: "Create or update secrets",
Long: "Locally encrypt a new or updated secret at either the rep ository or organization level and send it to GitHub for storage.", Long: "Locally encrypt a new or updated secret at either the rep ository, environment, or organization level and send it to GitHub for storage.",
Example: heredoc.Doc(` Example: heredoc.Doc(`
Paste secret in prompt Paste secret in prompt
$ gh secret set MYSECRET $ gh secret set MYSECRET
Use environment variable as secret value Use environment variable as secret value
$ gh secret set MYSECRET -b"${ENV_VALUE}" $ gh secret set MYSECRET -b"${ENV_VALUE}"
Use file as secret value Use file as secret value
$ gh secret set MYSECRET < file.json $ gh secret set MYSECRET < file.json
Set environment level secret
$ gh secret set MYSECRET -bval --env=anEnv
Set organization level secret visible to entire organizat ion Set organization level secret visible to entire organizat ion
$ gh secret set MYSECRET -bval --org=anOrg --visibility=a ll $ gh secret set MYSECRET -bval --org=anOrg --visibility=a ll
Set organization level secret visible only to certain rep ositories Set organization level secret visible only to certain rep ositories
$ gh secret set MYSECRET -bval --org=anOrg --repos="repo1 ,repo2,repo3" $ gh secret set MYSECRET -bval --org=anOrg --repos="repo1 ,repo2,repo3"
`), `),
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 { if len(args) != 1 {
return &cmdutil.FlagError{Err: errors.New("must p ass single secret name")} return &cmdutil.FlagError{Err: errors.New("must p ass single secret name")}
} }
return nil return nil
}, },
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
// support `-R, --repo` override // support `-R, --repo` override
opts.BaseRepo = f.BaseRepo opts.BaseRepo = f.BaseRepo
if err := cmdutil.MutuallyExclusive("specify only one of
`--org` or `--env`", opts.OrgName != "", opts.EnvName != ""); err != nil {
return err
}
opts.SecretName = args[0] opts.SecretName = args[0]
err := validSecretName(opts.SecretName) err := validSecretName(opts.SecretName)
if err != nil { if err != nil {
return err return err
} }
if cmd.Flags().Changed("visibility") { if cmd.Flags().Changed("visibility") {
if opts.OrgName == "" { if opts.OrgName == "" {
return &cmdutil.FlagError{Err: errors.New ( return &cmdutil.FlagError{Err: errors.New (
skipping to change at line 118 skipping to change at line 126
} }
} }
if runF != nil { if runF != nil {
return runF(opts) return runF(opts)
} }
return setRun(opts) return setRun(opts)
}, },
} }
cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "List secrets for a cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "Set a secret for a
n organization") n organization")
cmd.Flags().StringVarP(&opts.EnvName, "env", "e", "", "Set a secret for a
n organization")
cmd.Flags().StringVarP(&opts.Visibility, "visibility", "v", "private", "S et visibility for an organization secret: `all`, `private`, or `selected`") cmd.Flags().StringVarP(&opts.Visibility, "visibility", "v", "private", "S et visibility for an organization secret: `all`, `private`, or `selected`")
cmd.Flags().StringSliceVarP(&opts.RepositoryNames, "repos", "r", []string {}, "List of repository names for `selected` visibility") cmd.Flags().StringSliceVarP(&opts.RepositoryNames, "repos", "r", []string {}, "List of repository names for `selected` visibility")
cmd.Flags().StringVarP(&opts.Body, "body", "b", "", "A value for the secr et. Reads from STDIN if not specified.") cmd.Flags().StringVarP(&opts.Body, "body", "b", "", "A value for the secr et. Reads from STDIN if not specified.")
return cmd return cmd
} }
func setRun(opts *SetOptions) error { func setRun(opts *SetOptions) error {
body, err := getBody(opts) body, err := getBody(opts)
if err != nil { if err != nil {
return fmt.Errorf("did not understand secret body: %w", err) return fmt.Errorf("did not understand secret body: %w", err)
} }
c, err := opts.HttpClient() c, err := opts.HttpClient()
if err != nil { if err != nil {
return fmt.Errorf("could not create http client: %w", err) return fmt.Errorf("could not create http client: %w", err)
} }
client := api.NewClientFromHTTP(c) client := api.NewClientFromHTTP(c)
orgName := opts.OrgName orgName := opts.OrgName
envName := opts.EnvName
var baseRepo ghrepo.Interface var baseRepo ghrepo.Interface
if orgName == "" { if orgName == "" {
baseRepo, err = opts.BaseRepo() baseRepo, err = opts.BaseRepo()
if err != nil { if err != nil {
return fmt.Errorf("could not determine base repo: %w", er r) return fmt.Errorf("could not determine base repo: %w", er r)
} }
} }
cfg, err := opts.Config() cfg, err := opts.Config()
skipping to change at line 177 skipping to change at line 187
eBody, err := box.SealAnonymous(nil, body, &pk.Raw, opts.RandomOverride) eBody, err := box.SealAnonymous(nil, body, &pk.Raw, opts.RandomOverride)
if err != nil { if err != nil {
return fmt.Errorf("failed to encrypt body: %w", err) return fmt.Errorf("failed to encrypt body: %w", err)
} }
encoded := base64.StdEncoding.EncodeToString(eBody) encoded := base64.StdEncoding.EncodeToString(eBody)
if orgName != "" { if orgName != "" {
err = putOrgSecret(client, host, pk, *opts, encoded) err = putOrgSecret(client, host, pk, *opts, encoded)
} else if envName != "" {
err = putEnvSecret(client, pk, baseRepo, envName, opts.SecretName
, encoded)
} else { } else {
err = putRepoSecret(client, pk, baseRepo, opts.SecretName, encode d) err = putRepoSecret(client, pk, baseRepo, opts.SecretName, encode d)
} }
if err != nil { if err != nil {
return fmt.Errorf("failed to set secret: %w", err) return fmt.Errorf("failed to set secret: %w", err)
} }
if opts.IO.IsStdoutTTY() { if opts.IO.IsStdoutTTY() {
target := orgName target := orgName
if orgName == "" { if orgName == "" {
 End of changes. 7 change blocks. 
3 lines changed or deleted 18 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)