diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..541b300 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,67 @@ +name: Test module + +on: + workflow_dispatch: + pull_request: + branches: master + +jobs: + integration-test: + environment: test + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.x + + - name: Install Python dependencies + run: | + pip install ansible + pip install requests + python -m pip install --upgrade pip + pip list + + - name: Build + id: build + run: | + OUTPUT=$(ansible-galaxy collection build) + echo "$OUTPUT" + COLLECTION_PATH=$(echo "$OUTPUT" | grep -o '/[^ ]*\.tar\.gz') + echo "collection_path=$COLLECTION_PATH" >> $GITHUB_OUTPUT + echo "Collection path: $COLLECTION_PATH" + + - name: Install collection + run: ansible-galaxy collection install ${{ steps.build.outputs.collection_path }} --force + working-directory: tests/integration + + - name: Run get-vaults + run: ansible-playbook test_get_vault.yml + working-directory: tests/integration + env: + DVLS_APP_KEY: ${{ secrets.DVLS_APP_KEY }} + DVLS_APP_SECRET: ${{ secrets.DVLS_APP_SECRET }} + DVLS_SERVER_BASE_URL: ${{ secrets.DVLS_SERVER_BASE_URL }} + DVLS_VAULT_ID: ${{ secrets.DVLS_VAULT_ID }} + + - name: Run get-secrets + run: ansible-playbook test_get_secret.yml + working-directory: tests/integration + env: + DVLS_APP_KEY: ${{ secrets.DVLS_APP_KEY }} + DVLS_APP_SECRET: ${{ secrets.DVLS_APP_SECRET }} + DVLS_SERVER_BASE_URL: ${{ secrets.DVLS_SERVER_BASE_URL }} + DVLS_VAULT_ID: ${{ secrets.DVLS_VAULT_ID }} + + - name: Run create-secrets + run: ansible-playbook test_create_secret.yml + working-directory: tests/integration + env: + DVLS_APP_KEY: ${{ secrets.DVLS_APP_KEY }} + DVLS_APP_SECRET: ${{ secrets.DVLS_APP_SECRET }} + DVLS_SERVER_BASE_URL: ${{ secrets.DVLS_SERVER_BASE_URL }} + DVLS_VAULT_ID: ${{ secrets.DVLS_VAULT_ID }} diff --git a/tests/integration/secrets.yml b/tests/integration/secrets.yml new file mode 100644 index 0000000..69aabe3 --- /dev/null +++ b/tests/integration/secrets.yml @@ -0,0 +1,3 @@ +secrets: + - secret_name: "secret" + - secret_id: "890cbb54-7078-4d0c-925f-e89a33ee3e46" diff --git a/tests/integration/test_create_secret.yml b/tests/integration/test_create_secret.yml new file mode 100644 index 0000000..8c143c5 --- /dev/null +++ b/tests/integration/test_create_secret.yml @@ -0,0 +1,38 @@ +--- +- name: Fetch DVLS + hosts: localhost + tasks: + - name: Create secret using default value + devolutions.dvls.create_secret: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + secret: + secret_path: "Test-Ansible\\create-secrets" + secret_name: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}" + value: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}" + + - name: Create secret specifying value + devolutions.dvls.create_secret: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + secret: + secret_path: "Test-Ansible\\create-secrets" + secret_type: "Credential" + secret_subtype: "Default" + secret_name: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}" + value: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}" + + - name: Updating an already existing secret + devolutions.dvls.create_secret: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + secret: + secret_path: "Test-Ansible" + secret_name: "Default" + value: "{{ now(fmt='%Y-%m-%d_%H-%M-%S') }}" diff --git a/tests/integration/test_get_secret.yml b/tests/integration/test_get_secret.yml new file mode 100644 index 0000000..51ea538 --- /dev/null +++ b/tests/integration/test_get_secret.yml @@ -0,0 +1,65 @@ +--- +- name: Fetch DVLS + hosts: localhost + vars_files: + - secrets.yml + tasks: + - name: Fetch all secrets + devolutions.dvls.fetch_secrets: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + + - name: Fetch secrets using file + devolutions.dvls.fetch_secrets: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + secrets: "{{ secrets }}" + + - name: Get secret from ID + devolutions.dvls.fetch_secrets: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + secrets: + - secret_id: 08a6526d-1f86-40e2-aef1-a74cc31a548d + + - name: Get secret from name + devolutions.dvls.fetch_secrets: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + secrets: + - secret_name: AzureSP + + - name: Get secret from Folder + devolutions.dvls.fetch_secrets: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + secrets: + - secret_path: Test-Ansible + + - name: Get secret from Tag + devolutions.dvls.fetch_secrets: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + secrets: + - secret_tag: tag + + - name: Get secret from Type + devolutions.dvls.fetch_secrets: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + vault_id: "{{ lookup('env', 'DVLS_VAULT_ID') }}" + secrets: + - secret_type: Credential diff --git a/tests/integration/test_get_vault.yml b/tests/integration/test_get_vault.yml new file mode 100644 index 0000000..d9fc62f --- /dev/null +++ b/tests/integration/test_get_vault.yml @@ -0,0 +1,10 @@ +--- +- name: Fetch DVLS + hosts: localhost + tasks: + - name: Fetch dvls server + devolutions.dvls.fetch_server: + server_base_url: "{{ lookup('env', 'DVLS_SERVER_BASE_URL') }}" + app_key: "{{ lookup('env', 'DVLS_APP_KEY') }}" + app_secret: "{{ lookup('env', 'DVLS_APP_SECRET') }}" + register: server