Skip to content

Commit

Permalink
Merge pull request #7 from unfor19/release-1.0.4
Browse files Browse the repository at this point in the history
Release 1.0.4
  • Loading branch information
unfor19 authored Apr 27, 2020
2 parents a3a283e + de28658 commit e5c34de
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 73 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.6.7-slim
WORKDIR /code
RUN pip install --upgrade pip && pip install keyrings.alt && pip install githubsecrets
COPY . .
RUN pip install --upgrade pip && pip install keyrings.alt && pip install --editable .
ENTRYPOINT [ "ghs" ]
6 changes: 3 additions & 3 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:3.6.7-slim
WORKDIR /code
COPY . /code/
RUN python -m pip install --upgrade pip && pip install keyrings.alt && pip install --editable .
ENTRYPOINT [ "ghs" ]
COPY . .
RUN pip install --upgrade pip && pip install keyrings.alt && pip install --editable .
ENTRYPOINT [ "bash" ]
131 changes: 98 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,85 @@ The image runs as a CLI; you must provide arguments, prompts are not available w

Mount your home directory, or any other directory to save the credentials file

**IMPORTANT**: You must create the directory before mounting it, unless it's your home directory. The path must be absolute.

```bash
$ docker run -v $HOME:/root unfor19/githubsecrets --help
Usage: ghs [OPTIONS] COMMAND [ARGS]...
...
$ docker run --rm --mount type=bind,source="$HOME",target=/root unfor19/githubsecrets --ci secret-list -p unfor19 -r githubsecrets
... # Output below
```

<details><summary>Output
</summary>

```json
[
{
"base_url": "https://api.github.com/repos/unfor19/githubsecrets",
"body": {
"secrets": [
{
"created_at": "2020-04-11T00:01:12Z",
"name": "PIP_PASSWORD",
"updated_at": "2020-04-11T00:17:39Z"
},
{
"created_at": "2020-04-10T23:21:28Z",
"name": "PIP_USERNAME",
"updated_at": "2020-04-11T00:17:20Z"
},
{
"created_at": "2020-04-27T20:44:09Z",
"name": "testing",
"updated_at": "2020-04-27T20:45:43Z"
},
{
"created_at": "2020-04-27T20:22:37Z",
"name": "testrepos",
"updated_at": "2020-04-27T20:22:37Z"
},
{
"created_at": "2020-04-14T14:14:44Z",
"name": "TEST_GITHUB_TOKEN",
"updated_at": "2020-04-14T14:14:44Z"
}
],
"total_count": 5
},
"repository": "githubsecrets",
"status_code": 200
}
]
```

</details>

#### Windows

Mount your Temp directory, or any other directory to save the credentials file. Make sure you use `/` and not `\`

**IMPORTANT**: You must create the directory before mounting it, unless it's your Temp directory. The path must be absolute.

```
$ docker run --rm -v c:/Temp:/root unfor19/githubsecrets --help
Usage: ghs [OPTIONS] COMMAND [ARGS]...
...
$ docker run --rm -v c:/Temp:/root unfor19/githubsecrets --ci secret-delete -p unfor19 -r githubsecrets -s testrepos
... # Output below
```

### Build from source
<details><summary>Output
</summary>

```bash
$ git clone https://github.com/unfor19/githubsecrets.git && cd githubsecrets
...
$ pip install --upgrade pip
...
$ pip install -r requirements.txt
...
$ pip install --editable .
...
# Done!
```json
[
{
"base_url": "https://api.github.com/repos/unfor19/githubsecrets",
"repository": "githubsecrets",
"secret_name": "testrepos",
"status_code": 204
}
]
```

</details>

## Getting Started

**Note**: When using Docker, no need to add `ghs`; supply only a command and its arguments
Expand Down Expand Up @@ -106,6 +155,7 @@ $ pip install --editable .

- Secret name
- Secret value

1. Use it in your [GitHub Actions Workflows](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions)
- Snippet
```yml
Expand Down Expand Up @@ -141,23 +191,24 @@ View all available commands with `ghs --help`
```
Usage: ghs [OPTIONS] COMMAND [ARGS]...

All commands can run without providing options, and then you'll be
prompted to insert values.
All commands can run without providing options, and then you'll be
prompted to insert values.

Secrets' values and Personal-Access-Tokens are hidden when prompted
Secrets' values and Personal-Access-Tokens are hidden when prompted

Options:
--help Show this message and exit.
-ci, --ci Use this flag to avoid deletion confirmation prompts
--help Show this message and exit.

Commands:
init Create a credentials file to store your profiles
profile-apply Create or modify a profile
profile-delete Delete a profile
profile-list List all profile - truncates personal access tokens
secret-apply Create or modify a secret in a GitHub repository
secret-delete Delete a secret in a GitHub repository
secret-get Get a secret from a GitHub repository
secret-list List all secret in a GitHub repository
init Create a credentials file to store your profiles
profile-apply Create or modify multiple profiles providing a string...
profile-delete Delete multiple profiles providing a string delimited by...
profile-list List all profile - truncates personal access tokens
secret-apply Apply to multiple repositories providing a string...
secret-delete Delete secrets from multiple repositories providing a...
secret-get Get secrets from multiple repositories providing a string...
secret-list List secrets of multiple repositories providing a string...
```
## Contributing
Expand All @@ -167,10 +218,24 @@ Report issues/questions/feature requests on in the [Issues](https://github.com/u
Pull requests are welcome! Ideally, create a feature branch and issue for every single change you make. These are the steps:
1. Fork this repo
2. Create your feature branch from master (`git checkout -b my-new-feature`)
3. Commit your remarkable changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push --set-up-stream origin my-new-feature`)
5. Create a new Pull Request and tell us about your changes
1. Create your feature branch from master (`git checkout -b my-new-feature`)
1. Build from source and start coding!
```bash
$ git clone https://github.com/unfor19/githubsecrets.git && cd githubsecrets
...
$ pip install --upgrade pip
...
$ python -m venv ./ENV
...
$ . ./ENV/bin/activate
...
$ (ENV) pip install --editable .
...
# Done! Now when you run 'ghs' it will get automatically updated when you modify the code
```
1. Commit your remarkable changes (`git commit -am 'Added some feature'`)
1. Push to the branch (`git push --set-up-stream origin my-new-feature`)
1. Create a new Pull Request and tell us about your changes

