|
| 1 | +""" |
| 2 | +config.py |
| 3 | +
|
| 4 | +Authors: Rasmus Welander, Diogo Castro, Giuseppe Lo Presti. |
| 5 | + |
| 6 | +Last updated: 29/07/2024 |
| 7 | +""" |
| 8 | + |
| 9 | +from configparser import ConfigParser |
| 10 | + |
| 11 | + |
| 12 | +class Config: |
| 13 | + """ |
| 14 | + A class to read and store the configuration parameters provided to the CS3 client. |
| 15 | + """ |
| 16 | + |
| 17 | + def __init__(self, config: ConfigParser, config_category: str) -> None: |
| 18 | + """ |
| 19 | + Initializes the Config class with the configuration parameters. |
| 20 | +
|
| 21 | + :param config: Dictionary containing configuration parameters. |
| 22 | + :param config_category: The category of the configuration parameters. |
| 23 | + """ |
| 24 | + self._config_category: str = config_category |
| 25 | + self._config: ConfigParser = config |
| 26 | + |
| 27 | + @property |
| 28 | + def host(self) -> str: |
| 29 | + """ |
| 30 | + The host property returns the host address and port from the configuration. |
| 31 | +
|
| 32 | + :return: host address:port |
| 33 | + """ |
| 34 | + return self._config.get(self._config_category, "host") |
| 35 | + |
| 36 | + @property |
| 37 | + def chunk_size(self) -> int: |
| 38 | + """ |
| 39 | + The chunk_size property returns the chunk_size value from the configuration, |
| 40 | + fallback to 4194304 if not present. |
| 41 | +
|
| 42 | + :return: The chunk size value. |
| 43 | + """ |
| 44 | + return self._config.getint(self._config_category, "chunk_size", fallback=4194304) |
| 45 | + |
| 46 | + @property |
| 47 | + def grpc_timeout(self) -> int: |
| 48 | + """ |
| 49 | + The grpc_timeout property returns the grpc_timeout value from the configuration, |
| 50 | + fallback to 10 if not present. |
| 51 | +
|
| 52 | + :return: The grpc timeout value. |
| 53 | + """ |
| 54 | + return self._config.getint(self._config_category, "grpc_timeout", fallback=10) |
| 55 | + |
| 56 | + @property |
| 57 | + def http_timeout(self) -> int: |
| 58 | + """ |
| 59 | + The http_timeout property returns the http_timeout value from the configuration, |
| 60 | + fallback to 10 if not present. |
| 61 | +
|
| 62 | + :return: The http timeout value. |
| 63 | + """ |
| 64 | + return self._config.getint(self._config_category, "http_timeout", fallback=10) |
| 65 | + |
| 66 | + @property |
| 67 | + def ssl_enabled(self) -> bool: |
| 68 | + """ |
| 69 | + The ssl_enabled property returns the ssl_enabled value from the configuration, |
| 70 | + fallback to True if not present. |
| 71 | +
|
| 72 | + :return: ssl_enabled value. |
| 73 | + """ |
| 74 | + return self._config.getboolean(self._config_category, "ssl_enabled", fallback=False) |
| 75 | + |
| 76 | + @property |
| 77 | + def ssl_verify(self) -> bool: |
| 78 | + """ |
| 79 | + The ssl_verify property returns the ssl_verify value from the configuration, |
| 80 | +
|
| 81 | + :return: ssl_verify |
| 82 | + """ |
| 83 | + return self._config.getboolean(self._config_category, "ssl_verify", fallback=False) |
| 84 | + |
| 85 | + @property |
| 86 | + def ssl_client_cert(self) -> str: |
| 87 | + """ |
| 88 | + The ssl_client_cert property returns the ssl_client_cert value from the configuration, |
| 89 | + if not present, fallback to an empty string since it is not required if ssl is not enabled. |
| 90 | +
|
| 91 | + :return: ssl_client_cert |
| 92 | + """ |
| 93 | + return self._config.get(self._config_category, "ssl_client_cert", fallback=None) |
| 94 | + |
| 95 | + @property |
| 96 | + def ssl_client_key(self) -> str: |
| 97 | + """ |
| 98 | + The ssl_client_key property returns the ssl_client_key value from the configuration, |
| 99 | + if not present, fallback to an empty string since it is not required if ssl is not enabled. |
| 100 | +
|
| 101 | + :return: ssl_client_key |
| 102 | + """ |
| 103 | + return self._config.get(self._config_category, "ssl_client_key", fallback=None) |
| 104 | + |
| 105 | + @property |
| 106 | + def ssl_ca_cert(self) -> str: |
| 107 | + """ |
| 108 | + The ssl_ca_cert property returns the ssl_ca_cert value from the configuration, |
| 109 | + if not present, fallback to an empty string since it is not required if ssl is not enabled. |
| 110 | +
|
| 111 | + :return: ssl_ca_cert |
| 112 | + """ |
| 113 | + return self._config.get(self._config_category, "ssl_ca_cert", fallback=None) |
| 114 | + |
| 115 | + @property |
| 116 | + def auth_login_type(self) -> str: |
| 117 | + """ |
| 118 | + The auth_login_type property returns the auth_login_type value from the configuration. |
| 119 | + e.g. basic, bearer, oauth, machine. |
| 120 | +
|
| 121 | + :return: auth_login_type |
| 122 | + """ |
| 123 | + return self._config.get(self._config_category, "auth_login_type", fallback="basic") |
| 124 | + |
| 125 | + @property |
| 126 | + def auth_client_id(self) -> str: |
| 127 | + """ |
| 128 | + The auth_client_id property returns the auth_client_id value from the configuration, |
| 129 | +
|
| 130 | + :return: auth_client_id |
| 131 | + """ |
| 132 | + return self._config.get(self._config_category, "auth_client_id", fallback=None) |
| 133 | + |
| 134 | + @property |
| 135 | + def tus_enabled(self) -> bool: |
| 136 | + """ |
| 137 | + The tus_enabled property returns the tus_enabled value from the configuration, |
| 138 | +
|
| 139 | + :return: tus_enabled |
| 140 | + """ |
| 141 | + return self._config.getboolean(self._config_category, "tus_enabled", fallback=False) |
| 142 | + |
| 143 | + # For the lock implementation |
| 144 | + @property |
| 145 | + def lock_by_setting_attr(self) -> bool: |
| 146 | + """ |
| 147 | + The lock_by_setting_attr property returns the lock_by_setting_attr value from the configuration, |
| 148 | + fallback to False if not present. |
| 149 | +
|
| 150 | + The lock by setting attribute setting should be set if the storage provider does not |
| 151 | + implement locking functionality. In which case the client will use the fallback mechanism |
| 152 | + by locking resources by setting metadata attributes. If lock_not_impl is set to false and |
| 153 | + lock_by_setting_attr is set to true, the client will attempt to lock normally first, |
| 154 | + and if that fails, it will attempt to lock by setting metadata attributes. |
| 155 | +
|
| 156 | +
|
| 157 | + :return: lock_by_setting_attr |
| 158 | + """ |
| 159 | + return self._config.getboolean(self._config_category, "lock_by_setting_attr", fallback=False) |
| 160 | + |
| 161 | + # For the lock implementation |
| 162 | + @property |
| 163 | + def lock_not_impl(self) -> bool: |
| 164 | + """ |
| 165 | + The lock_not_impl property returns the lock_not_impl value from the configuration, |
| 166 | + fallback to False if not present. |
| 167 | +
|
| 168 | + The lock not implemented setting should be set if the storage provider |
| 169 | + does not implement locking functionality. In which case the client will use the |
| 170 | + fallback mechanism by locking resources by setting metadata attributes if the |
| 171 | + lock_by_setting_attr is set to True. |
| 172 | +
|
| 173 | + :return: lock_not_impl |
| 174 | + """ |
| 175 | + return self._config.getboolean(self._config_category, "lock_not_impl", fallback=False) |
| 176 | + |
| 177 | + # For the lock implementation |
| 178 | + @property |
| 179 | + def lock_expiration(self) -> int: |
| 180 | + """ |
| 181 | + The lock_expiration property returns the lock_expiration value from the configuration, |
| 182 | + fallback to 1800 if not present. |
| 183 | +
|
| 184 | + The lock expiration setting is used to determine the time |
| 185 | + in seconds before a lock is considered expired. |
| 186 | +
|
| 187 | + :return: lock_expiration |
| 188 | + """ |
| 189 | + return self._config.getint(self._config_category, "lock_expiration", fallback=1800) |
0 commit comments