Secret Mapping
ImmutableSecretMapping
Bases: UserDict, Mapping[Any, Secret]
A dictionary-like object that stores secret values and prevents changes to the dictionary.
Source code in src/sosecrets/secretdicts.py
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 | |
__init__(dict=None, /, **kwargs)
Initialize a new ImmutableSecretMapping object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping |
Dict[Any, Any]
|
A dictionary with |
required |
Source code in src/sosecrets/secretdicts.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
__setitem__(key, value)
Raise an exception when attempting to set a new key-value pair in the ImmutableSecretMapping object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
Any
|
The key to set. |
required |
value |
Any
|
The value to set. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
When attempting to set a new key-value pair. |
Source code in src/sosecrets/secretdicts.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
expose_dict()
Return a new dictionary that exposes exposed information.
This method returns a new dictionary with the same keys as the original dictionary,
but with values that have been converted to exposed information using their expose_secret() method.
The expose_secret() method is expected to return a exposed version of the value.
Returns:
| Type | Description |
|---|---|
Dict[Any, Any]
|
Dict[Any, Any]: A new dictionary with exposed values. |
Source code in src/sosecrets/secretdicts.py
89 90 91 92 93 94 95 96 97 98 99 100 | |
from_func(func, *func_args, **func_kwargs)
classmethod
Create a new ImmutableSecretMapping object from the result of a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func |
callable
|
A function that returns a dictionary with |
required |
*func_args |
Any
|
Positional arguments to pass to the function. |
()
|
**func_kwargs |
Any
|
Keyword arguments to pass to the function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ImmutableSecretMapping |
ImmutableSecretMapping
|
A new ImmutableSecretMapping object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the result of the function is empty. |
Source code in src/sosecrets/secretdicts.py
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 | |
get_exposed(key, default=None)
Get the exposed value of a key in the ImmutableSecretMapping object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
Any
|
The key to get. |
required |
default |
Optional[Any]
|
The default value to return if the key is not found. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The exposed value of the key, or the default value if the key is not found. |
Source code in src/sosecrets/secretdicts.py
75 76 77 78 79 80 81 82 83 84 85 86 87 | |
MutableSecretMapping
Bases: UserDict, Mapping[Any, Secret]
A dictionary-like object that stores secret values and allows changes to the dictionary.
Source code in src/sosecrets/secretdicts.py
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
__init__(dict=None, /, **kwargs)
Initialize a new MutableSecretMapping object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping |
Dict[Any, Any]
|
A dictionary with |
required |
Source code in src/sosecrets/secretdicts.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
__setitem__(key, value)
Set a new key-value pair in the MutableSecretMapping object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
Any
|
The key to set. |
required |
value |
Any
|
The value to set. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the value is not of type |
Source code in src/sosecrets/secretdicts.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
expose_dict()
Return a new dictionary that exposes exposed information.
This method returns a new dictionary with the same keys as the original dictionary,
but with values that have been converted to exposed information using their expose_secret() method.
The expose_secret() method is expected to return a exposed version of the value.
Returns:
| Type | Description |
|---|---|
Dict[Any, Any]
|
Dict[Any, Any]: A new dictionary with exposed values. |
Source code in src/sosecrets/secretdicts.py
190 191 192 193 194 195 196 197 198 199 200 201 | |
from_func(func, *func_args, **func_kwargs)
classmethod
Create a new MutableSecretMapping object from the result of a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func |
callable
|
A function that returns a dictionary with |
required |
*func_args |
Any
|
Positional arguments to pass to the function. |
()
|
**func_kwargs |
Any
|
Keyword arguments to pass to the function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
MutableSecretMapping |
MutableSecretMapping
|
A new |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the result of the function is empty. |
Source code in src/sosecrets/secretdicts.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
get_exposed(key, default=None)
Get the exposed value of a key in the MutableSecretMapping object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
Any
|
The key to get. |
required |
default |
Optional[Any]
|
The default value to return if the key is not found. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The exposed value of the key, or the default value if the key is not found. |
Source code in src/sosecrets/secretdicts.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |