Exemple #1
0
    def cli(self, workspace_suuid: str = None, description: str = None):
        if not self.name:
            click.echo(
                "Hi! It is time to create a new project in AskAnna. "
                "We start with some information about the project.\n"
            )
            self.name = click.prompt("Project name", type=str)

            if not description:
                description = click.prompt(
                    "Project description", type=str, default="", show_default=False
                )

        if not workspace_suuid:
            workspace = ask_which_workspace("In which workspace do you want to create the new project?")
            workspace_suuid = workspace.short_uuid

        url = f"{self.client.base_url}project/"
        r = self.client.post(
            url,
            data={
                "name": self.name,
                "workspace": workspace_suuid,
                "description": description,
            },
        )
        if r.status_code == 201:
            click.echo("\nYou have successfully created a new project in AskAnna!")
            return r.json()
        else:
            raise Exception("We could not create the project.")
Exemple #2
0
def add(name, value, masked, project_suuid):
    """
    Add a variable to a project
    """

    if project_suuid:
        project = aa_project.detail(project_suuid)
        click.echo(f"Selected project: {project.name}")
    elif config.project.project_suuid:
        project = aa_project.detail(config.project.project_suuid)
        if click.confirm(
                f"\nDo you want to create a variable for project \"{project.name}\"?"
        ):
            project_suuid = project.short_uuid
            click.echo(f"Selected project: {project.name}")

    if not project_suuid:
        workspace = ask_which_workspace(
            question="In which workspace do you want to add a variable?")
        project = ask_which_project(
            question="In which project do you want to add a variable?",
            workspace_suuid=workspace.short_uuid)

    confirm = False
    if not name:
        name = click.prompt("\nName of the new variable", type=str)
        confirm = True

    if not value:
        value = click.prompt("Value of the new variable", type=str)
        confirm = True

        if not masked:
            masked = click.prompt(
                "Should the value be masked in logs and the web interface? [y/N]",
                type=bool)

    if confirm:
        click.confirm(
            f"\nDo you want to create the variable \"{name}\" in project \"{project.name}\"?",
            abort=True)

    variable, created = aa_variable.create(name=name,
                                           value=value,
                                           is_masked=masked,
                                           project_suuid=project.short_uuid)
    if created:
        click.echo(
            f"\nYou created variable \"{variable.name}\" with SUUID {variable.short_uuid} in project "
            f"\"{project.name}\"")
        sys.exit(0)
    else:
        click.echo("Something went wrong in creating the variable.", err=True)
        sys.exit(1)
Exemple #3
0
def change(suuid, name, description):
    if not suuid:
        suuid = config.project.workspace_suuid
        if not suuid:
            workspace = ask_which_workspace(
                question="Which workspace do you want to change?")
            suuid = workspace.short_uuid

    if not name and not description:
        if click.confirm("\nDo you want to change the name of the workspace?"):
            name = click.prompt("New name of the workspace", type=str)
        if click.confirm(
                "\nDo you want to change the description of the workspace?"):
            description = click.prompt("New description of the workspace",
                                       type=str)

        click.confirm("\nDo you want to change the workspace?", abort=True)

    aa_workspace.change(suuid=suuid, name=name, description=description)
Exemple #4
0
def change(suuid, name, description):
    if not suuid:
        project_suuid = config.project.project_suuid

        if not project_suuid:
            workspace = ask_which_workspace(question="From which workspace do you want to change a job?")
            project = ask_which_project(question="From which project do you want to change a job?",
                                        workspace_suuid=workspace.short_uuid)
            project_suuid = project.short_uuid

        job = ask_which_job(question="Which job do you want to change?", project_suuid=project_suuid)
        suuid = job.short_uuid

    if not name and not description:
        if click.confirm("\nDo you want to change the name of the job?"):
            name = click.prompt("New name of the job", type=str)
        if click.confirm("\nDo you want to change the description of the job?"):
            description = click.prompt("New description of the job", type=str)

        click.confirm("\nDo you want to change the job?", abort=True)

    aa_job.change(suuid=suuid, name=name, description=description)
Exemple #5
0
def determine_project(
    project_suuid: str = None,
    workspace_suuid: str = None,
) -> Project:
    if not project_suuid:
        project_suuid = config.project.project_suuid

    # Still if there is no project_suuid found, we will ask which project to use
    if project_suuid:
        project = aa_project.detail(project_suuid)
        click.echo(f"Selected project: {project.name}")
        return project
    else:
        if not workspace_suuid:
            workspace = ask_which_workspace(
                question="From which workspace do you want to run a job?")
            workspace_suuid = workspace.short_uuid

        return ask_which_project(
            question="From which project do you want to run a job?",
            workspace_suuid=workspace_suuid,
        )