|
1 | | -# .github/workflows/test-oidc-get.yml |
2 | 1 | name: Test OIDC GET Request |
3 | 2 |
|
4 | 3 | on: |
|
7 | 6 | - main |
8 | 7 |
|
9 | 8 | permissions: |
10 | | - id-token: write # enable OIDC token issuance |
11 | | - contents: read # allows checkout (not strictly needed here) |
| 9 | + id-token: write |
| 10 | + contents: read |
12 | 11 |
|
13 | 12 | jobs: |
14 | 13 | oidc-get: |
15 | 14 | runs-on: ubuntu-latest |
16 | 15 | env: |
17 | 16 | CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} |
18 | | - API_URL: https://sentinel-content-validationapi-prod-bvgsc3hjhyeqangg.canadacentral-01.azurewebsites.net/ # π replace with your GET endpoint |
19 | 17 |
|
20 | 18 | steps: |
21 | 19 | - name: π Request OIDC token from GitHub |
|
30 | 28 | echo "βοΈ Token length: ${#token}" |
31 | 29 | echo "TOKEN=$token" >> $GITHUB_ENV |
32 | 30 |
|
33 | | - - name: π‘ Send GET request with Bearer token |
| 31 | + - name: π‘ Send GET request to prod |
34 | 32 | run: | |
35 | | - echo "π Sending GET to $API_URL" |
36 | | - response=$(curl -s -H "Authorization: Bearer $TOKEN" "$API_URL") |
| 33 | + echo "π Sending GET to https://sentinel-content-validationapi-prod-bvgsc3hjhyeqangg.canadacentral-01.azurewebsites.net/" |
| 34 | +
|
| 35 | + # Check if TOKEN is set |
| 36 | + if [ -z "$TOKEN" ]; then |
| 37 | + echo "β TOKEN is not set. Make sure the OIDC token was fetched correctly." |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +
|
| 41 | + # Send the GET request and capture both response and HTTP status |
| 42 | + response=$(curl -s -w "\n%{http_code}" -H "Authorization: Bearer $TOKEN" "https://sentinel-content-validationapi-prod-bvgsc3hjhyeqangg.canadacentral-01.azurewebsites.net/") |
| 43 | + |
| 44 | + # Split response and status |
| 45 | + http_body=$(echo "$response" | sed '$d') |
| 46 | + http_status=$(echo "$response" | tail -n1) |
| 47 | +
|
| 48 | + echo "π HTTP Status: $http_status" |
| 49 | + echo "π Raw Response:" |
| 50 | + echo "$http_body" |
| 51 | +
|
| 52 | + # Check if the response is valid JSON |
| 53 | + if echo "$http_body" | jq . > /dev/null 2>&1; then |
| 54 | + echo "βοΈ Parsed JSON:" |
| 55 | + echo "$http_body" | jq . |
| 56 | + else |
| 57 | + echo "β οΈ Response is not valid JSON or is empty." |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | +
|
| 61 | + # Fail the step if the HTTP status is not 2xx |
| 62 | + if [[ "$http_status" != 2* ]]; then |
| 63 | + echo "β Request failed with status $http_status" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + - name: π‘ Send GET request too prod |
| 68 | + run: | |
| 69 | + echo "π Sending GET to prod" |
| 70 | + response=$(curl -s -H "Authorization: Bearer $TOKEN" "https://sentinel-content-validationapi-prod-bvgsc3hjhyeqangg.canadacentral-01.azurewebsites.net/") |
| 71 | + echo "π Response JSON:" |
| 72 | + echo "$response" | jq . |
| 73 | + |
| 74 | +
|
| 75 | +
|
| 76 | + - name: π‘ Send GET request too dev |
| 77 | + run: | |
| 78 | + echo "π Sending GET to dev" |
| 79 | + response=$(curl -s -H "Authorization: Bearer $TOKEN" "https://sentintel-content-dev-fue4ashcg9fnfge9.canadacentral-01.azurewebsites.net/") |
37 | 80 | echo "π Response JSON:" |
38 | 81 | echo "$response" | jq . |
| 82 | + |
0 commit comments