Skip to content

Commit

Permalink
wikitide-backup: cache token
Browse files Browse the repository at this point in the history
  • Loading branch information
paladox committed Oct 16, 2024
1 parent 6473847 commit 46a0a2b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions modules/base/templates/backups/wikitide-backup.py.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ parser.add_argument('--database', dest='database', help='Specific database to do
args = parser.parse_args()


pca_password = "<%= @pca_password %>"
proxies = { 'https': 'http://bastion.wikitide.net:8080' }
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 }


def pca_connection(status, *args):
with Connection('gateways.storage.bhs.cloud.ovh.net', gateway='nc -X connect -x bastion.wikitide.net:8080 %h %p', user='pca', connect_kwargs={'password': '<%= @pca_password %>'}) as c:
if status == 'GET':
Expand All @@ -34,13 +42,6 @@ def pca_connection(status, *args):


def pca_web(method: str, url: str, expiry: int):
pca_password = "<%= @pca_password %>"
proxies = { 'https': 'http://bastion.wikitide.net:8080' }
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':
return requests.get(url, headers=headers, proxies=proxies)
elif method == 'POST':
Expand Down

0 comments on commit 46a0a2b

Please sign in to comment.