Skip to content

Commit a7dd06b

Browse files
committed
fixup
1 parent 1c58b27 commit a7dd06b

2 files changed

Lines changed: 34 additions & 39 deletions

File tree

rootfs/helmbroker/meta.py

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,41 @@
11
import os
2-
import yaml
2+
import json
3+
from jsonschema import validate
34
from .config import INSTANCES_PATH
45

5-
INSTANCE_META_FILE = os.path.join(INSTANCES_PATH, "instance.yaml")
6-
7-
class InstanceMeta(object):
8-
"""
9-
{
10-
"id": "instance_id",
11-
"details": {
12-
"service_id": "service_id",
13-
"plan_id" : "plan_id",
14-
"context" : {
15-
16-
},
17-
"parameters": {
18-
6+
INSTANCE_META_FILE = os.path.join(INSTANCES_PATH, "instance.json")
7+
INSTANCE_META_SCHEMA = {
8+
"type" : "object",
9+
"properties" : {
10+
"id" : {"type" : "string"},
11+
"details" : {
12+
"type" : "object",
13+
"properties": {
14+
"service_id": {"type" : "string"},
15+
"plan_id" : {"type" : "string"},
16+
"context" : {"type" : "object"},
17+
"parameters": {"type" : "object"},
1918
}
2019
},
2120
"last_operation": {
22-
"state": "Ready",
23-
"description": "everything is ok."
21+
"type" : "object",
22+
"properties": {
23+
"state": {"type" : "string"},
24+
"description": {"type" : "string"}
25+
}
2426
}
25-
}
26-
"""
27-
def __init__(self, id, details, last_operation):
28-
self.id = id
29-
self.details = details
30-
self.last_operation = last_operation
31-
32-
@classmethod
33-
def load(cls, file=INSTANCE_META_FILE):
34-
with open(file) as f:
35-
data = yaml.load(f, Loader=yaml.Loader)
36-
return cls(data["id"], data["details"], data["last_operation"])
27+
},
28+
}
29+
30+
31+
def load_instance_meta(file=INSTANCE_META_FILE):
32+
with open(file) as f:
33+
data = json.load(f)
34+
validate(instance=data, schema=INSTANCE_META_SCHEMA)
35+
return data
36+
3737

38-
def dump(self, file=INSTANCE_META_FILE):
39-
with open(file, "w") as f:
40-
yaml.dump(
41-
{
42-
"id": self.id,
43-
"details": self.details,
44-
"last_operation": self.last_operation
45-
},
46-
Loader=yaml.Loader
47-
)
38+
def dump_instance_meta(data, file=INSTANCE_META_FILE):
39+
validate(instance=data, schema=INSTANCE_META_SCHEMA)
40+
with open(file, "w") as f:
41+
json.dump(f, data)

rootfs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ gunicorn==20.1.0
33
openbrokerapi==4.1.2
44
requests==2.26.0
55
celery==5.1.2
6+
jsonschema==3.2.0

0 commit comments

Comments
 (0)