-
Notifications
You must be signed in to change notification settings - Fork 1
/
IndalekoUserSchema.py
76 lines (66 loc) · 2.92 KB
/
IndalekoUserSchema.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
'''
This defines the Indaleko User schema.
Project Indaleko
Copyright (C) 2024 Tony Mason
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import json
from jsonschema import validate
from IndalekoUserDataModel import IndalekoUserDataModel
from IndalekoRecordSchema import IndalekoRecordSchema
class IndalekoUserSchema(IndalekoRecordSchema):
'''This class defines the schema for Indaleko Users.'''
def __init__(self):
'''Initialize the schema.'''
if not hasattr(self, 'data_model'):
self.data_model = IndalekoUserDataModel()
if not hasattr(self, 'base_type'):
self.base_type = IndalekoUserDataModel.UserData
super().__init__()
@staticmethod
def get_old_schema():
services_schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema#",
"$id": "https://activitycontext.work/schema/user.json",
"title": "Service provider schema",
"description":
"This schema describes information about user identity within the Indaleko system.",
"type": "object",
"rule" : {
"properties": {
"Identifier": {
"description": "This is the UUID of the Indaleko User.",
"type": "string",
"format": "uuid"
},
"Domain" : {
"description" : "This is the domain in which this user is defined.",
"type" : "string",
"format" : "uuid",
},
},
"required": ["Identifier", "Domain"],
}
}
assert 'Record' not in \
services_schema['rule']['properties'], 'Record must not be specified.'
services_schema['rule']['properties']['Record'] = \
IndalekoRecordSchema.get_old_schema()['rule']
services_schema['rule']['required'].append('Record')
return services_schema
def main():
'''Test code for IndalekoUserSchema.'''
if IndalekoUserSchema.is_valid_json_schema(IndalekoUserSchema.get_old_schema()):
print('Schema is valid.')
print(json.dumps(IndalekoUserSchema.get_old_schema(), indent=4))
if __name__ == "__main__":
main()