xk6-frostfs/scenarios/preset/resolve_containers_in_preset.py
Dmitrii Stepanov 3574361f2e
All checks were successful
DCO action / DCO (pull_request) Successful in 1m51s
Tests and linters / Tests (1.21) (pull_request) Successful in 2m55s
Tests and linters / Tests with -race (pull_request) Successful in 3m20s
Tests and linters / Tests (1.20) (pull_request) Successful in 3m33s
[#104] s3local: Use default HTTP client instead of requests
`requests` lib is not default, so it can be unavailable.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-11-17 14:33:32 +03:00

33 lines
No EOL
915 B
Python
Executable file

#!/usr/bin/python3
import argparse
import json
import http.client
import ssl
parser = argparse.ArgumentParser()
parser.add_argument('--endpoint', help='Endpoint of the S3 gateway')
parser.add_argument('--preset_file', help='JSON file path with s3 preset')
args = parser.parse_args()
def main():
with open(args.preset_file) as f:
preset_text = f.read()
preset = json.loads(preset_text)
conn = http.client.HTTPSConnection(args.endpoint, context = ssl._create_unverified_context())
containers = []
for bucket in preset.get('buckets'):
conn.request("HEAD", f'/{bucket}')
response = conn.getresponse()
containers.append(response.getheader('X-Container-Id'))
response.read()
preset['containers'] = containers
with open(args.preset_file, 'w+') as f:
json.dump(preset, f, ensure_ascii=False, indent=2)
if __name__ == "__main__":
main()