Skip to content

Commit e5c34de

Browse files
authored
Merge pull request #7 from unfor19/release-1.0.4
Release 1.0.4
2 parents a3a283e + de28658 commit e5c34de

10 files changed

Lines changed: 181 additions & 73 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM python:3.6.7-slim
22
WORKDIR /code
3-
RUN pip install --upgrade pip && pip install keyrings.alt && pip install githubsecrets
3+
COPY . .
4+
RUN pip install --upgrade pip && pip install keyrings.alt && pip install --editable .
45
ENTRYPOINT [ "ghs" ]

Dockerfile.dev

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM python:3.6.7-slim
22
WORKDIR /code
3-
COPY . /code/
4-
RUN python -m pip install --upgrade pip && pip install keyrings.alt && pip install --editable .
5-
ENTRYPOINT [ "ghs" ]
3+
COPY . .
4+
RUN pip install --upgrade pip && pip install keyrings.alt && pip install --editable .
5+
ENTRYPOINT [ "bash" ]

README.md

Lines changed: 98 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,85 @@ The image runs as a CLI; you must provide arguments, prompts are not available w
3636

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

39+
**IMPORTANT**: You must create the directory before mounting it, unless it's your home directory. The path must be absolute.
40+
3941
```bash
40-
$ docker run -v $HOME:/root unfor19/githubsecrets --help
41-
Usage: ghs [OPTIONS] COMMAND [ARGS]...
42-
...
42+
$ docker run --rm --mount type=bind,source="$HOME",target=/root unfor19/githubsecrets --ci secret-list -p unfor19 -r githubsecrets
43+
... # Output below
4344
```
4445

46+
<details><summary>Output
47+
</summary>
48+
49+
```json
50+
[
51+
{
52+
"base_url": "https://api.github.com/repos/unfor19/githubsecrets",
53+
"body": {
54+
"secrets": [
55+
{
56+
"created_at": "2020-04-11T00:01:12Z",
57+
"name": "PIP_PASSWORD",
58+
"updated_at": "2020-04-11T00:17:39Z"
59+
},
60+
{
61+
"created_at": "2020-04-10T23:21:28Z",
62+
"name": "PIP_USERNAME",
63+
"updated_at": "2020-04-11T00:17:20Z"
64+
},
65+
{
66+
"created_at": "2020-04-27T20:44:09Z",
67+
"name": "testing",
68+
"updated_at": "2020-04-27T20:45:43Z"
69+
},
70+
{
71+
"created_at": "2020-04-27T20:22:37Z",
72+
"name": "testrepos",
73+
"updated_at": "2020-04-27T20:22:37Z"
74+
},
75+
{
76+
"created_at": "2020-04-14T14:14:44Z",
77+
"name": "TEST_GITHUB_TOKEN",
78+
"updated_at": "2020-04-14T14:14:44Z"
79+
}
80+
],
81+
"total_count": 5
82+
},
83+
"repository": "githubsecrets",
84+
"status_code": 200
85+
}
86+
]
87+
```
88+
89+
</details>
90+
4591
#### Windows
4692

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

95+
**IMPORTANT**: You must create the directory before mounting it, unless it's your Temp directory. The path must be absolute.
96+
4997
```
50-
$ docker run --rm -v c:/Temp:/root unfor19/githubsecrets --help
51-
Usage: ghs [OPTIONS] COMMAND [ARGS]...
52-
...
98+
$ docker run --rm -v c:/Temp:/root unfor19/githubsecrets --ci secret-delete -p unfor19 -r githubsecrets -s testrepos
99+
... # Output below
53100
```
54101

55-
### Build from source
102+
<details><summary>Output
103+
</summary>
56104

