http_storage
Base class for HTTP based stores.
API_PREFIX = settings.API_PREFIX
module-attribute
API URL prefix.
HttpResourceStorage
Bases: Storage
An HTTP base storage for a given resource type.
Source code in mlte/store/common/http_storage.py
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 | |
clean_url = self.client.process_credentials(uri.uri)
instance-attribute
Store the clean URL without credentials.
client = client
instance-attribute
The client for requests.
__init__(uri, resource_type, client=None)
Creates an HTTP storage for a specific resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
StoreURI
|
The properly formated StoreURI for an HTTP storage, including server and ports, and credentials. |
required |
resource_type
|
ResourceType | str
|
The type of resource, used to build the resource URL for this storage. Can be a ResourceType, or a simple string. |
required |
client
|
Optional[OAuthHttpClient]
|
The OAuthHttpClient to use, will default to RequestsClient if none. |
None
|
Source code in mlte/store/common/http_storage.py
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 | |
delete(id, groups=OrderedDict())
Delete method, to remove resource.
Source code in mlte/store/common/http_storage.py
82 83 84 85 86 | |
get(id=None, groups=OrderedDict(), query_args={})
Get method, to read resource.
Source code in mlte/store/common/http_storage.py
71 72 73 74 75 76 77 78 79 80 | |
post(json, groups=OrderedDict())
Post method, to create resource.
Source code in mlte/store/common/http_storage.py
59 60 61 62 63 | |
put(json, groups=OrderedDict())
Put method, to update resource.
Source code in mlte/store/common/http_storage.py
65 66 67 68 69 | |
send_command(method, groups=OrderedDict(), id=None, query_args={}, json=None, resource_type=None)
Sends an HTTP command request to the backend API, and returns a JSON response from it. Commonly not used directly, as it is expected for callers to use the post(), put(), read() and delete() method, but can be used when a non-standard command, which does not properly match the arguments of the previous 4 methods, needs to be sent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
MethodType
|
what HTTP method to use, from MethodType |
required |
groups
|
OrderedDict[str, str]
|
a dict of groups to prepend to the request path, where the key is the id of the given group, and the value is the string used to denote the beginning of the next nested level (e.g., {"model1": "version"}, with model1 being a model id, and "version" being the keyword for the next level). |
OrderedDict()
|
id
|
Optional[str]
|
the id of a given resource. |
None
|
query_args
|
dict[str, str]
|
dictionary of query args to append. |
{}
|
json
|
Optional[Any]
|
json payload to send, only for POST and PUT commands. |
None
|
resource_type
|
Optional[str]
|
optional param to overwride the default resource type set up when creating this storage; string to be used as the first item in the URL's path. |
None
|
Source code in mlte/store/common/http_storage.py
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 | |
start_session()
Perform authentication.
Source code in mlte/store/common/http_storage.py
55 56 57 | |