2023-03-31 10:30:33 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import json
|
2023-11-17 11:33:32 +00:00
|
|
|
import http.client
|
|
|
|
import ssl
|
2023-03-31 10:30:33 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2023-11-17 11:33:32 +00:00
|
|
|
conn = http.client.HTTPSConnection(args.endpoint, context = ssl._create_unverified_context())
|
2023-03-31 10:30:33 +00:00
|
|
|
containers = []
|
|
|
|
for bucket in preset.get('buckets'):
|
2023-11-17 11:33:32 +00:00
|
|
|
conn.request("HEAD", f'/{bucket}')
|
|
|
|
response = conn.getresponse()
|
|
|
|
containers.append(response.getheader('X-Container-Id'))
|
|
|
|
response.read()
|
2023-03-31 10:30:33 +00:00
|
|
|
|
|
|
|
preset['containers'] = containers
|
|
|
|
with open(args.preset_file, 'w+') as f:
|
|
|
|
json.dump(preset, f, ensure_ascii=False, indent=2)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|