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