rs_server_osam/utils/tools.md
A collection of varied and versatile utility functions
S3StorageConfigurationSingleton
Singleton to keep the content of the config file in memory, to avoid excessive I/O operations on the file. NOTE: We use always the same config file which is bucket_expiration.csv mounted as a configmap.
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
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 | |
get_last_modification_date_of_config_file(config_file_path)
classmethod
Returns last modification time for given file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file_path
|
str
|
Path to the config file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
float
|
Last time the file was modificated. |
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
get_s3_bucket_configuration(config_file_path)
classmethod
Returns content of given CSV configuration file as a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file_path
|
str
|
Path to the CSV config file. |
required |
Returns:
| Type | Description |
|---|---|
list[list]
|
list[list]: Content of the CSV file. |
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
117 118 119 120 121 122 123 124 125 126 127 128 129 | |
load_csv_file_into_variable(config_file_path)
classmethod
To load a CSV file into the singleton. If the file given is the same one as the one already in the singleton, and if this file hasn't changed since last execution, it will do nothing. In other cases, it will load the content of the file in the singleton and update the file name and modification date values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file_path
|
str
|
Path to the config file. |
required |
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
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 | |
create_description_from_template(keycloak_user, template)
Applies the given Keycloak user name in the description, using the given template. The template must have a '%keycloak-user%' placeholder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keycloak_user
|
str
|
Keycloak user to set in the description. |
required |
template
|
(str, optionnal)
|
Template to use. Default is '## linked to keycloak user %keycloak-user%'. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Description with correct user name. |
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
160 161 162 163 164 165 166 167 168 169 170 171 | |
get_allowed_buckets(user, csv_rows)
Get the allowed buckets for user from the csv configmap
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
255 256 257 | |
get_configmap_user_values(user)
Retrieves collection, eopf_type, and bucket access values for a given user
based on rules defined in the configmap_data.
The function filters configmap_data entries where the first element
(the user specifier) matches the provided user or the wildcard "*".
It then extracts and groups the second, third, and last values from the matching rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
str
|
The username to look up in the configmap rules. |
required |
Returns:
| Type | Description |
|---|---|
|
tuple[list, list, list]: Three lists corresponding to: - collections (list): Values from the second element in matched rules. - eopf_type (list): Values from the third element in matched rules. - bucket (list): Values from the last element in matched rules. |
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
get_keycloak_user_from_description(description, template)
Returns the Keycloak user name included in the given description using its template. The template must have a '%keycloak-user%' placeholder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description
|
str
|
Description containing a Keycloak user name. |
required |
template
|
(str, optionnal)
|
Template to use. Default is '## linked to keycloak user %keycloak-user%'. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Keycloak user name or None if the conditions are not fulfilled |
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
load_configmap_data()
cached
Loads the configmap data from the CSV file specified in the environment variable or default path.
Returns:
| Type | Description |
|---|---|
|
list[list]: Content of the CSV file as a list of rows. |
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
match_roles(roles)
Matches parsed roles against a configuration map to determine S3 bucket access paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roles
|
list[tuple[str, str]]
|
List of tuples representing (owner, collection) pairs from parsed user roles. |
required |
Returns:
| Type | Description |
|---|---|
|
set[str]: Set of S3 access paths that match the given roles based on wildcards and configmap entries. |
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
parse_role(role)
Parses a Keycloak role string into owner, collection, and operation components.
This function expects the role to follow the format: <prefix>_<owner>:<collection>_<operation>.
It extracts and returns the owner, collection name, and operation (e.g., read, write, download).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role
|
str
|
Role string to be parsed. |
required |
Returns:
| Type | Description |
|---|---|
|
tuple[str, str, str] | None: A tuple (owner, collection, operation) if parsing is successful; otherwise, returns None on format error or exception. |
Source code in docs/rs-server/services/osam/rs_server_osam/utils/tools.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |