-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fully support for running in CI process
- Loading branch information
Showing
5 changed files
with
133 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,126 @@ | ||
import click | ||
from .config import pass_config, create_artifacts | ||
from .config import pass_config, pass_validate, create_artifacts | ||
from .profile import Profile | ||
from .secret import Secret | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
@pass_config | ||
@click.option('--ci', is_flag=True, help="Use this flag to avoid deletion confirmation prompts") # noqa: E501 | ||
def cli(config, ci): | ||
"""All commands can run without providing options, and then you'll be prompted to insert values.\n | ||
Secrets' values and Personal-Access-Tokens are hidden when prompted""" # noqa: E501 | ||
pass | ||
config.ci = ci # noqa: F821 | ||
|
||
|
||
@cli.command() | ||
def init(): | ||
@pass_config | ||
def init(config): | ||
"""Create a credentials file to store your profiles""" | ||
create_artifacts() | ||
|
||
|
||
@cli.command() | ||
@pass_validate | ||
@pass_config | ||
@click.option('--profile-name', '-p', prompt=True) | ||
@click.option('--github-owner', '-o', prompt=True) | ||
@click.option('--personal-access-token', '-t', prompt=True, hide_input=True) | ||
def profile_apply(config, profile_name, github_owner, personal_access_token): | ||
@click.option( | ||
'--personal-access-token', '-t', prompt=True, | ||
hide_input=True, confirmation_prompt=True | ||
) | ||
def profile_apply( | ||
config, validate, | ||
profile_name, github_owner, personal_access_token | ||
): | ||
"""Create or modify a profile""" | ||
profile = Profile(profile_name) | ||
profile = Profile(config, profile_name) | ||
profile.apply(github_owner, personal_access_token) | ||
|
||
|
||
@cli.command() | ||
@pass_validate | ||
@pass_config | ||
@click.option('--profile-name', '-p', prompt=True) | ||
def profile_delete(config, profile_name): | ||
def profile_delete( | ||
config, validate, | ||
profile_name | ||
): | ||
"""Delete a profile""" | ||
profile = Profile(profile_name) | ||
profile = Profile(config, profile_name) | ||
profile.delete() | ||
|
||
|
||
@cli.command() | ||
@pass_validate | ||
@pass_config | ||
def profile_list(config): | ||
def profile_list(config, validate): | ||
"""List all profile - truncates personal access tokens""" | ||
Profile.lista() | ||
|
||
|
||
@cli.command() | ||
@pass_validate | ||
@pass_config | ||
@click.option('--repository', '-r', prompt=True) | ||
@click.option('--profile-name', '-p', prompt=True) | ||
@click.option('--secret-name', '-s', prompt=True) | ||
@click.option('--secret-value', '-v', prompt=True, hide_input=True) # noqa: E501 | ||
def secret_apply(config, repository, profile_name, secret_name, secret_value): | ||
@click.option( | ||
'--secret-value', '-v', prompt=True, | ||
hide_input=True, confirmation_prompt=True | ||
) | ||
def secret_apply( | ||
config, validate, | ||
repository, profile_name, secret_name, secret_value | ||
): | ||
"""Create or modify a secret in a GitHub repository""" | ||
profile = Profile(profile_name) | ||
secret = Secret(profile, repository, secret_name, secret_value) | ||
profile = Profile(config, profile_name) | ||
secret = Secret(config, profile, repository, secret_name, secret_value) | ||
secret.apply() | ||
|
||
|
||
@cli.command() | ||
@pass_validate | ||
@pass_config | ||
@click.option('--repository', '-r', prompt=True) | ||
@click.option('--profile-name', '-p', prompt=True) | ||
@click.option('--secret-name', '-s', prompt=True) | ||
def secret_delete(config, repository, profile_name, secret_name): | ||
def secret_delete( | ||
config, validate, | ||
repository, profile_name, secret_name | ||
): | ||
"""Delete a secret in a GitHub repository""" | ||
profile = Profile(profile_name) | ||
secret = Secret(profile, repository, secret_name) | ||
profile = Profile(config, profile_name) | ||
secret = Secret(config, profile, repository, secret_name) | ||
secret.delete() | ||
|
||
|
||
@cli.command() | ||
@pass_validate | ||
@pass_config | ||
@click.option('--repository', '-r', prompt=True) | ||
@click.option('--profile-name', '-p', prompt=True) | ||
@click.option('--secret-name', '-s', prompt=True) | ||
def secret_get(config, repository, profile_name, secret_name): | ||
def secret_get( | ||
config, validate, | ||
repository, profile_name, secret_name | ||
): | ||
"""Get a secret from a GitHub repository""" | ||
profile = Profile(profile_name) | ||
secret = Secret(profile, repository, secret_name) | ||
profile = Profile(config, profile_name) | ||
secret = Secret(config, profile, repository, secret_name) | ||
secret.get() | ||
|
||
|
||
@cli.command() | ||
@pass_validate | ||
@pass_config | ||
@click.option('--repository', '-r', prompt=True) | ||
@click.option('--profile-name', '-p', prompt=True) | ||
def secret_list(config, repository, profile_name): | ||
def secret_list( | ||
config, validate, | ||
repository, profile_name | ||
): | ||
"""List all secret in a GitHub repository""" | ||
profile = Profile(profile_name) | ||
secret = Secret(profile, repository) | ||
profile = Profile(config, profile_name) | ||
secret = Secret(config, profile, repository) | ||
secret.lista() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
#!/bin/bash | ||
PYTHON_VERSION=$(python -c 'import platform; print(platform.python_version())') | ||
PYTHON_VERSION=$(echo $PYTHON_VERSION | sed "s|\.||g") | ||
PROFILE_NAME=unfor19 | ||
REPOSITORY_NAME=githubsecrets | ||
|
||
echo ">> INIT" | ||
ghs init | ||
ghs --ci init | ||
echo ">> List profiles - no profiles yet" | ||
ghs --ci profile-list | ||
echo ">> Add profile" | ||
ghs profile-apply -p unfor19 -o unfor19 -t $GITHUB_TOKEN | ||
ghs --ci profile-apply -p $PROFILE_NAME -o $PROFILE_NAME -t $GITHUB_TOKEN | ||
echo ">> List profiles - Should see $PROFILE_NAME" | ||
ghs --ci profile-list | ||
echo ">> Add secret - TEST_${PYTHON_VERSION}" | ||
ghs secret-apply -p unfor19 -r githubsecrets -s "TEST_${PYTHON_VERSION}" -v oompaloompa | ||
ghs --ci secret-apply -p $PROFILE_NAME -r $REPOSITORY_NAME -s "TEST_${PYTHON_VERSION}" -v oompaloompa | ||
echo ">> List secrets" | ||
ghs secret-list -p unfor19 -r githubsecrets | ||
ghs --ci secret-list -p $PROFILE_NAME -r $REPOSITORY_NAME | ||
echo ">> Get secret - TEST_${PYTHON_VERSION}" | ||
ghs secret-get -p unfor19 -r githubsecrets -s "TEST_${PYTHON_VERSION}" | ||
ghs --ci secret-get -p $PROFILE_NAME -r $REPOSITORY_NAME -s "TEST_${PYTHON_VERSION}" | ||
echo ">> Delete secret - TEST_${PYTHON_VERSION}" | ||
ghs secret-delete -p unfor19 -r githubsecrets -s "TEST_${PYTHON_VERSION}" | ||
ghs --ci secret-delete -p $PROFILE_NAME -r $REPOSITORY_NAME -s "TEST_${PYTHON_VERSION}" | ||
echo ">> Delete profile - $PROFILE_NAME" | ||
ghs --ci profile-delete -p $PROFILE_NAME | ||
echo ">> Remove credentials file" | ||
rm -r ~/.githubsecrets |