def download_artifact()

in TerraformScripts/sc_terraform_wrapper/__main__.py [0:0]


def download_artifact(s3, artifact_url, artifact_file_local_path, workspace_path, cleanups):
    print('Downloading artifact file')
    artifact_bucket, artifact_key = terraform_utils.get_s3_location(artifact_url)
    try:
        s3.download_file(artifact_bucket, artifact_key, artifact_file_local_path)
    except botocore.exceptions.ClientError as e:
        if e.response['Error']['Code'] == '404':
            raise Exception('Terraform config does not exist. No config found at {}'
                            .format(artifact_url))

    if zipfile.is_zipfile(artifact_file_local_path):
        with zipfile.ZipFile(artifact_file_local_path, 'r') as z:
            z.extractall(workspace_path)
        cleanups.append(('Remove downloaded artifact file', lambda: os.remove(artifact_file_local_path)))
    else:
        artifact_file_workspace_path = os.path.join(workspace_path, os.path.basename(artifact_key))
        shutil.move(artifact_file_local_path, artifact_file_workspace_path)