5
0
Fork 0
mirror of https://github.com/hashicorp/vault-action.git synced 2025-11-09 16:16:55 +00:00

add more comments and docs

This commit is contained in:
JM Faircloth 2023-06-20 11:14:41 -05:00
parent 10ed4392a6
commit c3509cc095
5 changed files with 24 additions and 23 deletions

View file

@ -160,12 +160,9 @@ jobs:
url: http://localhost:8200 url: http://localhost:8200
token: testtoken token: testtoken
secrets: | secrets: |
secret/data/test-json-string jsonString ;
secret/data/test-json-string jsonString | JSON_STRING ; secret/data/test-json-string jsonString | JSON_STRING ;
- name: Test Vault Action (verify JSON string format)
run: | run: |
echo "${{ steps.import-secrets.outputs.jsonString }}" > secrets.json echo "${{ env.JSON_STRING }}" > secrets.json
cat secrets.json cat secrets.json
# we should be able to parse the output as JSON # we should be able to parse the output as JSON
jq -c . < secrets.json jq -c . < secrets.json

View file

@ -38,7 +38,9 @@ jobs:
- name: Import Secrets - name: Import Secrets
id: import-secrets id: import-secrets
# use the local changes
uses: ./ uses: ./
# run against a specific version of vault-action
# uses: hashicorp/vault-action@v2.1.2 # uses: hashicorp/vault-action@v2.1.2
with: with:
url: http://localhost:8200 url: http://localhost:8200
@ -52,7 +54,7 @@ jobs:
touch secrets.json touch secrets.json
echo "${{ steps.import-secrets.outputs.jsonString }}" >> secrets.json echo "${{ steps.import-secrets.outputs.jsonString }}" >> secrets.json
- name: Check json file - name: Check json file format
run: | run: |
echo echo
cat secrets.json cat secrets.json

View file

@ -1,3 +1,3 @@
.PHONY: local-test .PHONY: local-test
local-test: local-test:
docker compose down && docker-compose up -d vault && act workflow_dispatch -j local-test docker compose down; docker-compose up -d vault && act workflow_dispatch -j local-test

View file

@ -547,24 +547,22 @@ $ npm run test:integration:basic # Choose one of: basic, enterprise, e2e, e2e-tl
### Running the action locally ### Running the action locally
You can use the [act](https://github.com/nektos/act) command to test your You can use the [act](https://github.com/nektos/act) command to test your
changes locally if desired. Unfortunately it is not currently possible to use changes locally.
uncommitted local changes for a shared workfow. You will still need to push the
changes you would like to validate beforehand. Even if a commit is necessary,
this is still a more detailed and faster feedback loop than waiting for the
action to be executed by Github in a different repository.
Push your changes into a feature branch. Edit the ./.github/workflows/local-test.yaml file and add any steps necessary
```sh to test your changes. You may have to additionally edit the Vault url, token
$ git checkout -b my-feature-branch and secret path if you are not using one of the provided containerized
$ git commit -m "testing new changes" instances. The `local-test` job will call the ./integrationTests/e2e/setup.js
$ git push script to bootstrap your local Vault instance with secrets.
```
Edit the ./.github/workflows/local-test.yaml file to use your new feature Run your feature branch locally:
branch. You may have to additionally edit the vault url, token and secret path
if you are not using one of the provided containerized instance. Run your
feature branch locally.
```sh ```sh
$ act workflow_dispatch -j local-test act workflow_dispatch -j local-test
```
Or use the provided make target which will also spin up a Vault container:
```sh
make local-test
``` ```

View file

@ -75,7 +75,7 @@ async function selectData(data, selector) {
if (isJSON(d)) { if (isJSON(d)) {
// If we already have JSON we will not "stringify" it yet so that we // If we already have JSON we will not "stringify" it yet so that we
// don't end up calling JSON.parse. This would break the secrets that // don't end up calling JSON.parse. This would break the secrets that
// are stored as json. See: https://github.com/hashicorp/vault-action/issues/194 // are stored as JSON. See: https://github.com/hashicorp/vault-action/issues/194
result = d; result = d;
} else { } else {
result = JSON.stringify(d); result = JSON.stringify(d);
@ -106,6 +106,10 @@ async function selectData(data, selector) {
return result; return result;
} }
/**
* isJSON returns true if str parses as valid JSON
* @param {string} str
*/
function isJSON(str) { function isJSON(str) {
if (typeof str !== "string"){ if (typeof str !== "string"){
return false; return false;