Skip to content

Commit 4d905dc

Browse files
token checking of prod
1 parent 8f867a7 commit 4d905dc

File tree

3 files changed

+228
-225
lines changed

3 files changed

+228
-225
lines changed

.github/workflows/auth.yml

Lines changed: 108 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,117 @@
11

2-
name: PR Validation for Polling file
3-
4-
on:
5-
pull_request_target:
6-
types: [opened, synchronize]
7-
8-
permissions:
9-
id-token: write
10-
contents: read
11-
12-
env:
13-
CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
14-
API_BASE: ${{ secrets.SENTINEL_CONTENT_API_URL }}
15-
16-
jobs:
17-
pr-validate:
18-
runs-on: ubuntu-latest
19-
20-
steps:
21-
- name: Checkout PR code
22-
uses: actions/checkout@v3
23-
with:
24-
fetch-depth: 0
25-
ref: ${{ github.event.pull_request.head.ref }}
26-
repository: ${{ github.event.pull_request.head.repo.full_name }}
27-
28-
29-
30-
- name: Get changed JSON files and contents to send to API endpoint
31-
id: prepare_json_files
32-
run: |
33-
echo "Collecting changed JSON files..."
34-
BASE="${{ github.event.pull_request.base.sha }}"
35-
HEAD="${{ github.event.pull_request.head.sha }}"
36-
37-
mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep '\.json$')
38-
echo "Changed JSON files: ${files[@]}"
39-
40-
filtered_files=()
41-
for file in "${files[@]}"; do
42-
if [[ "$file" =~ [Pp][Oo][Ll][Ll] ]]; then
43-
filtered_files+=("$file")
44-
fi
45-
done
46-
47-
echo "Changed JSON files within the scope of this workflow (Polling files): ${filtered_files[@]}"
48-
49-
if [ ${#filtered_files[@]} -eq 0 ]; then
50-
echo "No JSON files with 'poll' in the name changed in this PR."
51-
echo "JSON_PAYLOAD_PATH=empty" >> $GITHUB_ENV
52-
exit 0
53-
fi
54-
55-
json_array="["
56-
for file in "${filtered_files[@]}"; do
57-
if [ -f "$file" ]; then
58-
if jq -e . "$file" > /dev/null 2>&1; then
59-
content=$(jq -c . < "$file")
60-
json_array+="{\"filename\": \"${file}\", \"content\": $content},"
61-
else
62-
echo "❌ Invalid JSON structure in file: $file"
63-
exit 1
64-
fi
65-
fi
66-
done
67-
json_array="${json_array%,}]"
68-
echo "$json_array" > files_payload.json
69-
echo "JSON_PAYLOAD_PATH=files_payload.json" >> $GITHUB_ENV
70-
71-
72-
- name: Request OIDC token from GitHub
73-
if: env.JSON_PAYLOAD_PATH != 'empty'
74-
id: fetch_token
75-
run: |
76-
echo "Requesting OIDC token"
77-
raw=$(curl -s \
78-
-H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
79-
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=api://${CLIENT_ID}")
80-
echo "🔁 Raw token response JSON: $raw"
81-
token=$(echo "$raw" | jq -r '.value')
82-
echo "✔️ Token length: ${#token}"
83-
echo "TOKEN=$token" >> $GITHUB_ENV
84-
85-
# 3. Send a simple GET request to "/"
86-
- name: Send GET request to check if API is live
87-
if: env.JSON_PAYLOAD_PATH != 'empty'
88-
run: |
2+
# name: PR Validation for Polling file
3+
4+
# on:
5+
# pull_request_target:
6+
# types: [opened, synchronize]
7+
8+
# permissions:
9+
# id-token: write
10+
# contents: read
11+
12+
# env:
13+
# CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
14+
# API_BASE: ${{ secrets.SENTINEL_CONTENT_API_URL }}
15+
16+
# jobs:
17+
# pr-validate:
18+
# runs-on: ubuntu-latest
19+
20+
# steps:
21+
# - name: Checkout PR code
22+
# uses: actions/checkout@v3
23+
# with:
24+
# fetch-depth: 0
25+
# ref: ${{ github.event.pull_request.head.ref }}
26+
# repository: ${{ github.event.pull_request.head.repo.full_name }}
27+
28+
29+
30+
# - name: Get changed JSON files and contents to send to API endpoint
31+
# id: prepare_json_files
32+
# run: |
33+
# echo "Collecting changed JSON files..."
34+
# BASE="${{ github.event.pull_request.base.sha }}"
35+
# HEAD="${{ github.event.pull_request.head.sha }}"
36+
37+
# mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep '\.json$')
38+
# echo "Changed JSON files: ${files[@]}"
39+
40+
# filtered_files=()
41+
# for file in "${files[@]}"; do
42+
# if [[ "$file" =~ [Pp][Oo][Ll][Ll] ]]; then
43+
# filtered_files+=("$file")
44+
# fi
45+
# done
46+
47+
# echo "Changed JSON files within the scope of this workflow (Polling files): ${filtered_files[@]}"
48+
49+
# if [ ${#filtered_files[@]} -eq 0 ]; then
50+
# echo "No JSON files with 'poll' in the name changed in this PR."
51+
# echo "JSON_PAYLOAD_PATH=empty" >> $GITHUB_ENV
52+
# exit 0
53+
# fi
54+
55+
# json_array="["
56+
# for file in "${filtered_files[@]}"; do
57+
# if [ -f "$file" ]; then
58+
# if jq -e . "$file" > /dev/null 2>&1; then
59+
# content=$(jq -c . < "$file")
60+
# json_array+="{\"filename\": \"${file}\", \"content\": $content},"
61+
# else
62+
# echo "❌ Invalid JSON structure in file: $file"
63+
# exit 1
64+
# fi
65+
# fi
66+
# done
67+
# json_array="${json_array%,}]"
68+
# echo "$json_array" > files_payload.json
69+
# echo "JSON_PAYLOAD_PATH=files_payload.json" >> $GITHUB_ENV
70+
71+
72+
# - name: Request OIDC token from GitHub
73+
# if: env.JSON_PAYLOAD_PATH != 'empty'
74+
# id: fetch_token
75+
# run: |
76+
# echo "Requesting OIDC token"
77+
# raw=$(curl -s \
78+
# -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
79+
# "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=api://${CLIENT_ID}")
80+
# echo "🔁 Raw token response JSON: $raw"
81+
# token=$(echo "$raw" | jq -r '.value')
82+
# echo "✔️ Token length: ${#token}"
83+
# echo "TOKEN=$token" >> $GITHUB_ENV
84+
85+
# # 3. Send a simple GET request to "/"
86+
# - name: Send GET request to check if API is live
87+
# if: env.JSON_PAYLOAD_PATH != 'empty'
88+
# run: |
8989

90-
echo " GET request"
91-
response=$(curl -s -H "Authorization: Bearer $TOKEN" "$API_BASE/")
92-
echo " GET response:"
93-
echo "$response" | jq . || true
90+
# echo " GET request"
91+
# response=$(curl -s -H "Authorization: Bearer $TOKEN" "$API_BASE/")
92+
# echo " GET response:"
93+
# echo "$response" | jq . || true
9494

9595

96-
# 5. Send POST request with JSON payload to "/"
97-
- name: Send POST request with JSON payload
98-
if: env.JSON_PAYLOAD_PATH != 'empty'
99-
run: |
100-
echo "Sending JSON payload to API"
96+
# # 5. Send POST request with JSON payload to "/"
97+
# - name: Send POST request with JSON payload
98+
# if: env.JSON_PAYLOAD_PATH != 'empty'
99+
# run: |
100+
# echo "Sending JSON payload to API"
101101

102-
response=$(curl -s -X POST "$API_BASE/" \
103-
-H "Authorization: Bearer $TOKEN" \
104-
-H "Content-Type: application/json" \
105-
--data-binary "@$JSON_PAYLOAD_PATH")
102+
# response=$(curl -s -X POST "$API_BASE/" \
103+
# -H "Authorization: Bearer $TOKEN" \
104+
# -H "Content-Type: application/json" \
105+
# --data-binary "@$JSON_PAYLOAD_PATH")
106106

107-
result_status=$(echo "$response" | jq -r '.status // empty')
108-
message=$(echo "$response" | jq -r '.message // "No message provided"')
107+
# result_status=$(echo "$response" | jq -r '.status // empty')
108+
# message=$(echo "$response" | jq -r '.message // "No message provided"')
109109

110-
# Handle result
111-
if [ "$result_status" != "passed" ]; then
112-
echo -e "❌ Validation failed:\n$message"
113-
exit 1
114-
fi
110+
# # Handle result
111+
# if [ "$result_status" != "passed" ]; then
112+
# echo -e "❌ Validation failed:\n$message"
113+
# exit 1
114+
# fi
115115

116-
echo "✅ $message"
116+
# echo "✅ $message"
117117

0 commit comments

Comments
 (0)