Exemple #1
0
def audit_list(deployment_name, pipeline_name, format_, **kwargs):
    """List the audit events.

    Use the command options as filters.
    """

    project_name = get_current_project(error=True)
    client = init_client()

    if deployment_name and pipeline_name:
        raise Exception(
            "Please, filter either on deployment or pipeline name, not both")
    elif deployment_name:
        events = client.deployment_audit_events_list(
            project_name=project_name,
            deployment_name=deployment_name,
            **kwargs)
    elif pipeline_name:
        events = client.pipeline_audit_events_list(project_name=project_name,
                                                   pipeline_name=pipeline_name,
                                                   **kwargs)
    else:
        events = client.project_audit_events_list(project_name=project_name,
                                                  **kwargs)
    client.api_client.close()

    print_list(events, ['date', 'action', 'user', 'event'],
               fmt=format_,
               pager=len(events) > 10)
def pipeline_versions_list(pipeline_name, labels, format_):
    """
    List the versions of a pipeline.

    The `<labels>` option can be used to filter on specific labels.
    """

    label_filter = get_label_filter(labels)

    project_name = get_current_project(error=True)

    client = init_client()
    default = client.pipelines_get(project_name=project_name,
                                   pipeline_name=pipeline_name).default_version
    response = client.pipeline_versions_list(project_name=project_name,
                                             pipeline_name=pipeline_name,
                                             labels=label_filter)
    client.api_client.close()

    if format_ == 'table':
        # Add [DEFAULT] to default version
        for i in response:
            if default and hasattr(i, 'version') and i.version == default:
                i.version = f"{i.version} {click.style('[DEFAULT]', fg='yellow')}"

    print_list(items=response,
               attrs=LIST_ITEMS,
               rename_cols={
                   'version': 'version_name',
                   **PIPELINE_VERSION_FIELDS_RENAMED
               },
               sorting_col=0,
               fmt=format_)
def env_vars_list(deployment_name, version_name, format_):
    """
    List environment variables.

    \b
    - When deployment_name and version_name are provided: the environment variables will be listed on deployment
    version level.
    - When a deployment name is provided, but not a version name: the environment variables will be listed on
    deployment level.
    - When no deployment_name nor a version name is provided: the environment variables will be listed on project level.
    """

    project_name = get_current_project(error=True)

    if version_name and not deployment_name:
        raise Exception("Missing option <deployment_name>")

    client = init_client()
    if version_name:
        response = client.deployment_version_environment_variables_list(
            project_name=project_name,
            deployment_name=deployment_name,
            version=version_name)
    elif deployment_name:
        response = client.deployment_environment_variables_list(
            project_name=project_name, deployment_name=deployment_name)
    else:
        response = client.project_environment_variables_list(
            project_name=project_name)
    client.api_client.close()

    print_list(response, LIST_ITEMS, sorting_col=1, fmt=format_)
Exemple #4
0
def deprecated_batch_requests_list(deployment_name, version_name, offset, limit, format_):
    """
    [DEPRECATED] List deployment batch requests.
    Deployment requests are only stored for deployment versions with `request_retention_mode` 'full' or 'metadata'.

    Use the version option to list the batch requests for a specific deployment version.
    If not specified, the batch requests are listed for the default version.
    """

    if format_ != 'json':
        click.secho(
            "Deprecation warning: 'batch_requests list' is deprecated, use 'requests list' instead",
            fg='red'
        )

    project_name = get_current_project(error=True)

    client = init_client()
    if version_name is not None:
        response = client.deployment_version_requests_list(
            project_name=project_name, deployment_name=deployment_name, version=version_name, limit=limit, offset=offset
        )
    else:
        response = client.deployment_requests_list(
            project_name=project_name, deployment_name=deployment_name, limit=limit, offset=offset
        )
    client.api_client.close()

    print_list(response, REQUEST_LIST_ITEMS, fmt=format_)
    if len(response) == limit:
        click.echo("\n(Use the <offset> and <limit> options to load more)")
