-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure.py
executable file
·107 lines (85 loc) · 2.7 KB
/
configure.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
import argparse
import json
import os
from typing import Dict
def create_datastore_spec(bucket: str, region: str) -> Dict:
return {
'mounts': [
{
'bucket': bucket,
'mountpoint': '/blocks',
'region': region,
'rootDirectory': '/blocks',
},
{
'mountpoint': '/',
'path': 'datastore',
'type': 'levelds',
}
],
'type': 'mount',
}
def update_config(config: Dict, bucket: str, region: str, region_endpoint: str):
config['Datastore']['Spec']['mounts'][0] = {
'child': {
'type': 's3ds',
'region': region,
'bucket': bucket,
'rootDirectory': '/blocks',
'regionEndpoint': region_endpoint,
'accessKey': '',
'secretKey': '',
},
'mountpoint': '/blocks',
'prefix': 's3.datastore',
'type': 'measure',
}
def get_config_path(base_dir: str):
return os.path.join(os.path.expanduser(base_dir), 'config')
def get_datastore_spec_path(base_dir: str):
return os.path.join(os.path.expanduser(base_dir), 'datastore_spec')
def load_config(base_dir: str) -> Dict:
config_path = get_config_path(base_dir)
print(config_path)
with open(config_path) as f:
return json.load(f)
def save_config(base_dir: str, config: Dict) -> Dict:
config_path = get_config_path(base_dir)
with open(config_path, 'w') as f:
json.dump(config, f, indent=4)
def save_datastore_spec(base_dir: str, datastore_spec: Dict) -> Dict:
datastore_spec_path = get_datastore_spec_path(base_dir)
with open(datastore_spec_path, 'w') as f:
json.dump(datastore_spec, f, separators=(',', ':'))
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--base-dir', default='~/.ipfs',
help='IPFS config dir. Defaults to ~/.ipfs'
)
parser.add_argument(
'--region', default='us-east-1',
help='AWS region for S3 bucket',
)
parser.add_argument(
'--bucket', required=True,
help='AWS S3 bucket name',
)
parser.add_argument(
'--region-endpoint',
help='AWS S3 region endpoint (for S3 compatible provider or acceleration)',
)
args = parser.parse_args()
config = load_config(args.base_dir)
update_config(
config,
args.bucket,
args.region,
args.region_endpoint,
)
save_config(args.base_dir, config)
datastore_spec = create_datastore_spec(args.bucket, args.region)
save_datastore_spec(args.base_dir, datastore_spec)
if __name__ == '__main__':
main()