|
2 | 2 | import json |
3 | 3 | import time |
4 | 4 | from jsonschema import validate |
5 | | -from .config import INSTANCES_PATH |
6 | | - |
| 5 | +from .config import INSTANCES_PATH, ADDONS_PATH |
7 | 6 |
|
8 | 7 | INSTANCE_META_SCHEMA = { |
9 | 8 | "type": "object", |
@@ -43,7 +42,7 @@ def dump_instance_meta(instance_id, data): |
43 | 42 | file = os.path.join(INSTANCES_PATH, instance_id, "instance.json") |
44 | 43 | validate(instance=data, schema=INSTANCE_META_SCHEMA) |
45 | 44 | with open(file, "w") as f: |
46 | | - json.dump(f, data) |
| 45 | + f.write(json.dumps(data, sort_keys=True, indent=2)) |
47 | 46 |
|
48 | 47 |
|
49 | 48 | BINDING_META_SCHEMA = { |
@@ -78,4 +77,64 @@ def dump_binding_meta(instance_id, data): |
78 | 77 | file = os.path.join(INSTANCES_PATH, instance_id, "binding.json") |
79 | 78 | validate(instance=data, schema=INSTANCE_META_SCHEMA) |
80 | 79 | with open(file, "w") as f: |
81 | | - f.write(json.dumps(data)) |
| 80 | + f.write(json.dumps(data, sort_keys=True, indent=2)) |
| 81 | + |
| 82 | + |
| 83 | +ADDONS_META_SCHEMA = { |
| 84 | + "type": "object", |
| 85 | + "patternProperties": { |
| 86 | + ".*": { |
| 87 | + "id": {"type": "string"}, |
| 88 | + "name": {"type": "string"}, |
| 89 | + "version": {"type": "string"}, |
| 90 | + "bindable": {"type": "boolean"}, |
| 91 | + "instances_retrievable": {"type": "boolean"}, |
| 92 | + "bindings_retrievable": {"type": "boolean"}, |
| 93 | + "allow_context_updates": {"type": "boolean"}, |
| 94 | + "description": {"type": "string"}, |
| 95 | + "tags": {"type": "string"}, |
| 96 | + "requires": {"type": "array"}, |
| 97 | + "metadata": {"type": "object"}, |
| 98 | + "plan_updateable": {"type": "boolean"}, |
| 99 | + "dashboard_client": {"type": "object"}, |
| 100 | + "plans": { |
| 101 | + "type": "object", |
| 102 | + "id": {"type": "string"}, |
| 103 | + "name": {"type": "string"}, |
| 104 | + "description": {"type": "string"}, |
| 105 | + "metadata": {"type": "object"}, |
| 106 | + "free": {"type": "boolean"}, |
| 107 | + "bindable": {"type": "boolean"}, |
| 108 | + "binding_rotatable": {"type": "boolean"}, |
| 109 | + "plan_updateable": {"type": "boolean"}, |
| 110 | + "schemas": {"type": "object"}, |
| 111 | + "maximum_polling_duration": {"type": "integer"}, |
| 112 | + "maintenance_info": {"type": "object"}, |
| 113 | + "required": [ |
| 114 | + "id", "name", "description" |
| 115 | + ] |
| 116 | + }, |
| 117 | + "required": [ |
| 118 | + "id", "name", "description", "bindable", "version", "plans" |
| 119 | + ] |
| 120 | + } |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | + |
| 125 | +def load_addons_meta(): |
| 126 | + file = os.path.join(ADDONS_PATH, "addons.json") |
| 127 | + with open(file, 'r') as f: |
| 128 | + data = json.loads(f.read()) |
| 129 | + if not data: |
| 130 | + return {} |
| 131 | + validate(instance=data, schema=INSTANCE_META_SCHEMA) |
| 132 | + return data |
| 133 | + |
| 134 | + |
| 135 | +def dump_addons_meta(data): |
| 136 | + file = os.path.join(ADDONS_PATH, "addons.json") |
| 137 | + validate(instance=data, schema=INSTANCE_META_SCHEMA) |
| 138 | + with open(file, "w") as f: |
| 139 | + print("save addons.json") |
| 140 | + f.write(json.dumps(data, sort_keys=True, indent=2)) |
0 commit comments