Storage Provider Types
Storage provider is one of the building blocks in Terraflex
-
it defines an abstract way to communicate with a storage of any kind.
A new storage provider can easily be provided by implementing one of the protocols below -
and registering into terraflex.plugins.storage_provider
entrypoint.
Readable Storage
StorageProviderProtocol
Protocol for storage providers - Read only.
Readable storage is the most basic storage provider - it allows to read files from the storage.
Every readonly storage provider must implement StorageProviderProtocol
methods -
and register to the terraflex.plugins.storage_provider
entrypoint.
Source code in terraflex/server/storage_provider_base.py
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 |
|
from_config(raw_config, *, manager, workdir)
async
classmethod
Create an instance of the storage provider from the configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_config |
Any
|
The raw configuration propagated from the storage provider config. |
required |
manager |
DependenciesManager
|
The dependencies manager - allows to request a binary path from. |
required |
workdir |
Path
|
The data directory of terraflex - located at |
required |
Source code in terraflex/server/storage_provider_base.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
get_file(item_identifier)
async
Get the content of the file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_identifier |
ItemKey
|
The identifier of the file. |
required |
Source code in terraflex/server/storage_provider_base.py
76 77 78 79 80 81 82 |
|
validate_key(key)
classmethod
Validate the key of the item in the storage provider from a config of usage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
dict[str, Any]
|
a dict with parameters to build the key of the item. |
required |
Returns:
Type | Description |
---|---|
ItemKey
|
The validated key. |
Source code in terraflex/server/storage_provider_base.py
63 64 65 66 67 68 69 70 71 72 73 |
|
ItemKey
Bases: BaseModel
, ABC
Params required to reference an item in a storage provider.
Every storage provider must implement a subclass of ItemKey
to represent the key of the item - using the validate_key() method.
Source code in terraflex/server/storage_provider_base.py
13 14 15 16 17 18 19 20 21 22 |
|
as_string()
abstractmethod
Return the string representation of the key.
Source code in terraflex/server/storage_provider_base.py
19 20 21 22 |
|
Writeable Storage
WriteableStorageProviderProtocol
Bases: StorageProviderProtocol
, Protocol
Protocol for storage providers - Writeable.
Writeable storage provider allows to write files to the storage.
Every writeable storage provider must implement WriteableStorageProviderProtocol
methods and its parent methods -
and register to the terraflex.plugins.storage_provider
entrypoint.
Source code in terraflex/server/storage_provider_base.py
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 |
|
delete_file(item_identifier)
async
Delete the file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_identifier |
ItemKey
|
The identifier of the file. |
required |
Source code in terraflex/server/storage_provider_base.py
105 106 107 108 109 110 111 |
|
put_file(item_identifier, data)
async
Put the content of the file in the provided file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_identifier |
ItemKey
|
The identifier of the file. |
required |
data |
bytes
|
The content of the file. |
required |
Source code in terraflex/server/storage_provider_base.py
96 97 98 99 100 101 102 103 |
|
Lockable Storage
LockableStorageProviderProtocol
Bases: WriteableStorageProviderProtocol
, Protocol
Protocol for storage providers - Lockable.
Lockable storage provider allows to lock items to prevent concurrent writes. Allows to support terraform state locking - see more at official docs.
Every lockable storage provider must implement LockableStorageProviderProtocol
methods and its parent methods -
and register to the terraflex.plugins.storage_provider
entrypoint.
Source code in terraflex/server/storage_provider_base.py
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 |
|
acquire_lock(item_identifier, data)
async
Acquire the lock of the item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_identifier |
ItemKey
|
The identifier of the item. |
required |
data |
LockBody
|
The lock data of the item. |
required |
Source code in terraflex/server/storage_provider_base.py
137 138 139 140 141 142 143 144 |
|
read_lock(item_identifier)
async
Read the lock of the item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_identifier |
ItemKey
|
The identifier of the item. |
required |
Returns:
Type | Description |
---|---|
LockBody
|
The lock data of the item. |
Source code in terraflex/server/storage_provider_base.py
126 127 128 129 130 131 132 133 134 135 |
|
release_lock(item_identifier)
async
Source code in terraflex/server/storage_provider_base.py
146 |
|
LockBody
Bases: BaseModel
Data struct that contains the lock information.
This is the same data struct that is required by terraform. It follows the same fields names as the terraform lock file.
See offical source.
Attributes:
Name | Type | Description |
---|---|---|
ID |
str
|
The ID of the lock. |
Operation |
str
|
The operation that is being performed. |
Who |
str
|
The entity that is performing the operation. |
Version |
str
|
The version of the lock. |
Created |
str
|
The time when the lock was created. |
Source code in terraflex/server/base_state_lock_provider.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|