diff --git a/.github/scripts/validate_fields.sh b/.github/scripts/validate_fields.sh new file mode 100644 index 0000000..f1358a3 --- /dev/null +++ b/.github/scripts/validate_fields.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Ensure the ENV environment variable is set +if [ -z "$DIRECTORY" ]; then + echo "Error: ENV environment variable is not set." + exit 1 +fi + +# Ensure the DIRECTORY environment variable is set +if [ -z "$DIRECTORY" ]; then + echo "Error: DIRECTORY environment variable is not set." + exit 1 +fi + +for file in $(find . -name "*.json" ! -name ".tyk.json"); do + # echo "Validating API/Policy definition $file" + # # Check if target_url is valid and not empty + # if jq -e '.proxy.target_url | length > 0' "$file" > /dev/null; then + # echo "$file contains a valid proxy.target_url." + # target_url=$(jq -r '.proxy.target_url' "$file") + # echo "proxy.target_url: $target_url" + # else + # echo "$file does NOT contain a valid proxy.target_url." + # exit 1 + # fi + + # Check if either JWT auth or or MutuatTLS is enabled + echo "Validating if the available authentication mechanisms are enabled" + if jq -e '.api_definition.enable_jwt == true or .api_definition.auth_configs.use_mutual_tls_auth == true' "$file" > /dev/null; then + echo "$file has either JWT auth or MutualTLS auth set to true." + else + echo "$file does NOT have either JWT auth or MutualTLS auth set to true." + exit 1 + fi + +done \ No newline at end of file diff --git a/.github/workflows/tyk-lint.yml b/.github/workflows/tyk-lint.yml index 5bbbc32..04d3b45 100644 --- a/.github/workflows/tyk-lint.yml +++ b/.github/workflows/tyk-lint.yml @@ -71,29 +71,9 @@ jobs: # Tyk API Linting / Validation using JQ Library - name: Lint / validate required auth mechanisms - env: - ENV: ${{ env.environment }} + env: + DIRECTORY: "./infrastructure/${{ env.environment }}/apis/" + ENV: ${{ env.environment }} run: | - cd "./$ENV" - for file in $(find . -name "*.json" ! -name ".tyk.json"); do - # echo "Validating API/Policy definition $file" - # # Check if target_url is valid and not empty - # if jq -e '.proxy.target_url | length > 0' "$file" > /dev/null; then - # echo "$file contains a valid proxy.target_url." - # target_url=$(jq -r '.proxy.target_url' "$file") - # echo "proxy.target_url: $target_url" - # else - # echo "$file does NOT contain a valid proxy.target_url." - # exit 1 - # fi - - # Check if either JWT auth or or MutuatTLS is enabled - echo "Validating if the appropriate authentication mechanisms are selected" - if jq -e '.api_definition.enable_jwt == true or .api_definition.auth_configs.use_mutual_tls_auth == true' "$file" > /dev/null; then - echo "$file has either enable_jwt or auth_configs.use_mutual_tls_auth set to true." - else - echo "$file does NOT have either enable_jwt or auth_configs.use_mutual_tls_auth set to true." - exit 1 - fi - - done + chmod +x ./.github/scripts/validate_fields.sh + ./.github/scripts/validate_fields.sh