def env_vars_create(env_var_name, env_var_value, secret, deployment_name,
                    version_name, yaml_file, format_):
    """
    Create an environment variable.

    \b
    - When deployment_name and version_name are provided: the environment variable will be created on deployment
    version level.
    - When a deployment name is provided, but not a version name: the environment variable will be created on
    deployment level.
    - When no deployment_name nor a version name is provided: the environment variable will be created on project level.

    \b
    It is possible to create multiple environment variables at ones by passing a yaml file.
    The structure of this file is assumed to look like:
    ```
    environment_variables:
      - name: env_var_1
        value: value_1
      - name: env_var_2
        value: value_2
        secret: true
      - name: env_var_3
        value: value_3
        secret: true
    ```
    The 'secret' parameter is optional, and is `false` by default.
    """

    project_name = get_current_project(error=True)

    if not yaml_file and not env_var_name:
        raise Exception(
            "Please, specify the environment variable in either a yaml file or as a command argument"
        )
    if yaml_file and (env_var_name or env_var_value or secret):
        raise Exception(
            "Please, use either a yaml file or command options, not both")
    if version_name and not deployment_name:
        raise Exception("Missing option <deployment_name>")

    if yaml_file:
        yaml_content = read_yaml(yaml_file,
                                 required_fields=['environment_variables'])
        check_required_fields(input_dict=yaml_content,
                              list_name='environment_variables',
                              required_fields=['name', 'value'])

        items = []
        for env_var in yaml_content['environment_variables']:
            secret = env_var['secret'] if 'secret' in env_var else False
            item = create_env_var(project_name, deployment_name, version_name,
                                  env_var['name'], env_var['value'], secret)
            items.append(item)
        print_list(items, LIST_ITEMS, fmt=format_)
    else:
        item = create_env_var(project_name, deployment_name, version_name,
                              env_var_name, env_var_value, secret)
        print_item(item, LIST_ITEMS, fmt=format_)
def revisions_list(deployment_name, version_name, format_):
    """
    List the revisions of a deployment version.
    """

    project_name = get_current_project(error=True)

    client = init_client()
    response = client.revisions_list(project_name=project_name, deployment_name=deployment_name, version=version_name)
    client.api_client.close()

    print_list(response, LIST_ITEMS, sorting_col=0, fmt=format_)
Exemple #7
0
def exports_list(status, format_):
    """
    List all your exports in your project.

    The `<status>` option can be used to filter on specific statuses.
    """

    project_name = get_current_project()
    if project_name:
        client = init_client()
        exports = client.exports_list(project_name=project_name, status=status)
        client.api_client.close()
        print_list(items=exports, attrs=LIST_ITEMS, sorting_col=1, sorting_reverse=True, fmt=format_)
Exemple #8
0
def schedules_list(format_):
    """List request schedules in project."""

    project_name = get_current_project(error=True)

    client = init_client()
    response = client.request_schedules_list(project_name=project_name)
    client.api_client.close()

    print_list(response,
               LIST_ITEMS,
               rename_cols=RENAME_COLUMNS,
               sorting_col=1,
               fmt=format_)
Exemple #9
0
def blobs_list(format_):
    """List blobs in project."""

    project_name = get_current_project(error=True)

    client = init_client()
    response = client.blobs_list(project_name=project_name)
    client.api_client.close()

    print_list(response,
               LIST_ITEMS,
               rename_cols={'ttl': 'time_to_live'},
               sorting_col=2,
               fmt=format_)
