Skip to content

project_roles

Functionality related to asking the user for GCP project roles.

ask_for_project_roles(auth_group)

Ask the user for GCP roles to which project-wide access should be granted.

Parameters:

Name Type Description Default
auth_group str

The auth group name, used for customizing the prompts

required

Returns:

Type Description
List[GCPRole]

A list of GCP roles

Source code in dapla_team_cli/tf/iam_bindings/project_roles.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def ask_for_project_roles(auth_group: str) -> List[GCPRole]:
    """Ask the user for GCP roles to which project-wide access should be granted.

    Args:
        auth_group: The auth group name, used for customizing the prompts

    Returns:
        A list of GCP roles
    """
    project_roles: List[GCPRole] = []

    if not q.confirm(f"Should {auth_group} be assigned any GCP IAM project roles?").ask():
        return project_roles

    q.print("(hit enter when done)")
    project_roles_set = set()
    role_name = ask_for_role()
    while role_name:
        project_roles_set.add(role_name)
        role_name = ask_for_role()

    project_roles = [GCPRole.parse_obj(gcp_project_roles[role]) for role in project_roles_set]

    return project_roles

ask_for_role()

Ask for one GCP role.

Source code in dapla_team_cli/tf/iam_bindings/project_roles.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def ask_for_role() -> str:
    """Ask for one GCP role."""
    choices = [str(item["name"]) for item in gcp_project_roles.values()]
    meta_information = {
        item["name"]: f"{item['title']} - {item['description']}" if item.get("description") else item["title"]
        for item in gcp_project_roles.values()
    }
    return str(
        q.autocomplete(
            message="IAM Role",
            choices=choices,
            meta_information=meta_information,
            style=prompt_custom_style,
            validate=GCPRoleValidator,
        ).ask()
    )