-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_models.py
131 lines (111 loc) · 3.03 KB
/
_models.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
"""
Models for Boxer
"""
# Copyright (c) 2023. ECCO Sneaks & Data
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from dataclasses import dataclass
from typing import Dict
@dataclass
class BoxerClaim:
"""
Boxer Claim
"""
claim_type: str
claim_value: str
issuer: str
def to_dict(self) -> Dict:
"""Convert to Dictionary
:return: Dictionary
"""
return {
"claimType": self.claim_type,
"claimValue": self.claim_value,
"issuer": self.issuer,
}
@classmethod
def from_dict(cls, json_data: Dict):
"""Initialize from Dictionary
:param json_data: Dictionary
:return:
"""
return BoxerClaim(
claim_type=json_data["claimType"],
claim_value=json_data["claimValue"],
issuer=json_data["issuer"],
)
@dataclass
class UserClaim:
"""
Boxer User Claim
"""
user_id: str
user_claim_id: str
claim: BoxerClaim
def to_dict(self) -> Dict:
"""Convert to Dictionary
:return: Dictionary
"""
return {
"userId": self.user_id,
"userClaimId": self.user_claim_id,
"claim": self.claim.to_dict(),
}
@classmethod
def from_dict(cls, json_data: Dict):
"""Initialize from Dictionary
:param json_data: Dictionary
:return:
"""
return UserClaim(
user_id=json_data["userId"],
user_claim_id=json_data["userClaimId"],
claim=BoxerClaim.from_dict(json_data["claim"]),
)
@dataclass
class GroupClaim:
"""
Boxer Group Claim
"""
group_name: str
group_claim_id: str
claim: BoxerClaim
def to_dict(self) -> Dict:
"""Convert to Dictionary
:return: Dictionary
"""
return {
"groupName": self.group_name,
"groupClaimId": self.group_claim_id,
"claim": self.claim.to_dict(),
}
@classmethod
def from_dict(cls, json_data: Dict):
"""Initialize from Dictionary
:param json_data: Dictionary
:return:
"""
return GroupClaim(
group_name=json_data["groupName"],
group_claim_id=json_data["groupClaimId"],
claim=BoxerClaim.from_dict(json_data["claim"]),
)
class BoxerToken:
"""
Represents token created by BoxerConnector.get_token
"""
def __init__(self, token: str):
self._token = token
def __str__(self):
return self._token