def requests_list(pipeline_name, version_name, limit, format_, **kwargs):
    """
    List pipeline requests.
    Pipeline requests are only stored for pipeline versions with `request_retention_mode` 'full' or 'metadata'.

    Use the version option to list the requests for a specific pipeline version.
    If not specified, the requests are listed for the default version.
    """

    project_name = get_current_project(error=True)

    if 'start_date' in kwargs and kwargs['start_date']:
        try:
            kwargs['start_date'] = format_datetime(parse_datetime(
                kwargs['start_date']),
                                                   fmt='%Y-%m-%dT%H:%M:%SZ')
        except ValueError:
            raise Exception(
                "Failed to parse start_date. Please use iso-format, "
                "for example, '2020-01-01T00:00:00.000000Z'")

    if 'end_date' in kwargs and kwargs['end_date']:
        try:
            kwargs['end_date'] = format_datetime(parse_datetime(
                kwargs['end_date']),
                                                 fmt='%Y-%m-%dT%H:%M:%SZ')
        except ValueError:
            raise Exception("Failed to parse end_date. Please use iso-format, "
                            "for example, '2020-01-01T00:00:00.000000Z'")

    client = init_client()
    if version_name is not None:
        response = client.pipeline_version_requests_list(
            project_name=project_name,
            pipeline_name=pipeline_name,
            version=version_name,
            limit=limit,
            **kwargs)

    else:
        response = client.pipeline_requests_list(project_name=project_name,
                                                 pipeline_name=pipeline_name,
                                                 limit=limit,
                                                 **kwargs)

    client.api_client.close()
    print_list(response, REQUEST_LIST_ITEMS, fmt=format_)
    if len(response) == limit:
        click.echo("\n(Use the <offset> and <limit> options to load more)")
Exemple #11
0
def deployments_list(labels, format_):
    """
    List all your deployments in your project.

    The `<labels>` option can be used to filter on specific labels.
    """

    label_filter = get_label_filter(labels)

    project_name = get_current_project()
    if project_name:
        client = init_client()
        deployments = client.deployments_list(project_name=project_name, labels=label_filter)
        client.api_client.close()
        print_list(items=deployments, attrs=LIST_ITEMS, sorting_col=1, fmt=format_)
def pipelines_list(labels, format_):
    """
    List pipelines in project.

    The <labels> option can be used to filter on specific labels.
    """

    label_filter = get_label_filter(labels)

    project_name = get_current_project(error=True)
    if project_name:
        client = init_client()
        pipelines = client.pipelines_list(project_name=project_name,
                                          labels=label_filter)
        print_list(pipelines, LIST_ITEMS, sorting_col=1, fmt=format_)
        client.api_client.close()
def env_vars_copy(from_deployment, from_version, to_deployment, to_version,
                  assume_yes):
    """
    Copy environment variables from one deployment (version) to another deployment (version).
    """
    project_name = get_current_project(error=True)
    client = init_client()

    if from_version is None:
        data = api.EnvironmentVariableCopy(source_deployment=from_deployment)
        env_vars = client.deployment_environment_variables_list(
            project_name=project_name, deployment_name=from_deployment)
    else:
        data = api.EnvironmentVariableCopy(source_deployment=from_deployment,
                                           source_version=from_version)
        env_vars = client.deployment_version_environment_variables_list(
            project_name=project_name,
            deployment_name=from_deployment,
            version=from_version)

    if not assume_yes:
        env_vars = [env for env in env_vars if env.inheritance_type is None]
        print_list(env_vars, ['id', 'name', 'value', 'secret'],
                   sorting_col=1,
                   fmt='table')
        click.echo("\n%s" % click.style(
            "All destination variables with the same name "
            "will be overwritten by this action",
            fg='yellow'))

    confirm_message = "Are you sure you want to copy %s these environment variables?" % click.style(
        "ALL", fg='red')

    if assume_yes or click.confirm(confirm_message):
        if to_version is None:
            client.deployment_environment_variables_copy(
                project_name=project_name,
                deployment_name=to_deployment,
                data=data)
        else:
            client.deployment_version_environment_variables_copy(
                project_name=project_name,
                deployment_name=to_deployment,
                version=to_version,
                data=data)
    client.api_client.close()