Skip to content

Commit

Permalink
Revert "wikitide-backup: remove caching the token for now" (#4064)
Browse files Browse the repository at this point in the history
Reverts #4062
  • Loading branch information
paladox authored Oct 26, 2024
1 parent b899225 commit 6b1114f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions modules/base/templates/backups/wikitide-backup.py.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import time
from fabric import Connection
from datetime import datetime

# Cache swift token
# We don't want to hit rate limits (429)
token = None

parser = argparse.ArgumentParser(description='Provides backup and download functionality for WikiTide backups from PCA.')
parser.add_argument('action', choices=['backup', 'download', 'find', 'unfreeze'], help='Action to be ran')
parser.add_argument('type', choices=['private', 'sslkeys', 'phorge', 'sql', 'mediawiki-xml', 'swift-account-container', 'grafana'], help='Type of backup to handle using the action')
Expand All @@ -36,10 +40,14 @@ def pca_connection(status, *args):


def pca_web(method: str, url: str, expiry: int):
global token

proxies = { 'https': 'http://bastion.wikitide.net:8080' }
pca_password = "<%= @pca_password %>"
json_data = { "auth": { "identity": { "methods": ["password"], "password": { "user": { "name": pca_password.split('.')[1], "domain": { "id": "default" }, "password": pca_password.split('.')[2] } } }, "scope": { "project": { "id": "76f9bc606a8044e08db7ebd118f6b19a", "domain": { "id": "default" } } } } }
token = requests.post(f'https://auth.cloud.ovh.net/v3/auth/tokens', json=json_data, proxies=proxies, headers={ 'Content-Type': 'application/json' }).headers.get('X-Subject-Token')

if token is None:
pca_password = "<%= @pca_password %>"
json_data = { "auth": { "identity": { "methods": ["password"], "password": { "user": { "name": pca_password.split('.')[1], "domain": { "id": "default" }, "password": pca_password.split('.')[2] } } }, "scope": { "project": { "id": "76f9bc606a8044e08db7ebd118f6b19a", "domain": { "id": "default" } } } } }
token = requests.post(f'https://auth.cloud.ovh.net/v3/auth/tokens', json=json_data, proxies=proxies, headers={ 'Content-Type': 'application/json' }).headers.get('X-Subject-Token')
headers = { 'X-AUTH-TOKEN': token }

if method == 'GET':
Expand Down

0 comments on commit 6b1114f

Please sign in to comment.