-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeta.py
More file actions
76 lines (64 loc) · 2 KB
/
meta.py
File metadata and controls
76 lines (64 loc) · 2 KB
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
import os
import json
from jsonschema import validate
from .config import INSTANCES_PATH
INSTANCE_META_SCHEMA = {
"type": "object",
"properties": {
"id": {"type": "string"},
"details": {
"type": "object",
"properties": {
"service_id": {"type": "string"},
"plan_id": {"type": "string"},
"context": {"type": "object"},
"parameters": {"type": "object"},
}
},
"last_operation": {
"type": "object",
"properties": {
"state": {"type": "string"},
"description": {"type": "string"}
}
}
},
}
def load_instance_meta(instance_id):
file = os.path.join(INSTANCES_PATH, instance_id, "instance.json")
with open(file) as f:
data = json.load(f)
validate(instance=data, schema=INSTANCE_META_SCHEMA)
return data
def dump_instance_meta(instance_id, data):
file = os.path.join(INSTANCES_PATH, instance_id, "instance.json")
validate(instance=data, schema=INSTANCE_META_SCHEMA)
with open(file, "w") as f:
json.dump(f, data)
BINDING_META_SCHEMA = {
"type": "object",
"properties": {
"id": {"type": "string"},
"credentials": {
"type": "object",
},
"last_operation": {
"type": "object",
"properties": {
"state": {"type": "string"},
"description": {"type": "string"}
}
}
}
}
def load_binding_meta(instance_id):
file = os.path.join(INSTANCES_PATH, instance_id, "binding.json")
with open(file, 'r') as f:
data = json.loads(f.read())
validate(instance=data, schema=INSTANCE_META_SCHEMA)
return data
def dump_binding_meta(instance_id, data):
file = os.path.join(INSTANCES_PATH, instance_id, "binding.json")
validate(instance=data, schema=INSTANCE_META_SCHEMA)
with open(file, "w") as f:
f.write(json.dumps(data))