Skip to content

Add support for setting environments secrets#3769

Merged
vilmibm merged 3 commits intocli:trunkfrom
browniebroke:feat/set-env-secrets
Jun 2, 2021
Merged

Add support for setting environments secrets#3769
vilmibm merged 3 commits intocli:trunkfrom
browniebroke:feat/set-env-secrets

Conversation

@browniebroke
Copy link
Contributor

Support to list environemnt secrets was added in #3270 but it would be nice to also be able to set them.

Fixes #3265

in the current directory, query the GitHub API, scan the user's `~/.ssh/config` file, clone or fetch git
repositories, etc. Naturally, none of these things should ever happen for real when running tests, unless
you are sure that any filesystem operations are stricly scoped to a location made for and maintained by the
you are sure that any filesystem operations are strictly scoped to a location made for and maintained by the
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, a small typo I noticed.

return setRun(opts)
},
}
cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "List secrets for an organization")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this description was wrong, fixed it while I was touching the code around.

Comment on lines +187 to +188
} else {
err = putRepoSecret(client, pk, baseRepo, opts.SecretName, encoded)
if envName != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's the most idiomatic way of writing this, let me know if you prefer it as:

	if orgName != "" {
		err = putOrgSecret(client, host, pk, *opts, encoded)
	} else if envName != "" {
		err = putEnvSecret(client, pk, baseRepo, envName, opts.SecretName, encoded)
	} else {
		err = putRepoSecret(client, pk, baseRepo, opts.SecretName, encoded)
	}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collapsing that nested conditional nto the else as you suggested would be a welcome change; it's so minor I'll just push a commit before I merge.

assert.Equal(t, payload.EncryptedValue, "UKYUCbHd0DJemxa3AOcZ6XcsBwALG9d4bpB8ZT0gSV39vl3BHiGSgj8zJapDxgB2BwqNqRhpjC4=")
}

func Test_setRun_env(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost like Test_setRun_repo above, except the 2nd mock and the EnvName option... Might be better to parametrize the existing test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now!

@browniebroke browniebroke marked this pull request as ready for review June 2, 2021 15:18
@vilmibm vilmibm self-requested a review June 2, 2021 16:50
Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!! It's super helpful and I appreciate how neatly you fit it into our existing code/UX.

assert.Equal(t, payload.EncryptedValue, "UKYUCbHd0DJemxa3AOcZ6XcsBwALG9d4bpB8ZT0gSV39vl3BHiGSgj8zJapDxgB2BwqNqRhpjC4=")
}

func Test_setRun_env(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now!

Comment on lines +187 to +188
} else {
err = putRepoSecret(client, pk, baseRepo, opts.SecretName, encoded)
if envName != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collapsing that nested conditional nto the else as you suggested would be a welcome change; it's so minor I'll just push a commit before I merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for environment secrets

2 participants