Skip to content

Commit 9ed397a

Browse files
authored
Specify user agent when using the Cirro CLI & controller cleanup (#175)
* override user agent and cleanup * bump version * merge * lint
1 parent 7c8c1c6 commit 9ed397a

File tree

3 files changed

+34
-52
lines changed

3 files changed

+34
-52
lines changed

cirro/cirro_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class CirroApi:
1212
"""
1313
Client for interacting directly with the Cirro API
1414
"""
15-
def __init__(self, auth_info: AuthInfo = None, base_url: str = None):
15+
def __init__(self, auth_info: AuthInfo = None, base_url: str = None, user_agent: str = 'Cirro SDK'):
1616
"""
1717
Instantiates the Cirro API object
1818
@@ -40,7 +40,7 @@ def __init__(self, auth_info: AuthInfo = None, base_url: str = None):
4040
self._api_client = CirroApiClient(
4141
base_url=self._configuration.rest_endpoint,
4242
auth_method=auth_info.get_auth_method(),
43-
client_name='Cirro SDK',
43+
client_name=user_agent,
4444
package_name='cirro'
4545
)
4646

cirro/cli/controller.py

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from cirro.models.process import PipelineDefinition, ConfigAppStatus, CONFIG_APP_URL
2424
from cirro.services.service_helpers import list_all_datasets
2525

26-
NO_PROJECTS = "No projects available"
2726
# Log to STDOUT
2827
log_formatter = logging.Formatter(
2928
'%(asctime)s %(levelname)-8s [Cirro CLI] %(message)s'
@@ -37,13 +36,8 @@
3736

3837
def run_list_datasets(input_params: ListArguments, interactive=False):
3938
"""List the datasets available in a particular project."""
40-
_check_configure()
41-
cirro = CirroApi()
42-
logger.info(f"Collecting data from {cirro.configuration.base_url}")
43-
projects = cirro.projects.list()
44-
45-
if len(projects) == 0:
46-
raise InputError(NO_PROJECTS)
39+
cirro = _init_cirro_client()
40+
projects = _get_projects(cirro)
4741

4842
if interactive:
4943
# Prompt the user for the project
@@ -63,17 +57,10 @@ def run_list_datasets(input_params: ListArguments, interactive=False):
6357

6458

6559
def run_ingest(input_params: UploadArguments, interactive=False):
66-
_check_configure()
67-
cirro = CirroApi()
68-
logger.info(f"Collecting data from {cirro.configuration.base_url}")
60+
cirro = _init_cirro_client()
61+
projects = _get_projects(cirro)
6962
processes = cirro.processes.list(process_type=Executor.INGEST)
7063

71-
logger.info("Listing available projects")
72-
projects = cirro.projects.list()
73-
74-
if len(projects) == 0:
75-
raise InputError(NO_PROJECTS)
76-
7764
if interactive:
7865
input_params, files = gather_upload_arguments(input_params, projects, processes)
7966
directory = input_params['data_directory']
@@ -121,15 +108,8 @@ def run_ingest(input_params: UploadArguments, interactive=False):
121108

122109

123110
def run_validate_folder(input_params: ValidateArguments, interactive=False):
124-
_check_configure()
125-
cirro = CirroApi()
126-
logger.info(f"Collecting data from {cirro.configuration.base_url}")
127-
128-
logger.info("Listing available projects")
129-
projects = cirro.projects.list()
130-
131-
if len(projects) == 0:
132-
raise InputError(NO_PROJECTS)
111+
cirro = _init_cirro_client()
112+
projects = _get_projects(cirro)
133113

134114
if interactive:
135115
input_params = gather_validate_arguments(input_params, projects)
@@ -154,34 +134,27 @@ def run_validate_folder(input_params: ValidateArguments, interactive=False):
154134

155135
logger.info("Validating files")
156136

157-
validation_results = cirro.datasets.validate_folder(
137+
results = cirro.datasets.validate_folder(
158138
project_id=project_id,
159139
dataset_id=dataset_id,
160140
local_folder=input_params['data_directory']
161141
)
162142

163143
for file_list, label, log_level in [
164-
(validation_results.files_matching, "✅ Matched Files (identical in Cirro and locally)", logging.INFO),
165-
(validation_results.files_not_matching, "⚠️ Checksum Mismatches (same file name, different content)", logging.WARNING),
166-
(validation_results.files_missing, "⚠️ Missing Locally (present in system but not found locally)", logging.WARNING),
167-
(validation_results.local_only_files, "⚠️ Unexpected Local Files (present locally but not in system)", logging.WARNING),
168-
(validation_results.validate_errors, "⚠️ Validation Failed (checksums may not be available)", logging.WARNING)
144+
(results.files_matching, "✅ Matched Files (identical in Cirro and locally)", logging.INFO),
145+
(results.files_not_matching, "⚠️ Checksum Mismatches (same file name, different content)", logging.WARNING),
146+
(results.files_missing, "⚠️ Missing Locally (present in system but not found locally)", logging.WARNING),
147+
(results.local_only_files, "⚠️ Unexpected Local Files (present locally but not in system)", logging.WARNING),
148+
(results.validate_errors, "⚠️ Validation Failed (checksums may not be available)", logging.WARNING)
169149
]:
170150
logger.log(level=log_level, msg=f"{label}: {len(file_list):,}")
171151
for file in file_list:
172152
logger.log(level=log_level, msg=f" - {file}")
173153

174154

175155
def run_download(input_params: DownloadArguments, interactive=False):
176-
_check_configure()
177-
cirro = CirroApi()
178-
logger.info(f"Collecting data from {cirro.configuration.base_url}")
179-
180-
logger.info("Listing available projects")
181-
projects = cirro.projects.list()
182-
183-
if len(projects) == 0:
184-
raise InputError(NO_PROJECTS)
156+
cirro = _init_cirro_client()
157+
projects = _get_projects(cirro)
185158

186159
files_to_download = None
187160
if interactive:
@@ -229,15 +202,9 @@ def run_download(input_params: DownloadArguments, interactive=False):
229202

230203

231204
def run_upload_reference(input_params: UploadReferenceArguments, interactive=False):
232-
_check_configure()
233-
cirro = CirroApi()
234-
logger.info(f"Collecting data from {cirro.configuration.base_url}")
235-
205+
cirro = _init_cirro_client()
206+
projects = _get_projects(cirro)
236207
reference_types = cirro.references.get_types()
237-
projects = cirro.projects.list()
238-
239-
if len(projects) == 0:
240-
raise InputError(NO_PROJECTS)
241208

242209
if interactive:
243210
input_params, files = gather_reference_upload_arguments(input_params, projects, reference_types)
@@ -307,6 +274,21 @@ def run_create_pipeline_config(input_params: CreatePipelineConfigArguments, inte
307274
f"{CONFIG_APP_URL}")
308275

309276

277+
def _init_cirro_client():
278+
_check_configure()
279+
cirro = CirroApi(user_agent="Cirro CLI")
280+
logger.info(f"Collecting data from {cirro.configuration.base_url}")
281+
return cirro
282+
283+
284+
def _get_projects(cirro: CirroApi):
285+
logger.info("Listing available projects")
286+
projects = cirro.projects.list()
287+
if len(projects) == 0:
288+
raise InputError("No projects available")
289+
return projects
290+
291+
310292
def _check_configure():
311293
"""
312294
Prompts the user to do initial configuration if needed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cirro"
3-
version = "1.8.0"
3+
version = "1.9.0"
44
description = "CLI tool and SDK for interacting with the Cirro platform"
55
authors = ["Cirro Bio <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)