From 345b181124c7096a6bf42dbbd14e5f61cccae8ae Mon Sep 17 00:00:00 2001 From: Maksim Ustinov Date: Fri, 1 Apr 2022 14:31:01 -0700 Subject: [PATCH] New HashiCorp Vault Plugin releaser using GitHub Actions. (#248) Release will be triggered when a new tag `vault-plugin-secrets-ksm/v*` is created in the repository --- .../publish.hashicorpvault.plugin.yml | 61 +++++++++++++++++++ integration/vault-plugin-secrets-ksm/.VERSION | 1 - integration/vault-plugin-secrets-ksm/Makefile | 29 +++++---- .../core/keeper_secrets_manager_core/core.py | 9 +-- 4 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/publish.hashicorpvault.plugin.yml delete mode 100644 integration/vault-plugin-secrets-ksm/.VERSION diff --git a/.github/workflows/publish.hashicorpvault.plugin.yml b/.github/workflows/publish.hashicorpvault.plugin.yml new file mode 100644 index 00000000..52f1da88 --- /dev/null +++ b/.github/workflows/publish.hashicorpvault.plugin.yml @@ -0,0 +1,61 @@ +name: Release HV Plugin + +on: + workflow_dispatch: + push: + tags: + - 'vault-plugin-secrets-ksm/v*' + +jobs: + release-hv-plugin: + environment: prod + runs-on: ubuntu-latest + + defaults: + run: + working-directory: integration/vault-plugin-secrets-ksm + + steps: + + - name: Checkout + uses: actions/checkout@v3.0.0 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + # Cache GoLang libs + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Create binaries + run: | # initially `github.ref` == "ref/tags/vault-plugin-secrets-ksm/vX.Y.Z" + PLUGIN_NAME="$(cut -d'/' -f3 <<<${{ github.ref }})" + PLUGIN_VERSION=${"$(cut -d'/' -f4 <<<${{ github.ref }})":1} + + echo "Plugin name: [${PLUGIN_NAME}]" + echo "Plugin version: [${PLUGIN_VERSION}]" + make release-all PLUGIN_NAME="${PLUGIN_NAME}" PLUGIN_VERSION="${PLUGIN_VERSION}" + + - name: "Info: List created files" + run: | + pwd + ls -la + + # Publish binaries + - name: Release Binaries + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: integration/vault-plugin-secrets-ksm/vault-plugin-secrets-ksm* + tag: ${{ github.ref }} + overwrite: true + file_glob: true + body: "KSM Hashicorp Vault Secrets Plugin ${{ github.ref }}" diff --git a/integration/vault-plugin-secrets-ksm/.VERSION b/integration/vault-plugin-secrets-ksm/.VERSION deleted file mode 100644 index 992977ad..00000000 --- a/integration/vault-plugin-secrets-ksm/.VERSION +++ /dev/null @@ -1 +0,0 @@ -v1.1.0 \ No newline at end of file diff --git a/integration/vault-plugin-secrets-ksm/Makefile b/integration/vault-plugin-secrets-ksm/Makefile index 698ea6de..2beaee4c 100644 --- a/integration/vault-plugin-secrets-ksm/Makefile +++ b/integration/vault-plugin-secrets-ksm/Makefile @@ -1,6 +1,5 @@ -PLUGIN_NAME = vault-plugin-secrets-ksm -versionFile = $(CURDIR)/.VERSION -VERSION := $(shell cat $(versionFile) | sed 's/^v//') +PLUGIN_NAME = $(PLUGIN_NAME) +PLUGIN_VERSION = $(PLUGIN_VERSION) all: fmt build @@ -20,15 +19,15 @@ release: go build; zip -m ${PLUGIN_NAME}.zip ${PLUGIN_NAME} ${PLUGIN_NAME}.exe release-all: - $(eval GOOS=darwin) $(eval GOARCH=amd64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} - $(eval GOOS=darwin) $(eval GOARCH=arm64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} - $(eval GOOS=freebsd) $(eval GOARCH=386) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} - $(eval GOOS=freebsd) $(eval GOARCH=amd64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} - $(eval GOOS=freebsd) $(eval GOARCH=arm) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} - $(eval GOOS=linux) $(eval GOARCH=386) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} - $(eval GOOS=linux) $(eval GOARCH=amd64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} - $(eval GOOS=linux) $(eval GOARCH=arm) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} - $(eval GOOS=linux) $(eval GOARCH=arm64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} - $(eval GOOS=windows) $(eval GOARCH=386) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME}.exe - $(eval GOOS=windows) $(eval GOARCH=amd64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME}.exe - sha256sum ${PLUGIN_NAME}_${VERSION}_*.zip > ${PLUGIN_NAME}_${VERSION}_SHA256SUMS + $(eval GOOS=darwin) $(eval GOARCH=amd64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} + $(eval GOOS=darwin) $(eval GOARCH=arm64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} + $(eval GOOS=freebsd) $(eval GOARCH=386) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} + $(eval GOOS=freebsd) $(eval GOARCH=amd64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} + $(eval GOOS=freebsd) $(eval GOARCH=arm) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} + $(eval GOOS=linux) $(eval GOARCH=386) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} + $(eval GOOS=linux) $(eval GOARCH=amd64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} + $(eval GOOS=linux) $(eval GOARCH=arm) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} + $(eval GOOS=linux) $(eval GOARCH=arm64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME} + $(eval GOOS=windows) $(eval GOARCH=386) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME}.exe + $(eval GOOS=windows) $(eval GOARCH=amd64) GOOS=${GOOS} GOARCH=${GOARCH} go build ; zip -m ${PLUGIN_NAME}_${PLUGIN_VERSION}_${GOOS}_${GOARCH}.zip ${PLUGIN_NAME}.exe + sha256sum ${PLUGIN_NAME}_${PLUGIN_VERSION}_*.zip > ${PLUGIN_NAME}_${PLUGIN_VERSION}_SHA256SUMS diff --git a/sdk/python/core/keeper_secrets_manager_core/core.py b/sdk/python/core/keeper_secrets_manager_core/core.py index 5be258c0..1747d43b 100644 --- a/sdk/python/core/keeper_secrets_manager_core/core.py +++ b/sdk/python/core/keeper_secrets_manager_core/core.py @@ -619,11 +619,11 @@ def get_notation(self, url): Example: - RECORD_UID/field/password => MyPasswprd + RECORD_UID/field/password => MyPassword RECORD_UID/field/password[0] => MyPassword RECORD_UID/field/password[] => ["MyPassword"] RECORD_UID/custom_field/name[first] => John - RECORD_UID/custom_field/name[last] => Smitht + RECORD_UID/custom_field/name[last] => Smith RECORD_UID/custom_field/phone[0][number] => "555-5555555" RECORD_UID/custom_field/phone[1][number] => "777-7777777" RECORD_UID/custom_field/phone[] => [{"number": "555-555...}, { "number": "777.....}] @@ -640,7 +640,8 @@ def get_notation(self, url): # Get the except below handle it raise ValueError() except IndexError: - raise ValueError("Keeper url missing information about the uid, field type, and field key.") + raise ValueError("Keeper url [{}] missing information about the uid, field type, and field key." + .format(url)) try: (uid, file_data_type, key) = url.split('/') @@ -654,7 +655,7 @@ def get_notation(self, url): if key is None: raise ValueError("file key is missing the in the keeper url.") - # By default we want to return a single value, which is the first item in the array + # By default, we want to return a single value, which is the first item in the array return_single = True index = 0 dict_key = None