-
Notifications
You must be signed in to change notification settings - Fork 1
/
IndalekoUserRelationshipDataModel.py
181 lines (154 loc) · 6.49 KB
/
IndalekoUserRelationshipDataModel.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
'''
This module defines the database schema for the MachineConfig collection.
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/>.
'''
from dataclasses import dataclass
from datetime import datetime
from typing import Annotated, List
from uuid import UUID
from apischema import schema
from apischema.graphql import graphql_schema
from apischema.metadata import required
from graphql import print_schema
from IndalekoDataModel import IndalekoDataModel
from IndalekoRecordDataModel import IndalekoRecordDataModel
from IndalekoUserDataModel import IndalekoUserDataModel
class IndalekoUserRelationshipDataModel(IndalekoRecordDataModel):
'''
This defines the data model for user relationships (which means use to
group and user to domain, but could be generalized.)
'''
@dataclass
class UserIdentity:
'''
A User can have multiple identities: same user, different
identities.
'''
Identities: Annotated[
List[IndalekoUserDataModel.UserData],
schema(description="The user's identities."),
required
]
@staticmethod
def get_user_identities() -> 'IndalekoUserRelationshipDataModel.UserIdentity':
'''Return the user identity.'''
return IndalekoUserRelationshipDataModel.UserIdentity(
Identities=[
IndalekoUserDataModel.get_user_data()
]
)
@dataclass
class GroupIdentity:
'''
There is a relationship concept known as a group, so we define the
group identity data here.
'''
Domain : Annotated[
IndalekoUserDataModel.UserDomain,
schema(description="The security domain that defines this group."),
required
]
Description : Annotated[
str,
schema(description="A human readable description of the group.")
]
@staticmethod
def get_group_identity() -> 'IndalekoUserRelationshipDataModel.GroupIdentity':
'''Return the group identity.'''
return IndalekoUserRelationshipDataModel.GroupIdentity(
Domain=IndalekoUserDataModel.get_user_domain(),
Description='This is a test record'
)
@dataclass
class UserRelationship:
'''
Define the relationship between a user and a group.
'''
User : Annotated[
IndalekoUserDataModel.UserData,
schema(description="The user in the relationship."),
required
]
Group : Annotated[
'IndalekoUserRelationshipDataModel.GroupIdentity',
schema(description="The group in the relationship."),
required
]
@staticmethod
def get_user_relationship() -> 'IndalekoUserRelationshipDataModel.UserRelationship':
'''Return the user relationship.'''
return IndalekoUserRelationshipDataModel.UserRelationship(
User=IndalekoUserDataModel.get_user_data(),
Group=IndalekoUserRelationshipDataModel.get_group_identity()
)
@dataclass
class EntityRelationship:
'''
Define the relationship between a user entities:
- user to group
- group to users
'''
Identity1 : Annotated[
IndalekoDataModel.IndalekoUUID,
schema(description="The first element in the relationship."),
required
]
Identity2 : Annotated[
IndalekoDataModel.IndalekoUUID,
schema(description="The second element in the relationship."),
required
]
RelationshipType : Annotated[
IndalekoDataModel.IndalekoUUID,
schema(description="The UUID that defines the type of relationship."),
required
]
Metadata : Annotated[
List[IndalekoDataModel.SemanticAttribute],
schema(description="Metadata associated with this relationship."),
required
]
Description : Annotated[
str,
schema(description="A human readable description of the relationship.")
]
@staticmethod
def get_entity_relationship() -> 'IndalekoUserRelationshipDataModel.EntityRelationship':
'''Return the entity relationship.'''
return IndalekoUserRelationshipDataModel.EntityRelationship(
Identity1=IndalekoDataModel.get_source_identifier(UUID('12345678-1234-5678-1234-567812345678')),
Identity2=IndalekoDataModel.get_source_identifier(UUID('12345678-1234-5678-1234-567812345678')),
RelationshipType=IndalekoDataModel.get_source_identifier(UUID('12345678-1234-5678-1234-567812345678')),
Metadata=[IndalekoDataModel.get_semantic_attribute()],
Description='This is a test record'
)
@staticmethod
def get_queries() -> List:
return [IndalekoUserRelationshipDataModel.get_user_identities,
IndalekoUserRelationshipDataModel.get_group_identity,
IndalekoUserRelationshipDataModel.get_entity_relationship,
IndalekoUserRelationshipDataModel.get_user_relationship]
@staticmethod
def get_types() -> List:
return [IndalekoUserRelationshipDataModel.UserIdentity,
IndalekoUserRelationshipDataModel.GroupIdentity,
IndalekoUserRelationshipDataModel.UserRelationship,
IndalekoUserRelationshipDataModel.EntityRelationship]
def main():
'''Test the IndalekoUserRelationshipDataModel data model.'''
print('GraphQL Schema:')
print(print_schema(graphql_schema(query=IndalekoUserRelationshipDataModel.get_queries(),
types=IndalekoUserRelationshipDataModel.get_types())))
if __name__ == "__main__":
main()