-
Notifications
You must be signed in to change notification settings - Fork 2
69 lines (60 loc) · 1.88 KB
/
clear-notify-cache.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Call Notification clear cache API
# on:
# workflow_call:
# secrets:
# CACHE_CLEAR_USER_NAME:
# required: true
# CACHE_CLEAR_CLIENT_SECRET:
# required: true
# API_KEY:
# required: true
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
reason:
description: "Reason for manual trigger"
required: true
default: "Testing"
jobs:
call-api:
runs-on: ubuntu-latest
steps:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
- name: Create package.json
run: |
echo '{"dependencies": {"jsonwebtoken": "^8.5.1", "axios": "^0.21.1"}}' > package.json
- name: Install dependencies
run: npm install
- name: Call API with JWT
env:
CACHE_CLEAR_CLIENT_SECRET: ${{ secrets.CACHE_CLEAR_CLIENT_SECRET }}
run: |
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 token = jwt.sign(payload, process.env.CACHE_CLEAR_CLIENT_SECRET, { algorithm: 'HS256' });
axios.post('https://notification.canada.ca/cache/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);
});
shell: node {0}