-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.py
65 lines (47 loc) · 1.41 KB
/
init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import subprocess
from pydantic import BaseModel, Field
from typing import Optional, List
import uuid
import os
import yaml
minio_address = os.getenv("MINIO_HOST")
root_user = os.getenv("MINIO_ROOT_USER")
root_password = os.getenv("MINIO_ROOT_PASSWORD")
alias = "local"
class Bucket(BaseModel):
name: str
class User(BaseModel):
name: str
access_key: str
secret_key: str
policies: List[str]
class Config(BaseModel):
users: List[User]
buckets: List[Bucket]
def main():
print("Initializing MinIO server...")
print(f"MinIO address: {minio_address}")
print(f"Root user: {root_user}")
print(f"Root password: {root_password}")
print(f"Alias: {alias}")
with open("./config.yaml", "r") as f:
x = yaml.safe_load(f)
config = Config(**x)
subprocess.call(
f"./mc alias set {alias} {minio_address} {root_user} {root_password}",
shell=True,
)
for bucket in config.buckets:
subprocess.call(f"./mc mb {alias}/{bucket.name}", shell=True)
for user in config.users:
subprocess.call(
f"./mc admin user add {alias} {user.access_key} {user.secret_key}",
shell=True,
)
for policy in user.policies:
subprocess.call(
f"./mc admin policy attach {alias} {policy} --user {user.access_key}",
shell=True,
)
if __name__ == "__main__":
main()