diff --git a/modules/base/templates/backups/wikitide-backup.py.erb b/modules/base/templates/backups/wikitide-backup.py.erb index 9b31738537..8be26a3aa0 100644 --- a/modules/base/templates/backups/wikitide-backup.py.erb +++ b/modules/base/templates/backups/wikitide-backup.py.erb @@ -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') @@ -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':