## Authors

Expand Down
Binary file removed assets/github-secrets-usage.gif
Binary file not shown.
4 changes: 0 additions & 4 deletions deploy.sh

This file was deleted.

2 changes: 0 additions & 2 deletions pack.sh

This file was deleted.

17 changes: 17 additions & 0 deletions scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
import click
from cryptography.fernet import Fernet
import keyring
import os


def is_docker():
path = '/proc/self/cgroup'
return (
os.path.exists('/.dockerenv') or
os.path.isfile(path) and any('docker' in line for line in open(path))
)


def print_pretty_json(res):
click.echo(json.dumps(res, indent=4, sort_keys=True))


def list_by_comma(my_string):
return [item.strip() for item in my_string.split(",")]


def error_exit(msg):
Expand Down
67 changes: 48 additions & 19 deletions scripts/githubsecrets.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import click
from .config import pass_config, pass_validate, create_artifacts
from .config import pass_config, pass_validate, create_artifacts, list_by_comma, print_pretty_json, is_docker
from .profile import Profile
from .secret import Secret


@click.group()
@pass_config
@click.option('--ci', is_flag=True, help="Use this flag to avoid deletion confirmation prompts") # noqa: E501
@click.option('--ci', '-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
if is_docker():
ci = True
config.ci = ci # noqa: F821


Expand All @@ -33,9 +35,12 @@ def profile_apply(
config, validate,
profile_name, github_owner, personal_access_token
):
"""Create or modify a profile"""
"""Create or modify multiple profiles providing a string delimited by commas ","\n
Example: ghs profile-apply -p 'willy, oompa'"""
profile = Profile(config, profile_name)
profile.apply(github_owner, personal_access_token)
profiles = list_by_comma(profile_name)
for prof in profiles:
profile.apply(github_owner, personal_access_token)


@cli.command()
Expand All @@ -46,9 +51,12 @@ def profile_delete(
config, validate,
profile_name
):
"""Delete a profile"""
profile = Profile(config, profile_name)
profile.delete()
"""Delete multiple profiles providing a string delimited by commas ","\n
Example: ghs profile-delete -p 'willy, oompa'"""
profile_names = list_by_comma(profile_name)
for prof_name in profile_names:
profile = Profile(config, prof_name)
profile.delete()


@cli.command()
Expand All @@ -73,10 +81,16 @@ def secret_apply(
config, validate,
repository, profile_name, secret_name, secret_value
):
"""Create or modify a secret in a GitHub repository"""
"""Apply to multiple repositories providing a string delimited by commas ","\n
Example: ghs secret-apply -p willy -r 'githubsecrets, serverless-template'"""
profile = Profile(config, profile_name)
secret = Secret(config, profile, repository, secret_name, secret_value)
secret.apply()
repositories = list_by_comma(repository)
responses = []
for repo in repositories:
secret = Secret(config, profile, repo, secret_name, secret_value)
secret.apply()
responses.append(secret.apply())
print_pretty_json(responses)


@cli.command()
Expand All @@ -89,10 +103,15 @@ def secret_delete(
config, validate,
repository, profile_name, secret_name
):
"""Delete a secret in a GitHub repository"""
"""Delete secrets from multiple repositories providing a string delimited by commas ","\n
Example: ghs secret-delete -p willy -r 'githubsecrets, serverless-template'"""
profile = Profile(config, profile_name)
secret = Secret(config, profile, repository, secret_name)
secret.delete()
repositories = list_by_comma(repository)
responses = []
for repo in repositories:
secret = Secret(config, profile, repo, secret_name)
responses.append(secret.delete())
print_pretty_json(responses)


@cli.command()
Expand All @@ -105,10 +124,15 @@ def secret_get(
config, validate,
repository, profile_name, secret_name
):
"""Get a secret from a GitHub repository"""
"""Get secrets from multiple repositories providing a string delimited by commas ","\n
Example: ghs secret-get -p willy -r 'githubsecrets, serverless-template'"""
profile = Profile(config, profile_name)
secret = Secret(config, profile, repository, secret_name)
secret.get()
repositories = list_by_comma(repository)
responses = []
for repo in repositories:
secret = Secret(config, profile, repo, secret_name)
responses.append(secret.get())
print_pretty_json(responses)


@cli.command()
Expand All @@ -120,7 +144,12 @@ def secret_list(
config, validate,
repository, profile_name
):
"""List all secret in a GitHub repository"""
"""List secrets of multiple repositories providing a string delimited by commas ","\n
Example: ghs secret-delete -p willy -r 'githubsecrets, serverless-template'"""
profile = Profile(config, profile_name)
secret = Secret(config, profile, repository)
secret.lista()
repositories = list_by_comma(repository)
responses = []
for repo in repositories:
secret = Secret(config, profile, repo)
responses.append(secret.lista())
print_pretty_json(responses)
Loading

0 comments on commit e5c34de

Please sign in to comment.