-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.py
82 lines (63 loc) · 2.01 KB
/
api.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
import api_signer
import protocol_formatter
import operation_obj
SAFE_REGIONS = [
"af-south-1",
"ap-east-1",
"ap-northeast-1",
"ap-northeast-2",
"ap-northeast-3",
"ap-south-1",
"ap-southeast-1",
"ap-southeast-2",
"ca-central-1",
"eu-central-1",
"eu-north-1",
"eu-south-1",
"eu-west-1",
"eu-west-2",
"eu-west-3",
"me-south-1",
"sa-east-1",
"us-east-1",
"us-east-2",
"us-west-1",
"us-west-2",
]
class API:
def __init__(self, key, service_definition):
self._definition = service_definition
self._latest_version = self.latest_version()
self.protocol = self.latest()['metadata']['protocol']
self.endpoints = self.latest()['endpoints']
self.operations = self._make_operations_list(
self.latest()['metadata'],
self.latest()['endpoints'],
self.latest()['shapes'],
self.latest()['operations']
)
# Returns the definiton of the lastest api version
def latest(self):
# Find the most recent api version
# We can do this by sorting keys
options = list(self._definition.keys())
options.sort()
return self._definition[list(reversed(options))[0]]
# Returns the latest api version
def latest_version(self):
return list(self._definition.keys())[0]
# Returns a list of the available API versions
def api_versions(self):
return list(self._definition.keys())
# Returns a list of all operations
def list_operations(self):
return list(self.operations.keys())
# Returns the protocol
def get_protocol(self):
return self.protocol
# Returns a dictionary with all the available operations
def _make_operations_list(self, metadata, endpoints, shapes, operations):
to_return = {}
for operation_name, operation in operations.items():
to_return[operation_name] = operation_obj.Operation(metadata, endpoints, shapes, operation)
return to_return