Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MANIFEST] Set up a workflow to test clearing cache on the notify website post a deploy #2920

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/clear-notify-cache.yaml
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
12 changes: 10 additions & 2 deletions .github/workflows/merge_to_main_staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
with:
config_file: /var/tmp/staging.ovpn
client_key: ${{ secrets.STAGING_OVPN_CLIENT_KEY }}
echo_config: false
echo_config: false

- name: Decrypt staging env
run: |
Expand Down Expand Up @@ -128,4 +128,12 @@ jobs:
if: ${{ failure() }}
run: |
json="{'text':'<!here> Manifests Merge To Staging CI is failing in <https://github.com/cds-snc/notification-manifests/|notification-manifests> !'}"
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_WEBHOOK }}
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_WEBHOOK }}

clear-cache:
needs: kubectl-apply
uses: ./.github/workflows/clear-notify-cache.yaml
secrets:
CACHE_CLEAR_USER_NAME: ${{ secrets.STAGING_CACHE_CLEAR_USER_NAME }}
CACHE_CLEAR_CLIENT_SECRET: ${{ secrets.STAGING_CACHE_CLEAR_CLIENT_SECRET }}
API_URL: ${{ secrets.STAGING_API_URL }}
38 changes: 38 additions & 0 deletions scripts/clear-cache.js
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);
});
63 changes: 0 additions & 63 deletions scripts/clear_cache.js

This file was deleted.

Loading