This repository has been archived by the owner on Jun 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
133 lines (101 loc) · 3.8 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
132
133
# This code is a part of MagicCap which is a MPL-2.0 licensed project.
# Copyright (C) Jake Gealer <[email protected]> 2018.
from pynamodb.models import Model
from pynamodb.indexes import GlobalSecondaryIndex, AllProjection
from pynamodb.attributes import UnicodeAttribute, NumberAttribute, JSONAttribute, ListAttribute, BooleanAttribute
# Imports go here.
class VersionIndex(GlobalSecondaryIndex):
"""The index used for querying the version."""
class Meta:
read_capacity_units = 2
write_capacity_units = 1
projection = AllProjection()
version = UnicodeAttribute(hash_key=True)
class Version(Model):
"""The model used for each version."""
class Meta:
table_name = "magiccap_versions"
region = "eu-west-2"
read_capacity_units = 2
write_capacity_units = 1
release_id = NumberAttribute(hash_key=True)
version = UnicodeAttribute()
version_index = VersionIndex()
changelogs = UnicodeAttribute()
beta = BooleanAttribute(null=True)
def get_version(version):
"""Uses the index to get a version."""
for i in Version.version_index.query(version):
return i
raise Version.DoesNotExist
class TravisKeys(Model):
"""The model used for Travis API keys."""
class Meta:
table_name = "magiccap_travis_keys"
region = "eu-west-2"
read_capacity_units = 1
write_capacity_units = 1
key = UnicodeAttribute(hash_key=True)
class IPHashTimestamps(Model):
"""The timestamp that a IP address hash connected. This is used for ratelimiting."""
class Meta:
table_name = "magiccap_ip_hash_timestamps"
region = "eu-west-2"
read_capacity_units = 1
write_capacity_units = 1
ip_hash = UnicodeAttribute(hash_key=True)
timestamp = NumberAttribute()
class UnvalidatedGlobalKeyRequests(Model):
"""Global key requests that have not been validated yet."""
class Meta:
table_name = "magiccap_unvalidated_global_key_requests"
region = "eu-west-2"
read_capacity_units = 1
write_capacity_units = 1
key = UnicodeAttribute(hash_key=True)
data = JSONAttribute()
class GlobalKeys(Model):
"""Defines global keys (and those pending review)."""
class Meta:
table_name = "magiccap_global_keys"
region = "eu-west-2"
read_capacity_units = 3
write_capacity_units = 2
key = UnicodeAttribute(hash_key=True)
email = UnicodeAttribute()
scopes = ListAttribute()
publisher_name = UnicodeAttribute()
service_name = UnicodeAttribute()
reviewed = BooleanAttribute()
class OneTimeKeys(Model):
"""Defines one time keys."""
class Meta:
table_name = "magiccap_one_time_keys"
region = "eu-west-2"
read_capacity_units = 2
write_capacity_units = 1
key = UnicodeAttribute(hash_key=True)
global_key = UnicodeAttribute()
class DeviceIDIndex(GlobalSecondaryIndex):
"""The index used for querying the device ID."""
class Meta:
read_capacity_units = 2
write_capacity_units = 1
projection = AllProjection()
device_id = UnicodeAttribute(hash_key=True)
class InstallID(Model):
"""Defines install ID's."""
class Meta:
table_name = "magiccap_install_ids"
region = "eu-west-2"
read_capacity_units = 3
write_capacity_units = 3
install_id = UnicodeAttribute(hash_key=True)
device_id = UnicodeAttribute()
hashed_ip = UnicodeAttribute()
device_id_index = DeviceIDIndex()
def get_device_id(device_id):
"""Uses the index to get a device ID."""
for i in InstallID.device_id_index.query(device_id):
return i
raise InstallID.DoesNotExist