|
1 | 1 | # programatically-create-delete-update-github-repository-secrets
|
2 | 2 | programatically-create-delete-update-github-repository-secrets
|
3 | 3 |
|
| 4 | +# Pre requesites |
| 5 | +* Personal Access Token (PAT) is the recommended way to authenticate. In this demo PAT is USED. |
| 6 | +* You can generate a new one from Github settings |
| 7 | +* You need to encrypt a secret before you can create or update secrets. |
| 8 | + |
| 9 | + |
| 10 | +# How code works for create or update a repository secret |
| 11 | + |
| 12 | +* First this will execute the `get_repository_public_key.py` `python program` to get the Organization public key and public key id |
| 13 | + * This public key is required and used for encryption of secret |
| 14 | + * This public key id is required at time of creation or updation of secret |
| 15 | + |
| 16 | + `Reference`: [get-a-repository-public-key](https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-a-repository-public-key) |
| 17 | + |
| 18 | + |
| 19 | +* Then the `python program` `encrypt_using_libnacl` this uses the public key from step 1 and encrypts the secret |
| 20 | +using the prefered method by GitHub. |
| 21 | + |
| 22 | + `Reference`: [create-or-update-a-repository-secret](https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-a-repository-secret) |
| 23 | + |
| 24 | + - Reference used for encryption : [example-encrypting-a-secret-using-python](https://docs.github.com/en/rest/guides/encrypting-secrets-for-the-rest-api?apiVersion=2022-11-28#example-encrypting-a-secret-using-python ) |
| 25 | + |
| 26 | +* Then `Python program` `create_or_update_repo_secret` is used to take the public key id from above step and encrypted secret value to create or update the secret. |
| 27 | + |
| 28 | +| status code | operation | |
| 29 | +|-------------|--------------------------| |
| 30 | +| 201 | Response when creating a repository secret | |
| 31 | +| 204 | Response when updating a secret repository secret | |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +## Inputs of workflow |
| 36 | + |
| 37 | +| input name | description| |
| 38 | +|------------|------------| |
| 39 | +| organization | name of github organization | |
| 40 | +| repository_name | name of github repo where secret need to be created | |
| 41 | +| secret_name | organization Secret name | |
| 42 | +| secret_value | Secret value | |
| 43 | + |
| 44 | + |
| 45 | +# # How code works for deleting an repository secret |
| 46 | + |
| 47 | +* This runs the `python program` `delete_repo_secret.py` which takes 3 inputs from github workflow |
| 48 | +1. organization name |
| 49 | +2. repository name |
| 50 | +3. secret name |
| 51 | + |
| 52 | +* Then deletes the secret |
| 53 | + |
| 54 | +| input | description| |
| 55 | +|-------|--------------| |
| 56 | +| organization | GitHub Organization name | |
| 57 | +| repository_name | name of github repo where secret need to be created | |
| 58 | +| secret_name | Secert to be deleted | |
0 commit comments