Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmlutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ def __init__(
api_key: str,
ca_path: str,
project_slug: str,
skip_tls_verification: bool = False,
) -> None:
self.host = host
self.username = username
self.project_name = project_name
self.api_key = api_key
self.ca_path = ca_path
self.project_slug = project_slug
self.skip_tls_verification = skip_tls_verification

@property
def apiv2_key(self) -> str:
Expand All @@ -42,6 +44,7 @@ def apiv2_key(self) -> str:
api_key=self.api_key,
json_data=json_data,
ca_path=self.ca_path,
skip_tls_verification=self.skip_tls_verification,
)
response_dict = response.json()
_apiv2_key = response_dict["apiKey"]
Expand Down
8 changes: 4 additions & 4 deletions cmlutils/cdswctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def _get_cdswctl_download_url(host: str) -> str:
return final_url


def _download_and_extract(url: str, ca_path: str):
def _download_and_extract(url: str, ca_path: str, skip_tls_verification: bool = False):
file_name = url.split("/")[-1]
dir_path = _cdswctl_tmp_dir_path()
file_path = os.path.join(dir_path, file_name)
download_file(url=url, filepath=file_path, ca_path=ca_path)
download_file(url=url, filepath=file_path, ca_path=ca_path, skip_tls_verification=skip_tls_verification)
if Path(constants.BASE_PATH_CDSWCTL) in Path(dir_path).parents:
tf = tarfile.open(file_path)
tf.extractall(dir_path)
Expand All @@ -51,9 +51,9 @@ def _cdswctl_tmp_dir_path() -> str:
return dirpath


def obtain_cdswctl(host: str, ca_path: str) -> str:
def obtain_cdswctl(host: str, ca_path: str, skip_tls_verification: bool = False) -> str:
file_url = _get_cdswctl_download_url(host)
expected_cdswctl_path = _download_and_extract(file_url, ca_path=ca_path)
expected_cdswctl_path = _download_and_extract(file_url, ca_path=ca_path, skip_tls_verification=skip_tls_verification)
logging.info(
"Expected cdsw path for cdswctl for file transfer %s", expected_cdswctl_path
)
Expand Down
3 changes: 2 additions & 1 deletion cmlutils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
OUTPUT_DIR_KEY = "output_dir"
PROJECT_NAME_KEY = "project_name"
CA_PATH_KEY = "ca_path"
SKIP_TLS_VERIFICATION_KEY = "skip_tls_verification"
MAX_API_PAGE_LENGTH = 30


Expand Down Expand Up @@ -56,7 +57,7 @@ class ApiV1Endpoints(Enum):
API_KEY = "/api/v1/users/$username/apikey"
RUNTIMES = "/api/v1/runtimes"
USER_INFO = "/api/v1/users/$username"
PROJECTS_SUMMARY = "/api/v1/users/$username/projects-summary?all=true&context=$username&sortColumn=updated_at&projectName=$projectName&limit=$limit&offset=$offset"
PROJECTS_SUMMARY = "/api/v1/users/$username/projects-summary?all=true&scope=all&context=$username&sortColumn=updated_at&projectName=$projectName&limit=$limit&offset=$offset"


"""Mapping of old fields v1 to new fields of v2"""
Expand Down
11 changes: 11 additions & 0 deletions cmlutils/project_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def _read_config_file(file_path: str, project_name: str):
print("Key %s is missing from config file." % (key))
raise
output_config[CA_PATH_KEY] = config.get(project_name, CA_PATH_KEY, fallback="")
output_config[constants.SKIP_TLS_VERIFICATION_KEY] = config.getboolean(
project_name, constants.SKIP_TLS_VERIFICATION_KEY, fallback=False
)
return output_config
else:
print("Validation error: cannot find config file:", file_path)
Expand Down Expand Up @@ -103,6 +106,7 @@ def project_export_cmd(project_name):
apiv1_key = config[API_V1_KEY]
output_dir = config[OUTPUT_DIR_KEY]
ca_path = config[CA_PATH_KEY]
skip_tls_verification = config[constants.SKIP_TLS_VERIFICATION_KEY]

output_dir = get_absolute_path(output_dir)
ca_path = get_absolute_path(ca_path)
Expand All @@ -121,6 +125,7 @@ def project_export_cmd(project_name):
ca_path=ca_path,
project_slug=project_name,
owner_type="",
skip_tls_verification=skip_tls_verification,
)
creator_username, project_slug, owner_type = pobj.get_creator_username()
if creator_username is None:
Expand All @@ -139,6 +144,7 @@ def project_export_cmd(project_name):
apiv1_key=apiv1_key,
ca_path=ca_path,
project_slug=project_slug,
skip_tls_verification=skip_tls_verification,
)
for v in validators:
validation_response = v.validate()
Expand All @@ -164,6 +170,7 @@ def project_export_cmd(project_name):
ca_path=ca_path,
project_slug=project_slug,
owner_type=owner_type,
skip_tls_verification=skip_tls_verification,
)
start_time = time.time()
pexport.transfer_project_files(log_filedir=log_filedir)
Expand Down Expand Up @@ -225,6 +232,7 @@ def project_import_cmd(project_name, verify):
apiv1_key = config[API_V1_KEY]
local_directory = config[OUTPUT_DIR_KEY]
ca_path = config[CA_PATH_KEY]
skip_tls_verification = config[constants.SKIP_TLS_VERIFICATION_KEY]
local_directory = get_absolute_path(local_directory)
ca_path = get_absolute_path(ca_path)
log_filedir = os.path.join(local_directory, project_name, "logs")
Expand All @@ -238,6 +246,7 @@ def project_import_cmd(project_name, verify):
top_level_dir=local_directory,
ca_path=ca_path,
project_slug=project_name,
skip_tls_verification=skip_tls_verification,
)
logging.info("Started importing project: %s", project_name)
try:
Expand All @@ -248,6 +257,7 @@ def project_import_cmd(project_name, verify):
top_level_directory=local_directory,
apiv1_key=apiv1_key,
ca_path=ca_path,
skip_tls_verification=skip_tls_verification,
)
logging.info("Begin validating for import.")
for v in validators:
Expand Down Expand Up @@ -296,6 +306,7 @@ def project_import_cmd(project_name, verify):
top_level_dir=local_directory,
ca_path=ca_path,
project_slug=project_slug,
skip_tls_verification=skip_tls_verification,
)
start_time = time.time()
if verify:
Expand Down
Loading