Skip to content

Commit ea95249

Browse files
committed
Script for adding secrets to jore4 repositories
add_secrets.py sets e-mail and password for our robot user as secrets to all jore4 repositories, so that they can be used in RF tests.
1 parent 36ab232 commit ea95249

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test_users.json

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Tools which are commonly used by other JORE4 projects
1111
- [Github Actions](#github-actions)
1212
- [extract-metadata](#extract-metadata)
1313
- [healthcheck](#healthcheck)
14+
- [Github scripts](#github-scripts)
15+
- [add_secrets.py](#add_secretspy)
1416

1517
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1618

@@ -95,3 +97,11 @@ steps:
9597
with:
9698
command: "curl --fail http://localhost:3200/actuator/health --output /dev/null --silent"
9799
```
100+
101+
## Github scripts
102+
103+
### add_secrets.py
104+
105+
Adds robot users hsl-id e-mail and password to all jore4 repositories.
106+
Uses file named `test_users.json` as input for user details. This file should be created by changing placeholder values in `tests_users_template.json` to correct passwords and e-mails.
107+
After the script is run the secrets can be found by going to repositorys `Settings` page in github and then selecting `Secrets` tab. There should be now secrets named `ROBOT_HSLID_EMAIL` and `ROBOT_HSLID_PASSWORD` and they should show that they have been updated when you ran the script.

github-scripts/add_secrets.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import subprocess
3+
import json
4+
5+
def get_list_of_jore4_repositories():
6+
response = subprocess.check_output("gh repo list HSLdevcom --topic jore4 --json nameWithOwner", shell=True)
7+
repositories_as_json = json.loads(response)
8+
repositories = []
9+
for repository in repositories_as_json:
10+
repositories.append(repository['nameWithOwner'])
11+
return repositories
12+
13+
def set_secret_for_repositories(list_of_repositories, secret_json):
14+
user_email = secret_json['email']
15+
user_password = secret_json['password']
16+
for repository in list_of_repositories:
17+
subprocess.check_output("gh secret set ROBOT_HSLID_EMAIL -b\"{}\" --repo {}".format(user_email, repository), shell=True)
18+
subprocess.check_output("gh secret set ROBOT_HSLID_PASSWORD -b\"{}\" --repo {}".format(user_password, repository), shell=True)
19+
print(repository)
20+
21+
repositories = get_list_of_jore4_repositories()
22+
secret_file = open('test_users.json',)
23+
secret_json = json.load(secret_file)
24+
set_secret_for_repositories(repositories, secret_json)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"email": "email@foruser.com",
3+
"password": "password"
4+
}

0 commit comments

Comments
 (0)