github.com/treeverse/lakefs@v1.24.1-0.20240520134607-95648127bfb0/clients/python-legacy/templates/client.mustache (about) 1 import warnings 2 3 from urllib3.util import parse_url, Url 4 5 import lakefs_client.apis 6 {{#apiInfo}} 7 {{#apis}} 8 from {{apiPackage}} import {{classFilename}} 9 {{/apis}} 10 {{/apiInfo}} 11 12 13 class _WrappedApiClient(lakefs_client.ApiClient): 14 """ApiClient that fixes some weirdness""" 15 16 # Wrap files_parameters to work with unnamed "files" (e.g. MemIOs). 17 def files_parameters(self, files=None): 18 if files is not None: 19 for (param_name, file_instances) in files.items(): 20 i = 0 21 if file_instances is None: 22 continue 23 for file_instance in file_instances: 24 if file_instance is not None and not hasattr(file_instance, 'name'): 25 # Generate a fake name. 26 i += 1 27 file_instance.name = f'{param_name}{i}' 28 return super().files_parameters(files) 29 30 31 class LakeFSClient: 32 def __init__(self, configuration=None, header_name=None, header_value=None, cookie=None, pool_threads=1): 33 configuration = LakeFSClient._ensure_endpoint(configuration) 34 self._api = _WrappedApiClient(configuration=configuration, header_name=header_name, 35 header_value=header_value, cookie=cookie, pool_threads=pool_threads) 36 {{#apiInfo}} 37 {{#apis}} 38 self.{{classFilename}} = {{classFilename}}.{{{classname}}}(self._api) 39 {{/apis}} 40 {{/apiInfo}} 41 42 @staticmethod 43 def _ensure_endpoint(configuration): 44 """Normalize lakefs connection endpoint found in configuration's host""" 45 if not configuration or not configuration.host: 46 return configuration 47 try: 48 # prefix http scheme if missing 49 if not configuration.host.startswith('http://') and not configuration.host.startswith('https://'): 50 configuration.host = 'http://' + configuration.host 51 # if 'host' not set any 'path', format the endpoint url with default 'path' based on the generated code 52 o = parse_url(configuration.host) 53 if not o.path or o.path == '/': 54 settings = configuration.get_host_settings() 55 if settings: 56 base_path = parse_url(settings[0].get('url')).path 57 configuration.host = Url(scheme=o.scheme, auth=o.auth, host=o.host, port=o.port, 58 path=base_path, query=o.query, fragment=o.fragment).url 59 except ValueError: 60 pass 61 return configuration 62 63 @property 64 def actions(self): 65 warnings.warn("Deprecated property. Use actions_api instead.", DeprecationWarning) 66 return self.actions_api 67 68 @property 69 def auth(self): 70 warnings.warn("Deprecated property. Use auth_api instead.", DeprecationWarning) 71 return self.auth_api 72 73 @property 74 def branches(self): 75 warnings.warn("Deprecated property. Use branches_api instead.", DeprecationWarning) 76 return self.branches_api 77 78 @property 79 def commits(self): 80 warnings.warn("Deprecated property. Use commits_api instead.", DeprecationWarning) 81 return self.commits_api 82 83 @property 84 def config(self): 85 warnings.warn("Deprecated property. Use config_api instead.", DeprecationWarning) 86 return self.config_api 87 88 @property 89 def experimental(self): 90 warnings.warn("Deprecated property. Use experimental_api instead.", DeprecationWarning) 91 return self.experimental_api 92 93 @property 94 def health_check(self): 95 warnings.warn("Deprecated property. Use health_check_api instead.", DeprecationWarning) 96 return self.health_check_api 97 98 @property 99 def metadata(self): 100 warnings.warn("Deprecated property. Use metadata_api instead.", DeprecationWarning) 101 return self.metadata_api 102 103 @property 104 def objects(self): 105 warnings.warn("Deprecated property. Use objects_api instead.", DeprecationWarning) 106 return self.objects_api 107 108 @property 109 def otf_diff(self): 110 warnings.warn("Deprecated property. Use otf_diff_api instead.", DeprecationWarning) 111 return self.otf_diff_api 112 113 @property 114 def refs(self): 115 warnings.warn("Deprecated property. Use refs_api instead.", DeprecationWarning) 116 return self.refs_api 117 118 @property 119 def repositories(self): 120 warnings.warn("Deprecated property. Use repositories_api instead.", DeprecationWarning) 121 return self.repositories_api 122 123 @property 124 def retention(self): 125 warnings.warn("Deprecated property. Use retention_api instead.", DeprecationWarning) 126 return self.retention_api 127 128 @property 129 def staging(self): 130 warnings.warn("Deprecated property. Use staging_api instead.", DeprecationWarning) 131 return self.staging_api 132 133 @property 134 def statistics(self): 135 warnings.warn("Deprecated property. Use statistics_api instead.", DeprecationWarning) 136 return self.statistics_api 137 138 @property 139 def tags(self): 140 warnings.warn("Deprecated property. Use tags_api instead.", DeprecationWarning) 141 return self.tags_api 142 143 @property 144 def templates(self): 145 warnings.warn("Deprecated property. Use templates_api instead.", DeprecationWarning) 146 return self.templates_api