35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import pathlib
|
|
import secrets
|
|
import json
|
|
|
|
p = pathlib.Path('.env')
|
|
env = dict(x.split('=',1) for x in p.read_text().splitlines() if '=' in x and not x.startswith('#'))
|
|
|
|
for role in ('API', 'WORKER'):
|
|
env.setdefault('S3_'+role+'_PASSWORD', secrets.token_hex(24))
|
|
|
|
p.write_text(''.join(f'{k}={v}\n' for k,v in env.items()))
|
|
|
|
config = {
|
|
'identities': [
|
|
{
|
|
'name': 'operator',
|
|
'credentials': [{'accessKey':'lab','secretKey':env['S3_SECRET_ACCESS_KEY']}],
|
|
'actions': ['Admin','Read','Write','List']
|
|
},
|
|
{
|
|
'name': 'api',
|
|
'credentials': [{'accessKey':'messenger_api','secretKey':env['S3_API_PASSWORD']}],
|
|
'actions': ['Read:messenger-attachments','Write:messenger-attachments','List:messenger-attachments']
|
|
},
|
|
{
|
|
'name': 'worker',
|
|
'credentials': [{'accessKey':'messenger_worker','secretKey':env['S3_WORKER_PASSWORD']}],
|
|
'actions': ['Read:messenger-attachments','Write:messenger-attachments','List:messenger-attachments']
|
|
}
|
|
]
|
|
}
|
|
|
|
pathlib.Path('secrets/s3.json').write_text(json.dumps(config))
|
|
print('PASS: S3 identities configured')
|