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