-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Reusable Clear Cache Workflow | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
required: true | ||
type: string | ||
secrets: | ||
CACHE_CLEAR_USER_NAME: | ||
required: true | ||
CACHE_CLEAR_CLIENT_SECRET: | ||
required: true | ||
API_URL: | ||
required: true | ||
|
||
jobs: | ||
clear-cache: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "14" | ||
|
||
- name: Install dependencies | ||
run: npm install jsonwebtoken axios | ||
|
||
- name: Call API to clear cache | ||
env: | ||
CACHE_CLEAR_USER_NAME: ${{ secrets.CACHE_CLEAR_USER_NAME }} | ||
CACHE_CLEAR_CLIENT_SECRET: ${{ secrets.CACHE_CLEAR_CLIENT_SECRET }} | ||
API_URL: ${{ secrets.API_URL }} | ||
run: node scripts/clear-cache.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const jwt = require('jsonwebtoken'); | ||
const axios = require('axios'); | ||
|
||
const payload = { | ||
iss: process.env.CACHE_CLEAR_USER_NAME, | ||
iat: Math.floor(Date.now() / 1000), | ||
exp: Math.floor(Date.now() / 1000) + (60 * 60), // 1 hour from now | ||
}; | ||
const options = { | ||
algorithm: 'HS256', | ||
header: { | ||
alg: 'HS256', | ||
typ: 'JWT' | ||
} | ||
}; | ||
|
||
const token = jwt.sign(payload, process.env.CACHE_CLEAR_CLIENT_SECRET, options); | ||
|
||
try { | ||
const decoded = jwt.verify(token, process.env.CACHE_CLEAR_CLIENT_SECRET, { algorithms: ['HS256'] }); | ||
console.log('Token verified successfully. Payload:', decoded); | ||
} catch (err) { | ||
console.error('Token verification failed:', err.message); | ||
} | ||
|
||
axios.post(process.env.API_URL + '/cache-clear', null, { | ||
headers: { | ||
'Authorization': `Bearer ${token}`, | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
.then(response => { | ||
console.log('API call successful:', response.data); | ||
}) | ||
.catch(error => { | ||
console.error('Error calling API:', error.response ? error.response.data : error.message); | ||
process.exit(1); | ||
}); |
This file was deleted.
Oops, something went wrong.