57-
```bash
58-
$ git clone https://github.com/unfor19/githubsecrets.git && cd githubsecrets
59-
...
60-
$ pip install --upgrade pip
61-
...
62-
$ pip install -r requirements.txt
63-
...
64-
$ pip install --editable .
65-
...
66-
# Done!
105+
```json
106+
[
107+
{
108+
"base_url": "https://api.github.com/repos/unfor19/githubsecrets",
109+
"repository": "githubsecrets",
110+
"secret_name": "testrepos",
111+
"status_code": 204
112+
}
113+
]
67114
```
68115

116+
</details>
117+
69118
## Getting Started
70119

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

107156
- Secret name
108157
- Secret value
158+
109159
1. Use it in your [GitHub Actions Workflows](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions)
110160
- Snippet
111161
```yml
@@ -141,23 +191,24 @@ View all available commands with `ghs --help`
141191
```
142192
Usage: ghs [OPTIONS] COMMAND [ARGS]...
143193

144-
All commands can run without providing options, and then you'll be
145-
prompted to insert values.
194+
All commands can run without providing options, and then you'll be
195+
prompted to insert values.
146196

147-
Secrets' values and Personal-Access-Tokens are hidden when prompted
197+
Secrets' values and Personal-Access-Tokens are hidden when prompted
148198

149199
Options:
150-
--help Show this message and exit.
200+
-ci, --ci Use this flag to avoid deletion confirmation prompts
201+
--help Show this message and exit.
151202

152203
Commands:
153-
init Create a credentials file to store your profiles
154-
profile-apply Create or modify a profile
155-
profile-delete Delete a profile
156-
profile-list List all profile - truncates personal access tokens
157-
secret-apply Create or modify a secret in a GitHub repository
158-
secret-delete Delete a secret in a GitHub repository
159-
secret-get Get a secret from a GitHub repository
160-
secret-list List all secret in a GitHub repository
204+
init Create a credentials file to store your profiles
205+
profile-apply Create or modify multiple profiles providing a string...
206+
profile-delete Delete multiple profiles providing a string delimited by...
207+
profile-list List all profile - truncates personal access tokens
208+
secret-apply Apply to multiple repositories providing a string...
209+
secret-delete Delete secrets from multiple repositories providing a...
210+
secret-get Get secrets from multiple repositories providing a string...
211+
secret-list List secrets of multiple repositories providing a string...
161212
```
162213
163214
## Contributing
@@ -167,10 +218,24 @@ Report issues/questions/feature requests on in the [Issues](https://github.com/u
167218
Pull requests are welcome! Ideally, create a feature branch and issue for every single change you make. These are the steps:
168219
169220
1. Fork this repo
170-
2. Create your feature branch from master (`git checkout -b my-new-feature`)
171-
3. Commit your remarkable changes (`git commit -am 'Added some feature'`)
172-
4. Push to the branch (`git push --set-up-stream origin my-new-feature`)
173-
5. Create a new Pull Request and tell us about your changes
221+
1. Create your feature branch from master (`git checkout -b my-new-feature`)
222+
1. Build from source and start coding!
223+
```bash
224+
$ git clone https://github.com/unfor19/githubsecrets.git && cd githubsecrets
225+
...
226+
$ pip install --upgrade pip
227+
...
228+
$ python -m venv ./ENV
229+
...
230+
$ . ./ENV/bin/activate
231+
...
232+
$ (ENV) pip install --editable .
233+
...
234+
# Done! Now when you run 'ghs' it will get automatically updated when you modify the code
235+
```
236+
1. Commit your remarkable changes (`git commit -am 'Added some feature'`)
237+
1. Push to the branch (`git push --set-up-stream origin my-new-feature`)
238+
1. Create a new Pull Request and tell us about your changes
174239

175240
## Authors
176241

assets/github-secrets-usage.gif

-863 KB
Binary file not shown.

deploy.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

pack.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

scripts/config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
import click
55
from cryptography.fernet import Fernet
66
import keyring
7+
import os
8+
9+
10+
def is_docker():
11+
path = '/proc/self/cgroup'
12+
return (
13+
os.path.exists('/.dockerenv') or
14+
os.path.isfile(path) and any('docker' in line for line in open(path))
15+
)
16+
17+
18+
def print_pretty_json(res):
19+
click.echo(json.dumps(res, indent=4, sort_keys=True))
20+
21+
22+
def list_by_comma(my_string):
23+
return [item.strip() for item in my_string.split(",")]
724

825

926
def error_exit(msg):

scripts/githubsecrets.py

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import click
2-
from .config import pass_config, pass_validate, create_artifacts
2+
from .config import pass_config, pass_validate, create_artifacts, list_by_comma, print_pretty_json, is_docker
33
from .profile import Profile
44
from .secret import Secret
55

66

77
@click.group()
88
@pass_config
9-
@click.option('--ci', is_flag=True, help="Use this flag to avoid deletion confirmation prompts") # noqa: E501
9+
@click.option('--ci', '-ci', is_flag=True, help="Use this flag to avoid deletion confirmation prompts") # noqa: E501
1010
def cli(config, ci):
1111
"""All commands can run without providing options, and then you'll be prompted to insert values.\n
1212
Secrets' values and Personal-Access-Tokens are hidden when prompted""" # noqa: E501
13+
if is_docker():
14+
ci = True
1315
config.ci = ci # noqa: F821
1416

1517

@@ -33,9 +35,12 @@ def profile_apply(
3335
config, validate,
3436
profile_name, github_owner, personal_access_token
3537
):
36-
"""Create or modify a profile"""
38+
"""Create or modify multiple profiles providing a string delimited by commas ","\n
39+
Example: ghs profile-apply -p 'willy, oompa'"""
3740
profile = Profile(config, profile_name)
38-
profile.apply(github_owner, personal_access_token)
41+
profiles = list_by_comma(profile_name)
42+
for prof in profiles:
43+
profile.apply(github_owner, personal_access_token)
3944

4045

4146
@cli.command()
@@ -46,9 +51,12 @@ def profile_delete(
4651
config, validate,
4752
profile_name
4853
):
49-
"""Delete a profile"""
50-
profile = Profile(config, profile_name)
51-
profile.delete()
54+
"""Delete multiple profiles providing a string delimited by commas ","\n
55+
Example: ghs profile-delete -p 'willy, oompa'"""
56+
profile_names = list_by_comma(profile_name)
57+
for prof_name in profile_names:
58+
profile = Profile(config, prof_name)
59+
profile.delete()
5260

5361

5462
@cli.command()
@@ -73,10 +81,16 @@ def secret_apply(
7381
config, validate,
7482
repository, profile_name, secret_name, secret_value
7583
):
76-
"""Create or modify a secret in a GitHub repository"""
84+
"""Apply to multiple repositories providing a string delimited by commas ","\n
85+
Example: ghs secret-apply -p willy -r 'githubsecrets, serverless-template'"""
7786
profile = Profile(config, profile_name)
78-
secret = Secret(config, profile, repository, secret_name, secret_value)
79-
secret.apply()
87+
repositories = list_by_comma(repository)
88+
responses = []
89+
for repo in repositories:
90+
secret = Secret(config, profile, repo, secret_name, secret_value)
91+
secret.apply()
92+
responses.append(secret.apply())
93+
print_pretty_json(responses)
8094

8195

8296
@cli.command()
@@ -89,10 +103,15 @@ def secret_delete(
89103
config, validate,
90104
repository, profile_name, secret_name
91105
):
92-
"""Delete a secret in a GitHub repository"""
106+
"""Delete secrets from multiple repositories providing a string delimited by commas ","\n
107+
Example: ghs secret-delete -p willy -r 'githubsecrets, serverless-template'"""
93108
profile = Profile(config, profile_name)
94-
secret = Secret(config, profile, repository, secret_name)
95-
secret.delete()
109+
repositories = list_by_comma(repository)
110+
responses = []
111+
for repo in repositories:
112+
secret = Secret(config, profile, repo, secret_name)
113+
responses.append(secret.delete())
114+
print_pretty_json(responses)
96115

97116

98117
@cli.command()
@@ -105,10 +124,15 @@ def secret_get(
105124
config, validate,
106125
repository, profile_name, secret_name
107126
):
108-
"""Get a secret from a GitHub repository"""
127+
"""Get secrets from multiple repositories providing a string delimited by commas ","\n
128+
Example: ghs secret-get -p willy -r 'githubsecrets, serverless-template'"""
109129
profile = Profile(config, profile_name)
110-
secret = Secret(config, profile, repository, secret_name)
111-
secret.get()
130+
repositories = list_by_comma(repository)
131+
responses = []
132+
for repo in repositories:
133+
secret = Secret(config, profile, repo, secret_name)
134+
responses.append(secret.get())
135+
print_pretty_json(responses)
112136

113137

114138
@cli.command()
@@ -120,7 +144,12 @@ def secret_list(
120144
config, validate,
121145
repository, profile_name
122146
):
123-
"""List all secret in a GitHub repository"""
147+
"""List secrets of multiple repositories providing a string delimited by commas ","\n
148+
Example: ghs secret-delete -p willy -r 'githubsecrets, serverless-template'"""
124149
profile = Profile(config, profile_name)
125-
secret = Secret(config, profile, repository)
126-
secret.lista()
150+
repositories = list_by_comma(repository)
151+
responses = []
152+
for repo in repositories:
153+
secret = Secret(config, profile, repo)
154+
responses.append(secret.lista())
155+
print_pretty_json(responses)

0 commit comments

Comments
 (0)