Skip to content

Commit

Permalink
refactored JQ linter to script file
Browse files Browse the repository at this point in the history
  • Loading branch information
Long Le authored and Long Le committed Sep 13, 2024
1 parent dcb3ed5 commit 7ec5bcf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
36 changes: 36 additions & 0 deletions .github/scripts/validate_fields.sh
Original file line number Diff line number Diff line change
@@ -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
30 changes: 5 additions & 25 deletions .github/workflows/tyk-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7ec5bcf

Please sign in to comment.