Skip to content

gcp

GCP specific stuff.

GCPRole

Bases: BaseModel

A GCPRole holds information about a GCP role, such as name and description.

Attributes:

Name Type Description
name str

The technical name of the GCP role, such as roles/bigquery.admin

title str

A display friendly name, such as BigQuery Admin

description str

A descriptive text that gives a short presentation of the role, such as ``Administer all BigQuery resources and data

Source code in dapla_team_cli/gcp/__init__.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class GCPRole(BaseModel):
    """A `GCPRole` holds information about a GCP role, such as name and description.

    Attributes:
        name: The technical name of the GCP role, such as `roles/bigquery.admin`
        title: A display friendly name, such as `BigQuery Admin`
        description: A descriptive text that gives a short presentation of the role,
            such as ``Administer all BigQuery resources and data
    """

    name: str
    title: str
    description: str

    def __eq__(self, __o: object) -> bool:
        """Custom equals operator, match on name."""
        if not isinstance(__o, GCPRole):
            return super().__eq__(__o)
        return self.name == __o.name

    def __lt__(self, __o: object) -> bool:
        """Implemented to support sorting."""
        if not isinstance(__o, GCPRole):
            raise NotImplementedError
        return self.name < __o.name

    def __hash__(self) -> int:
        """Implemented to support using GCPRole as a key in a dictionary."""
        return hash(self.name)

__eq__(__o)

Custom equals operator, match on name.

Source code in dapla_team_cli/gcp/__init__.py
29
30
31
32
33
def __eq__(self, __o: object) -> bool:
    """Custom equals operator, match on name."""
    if not isinstance(__o, GCPRole):
        return super().__eq__(__o)
    return self.name == __o.name

__hash__()

Implemented to support using GCPRole as a key in a dictionary.

Source code in dapla_team_cli/gcp/__init__.py
41
42
43
def __hash__(self) -> int:
    """Implemented to support using GCPRole as a key in a dictionary."""
    return hash(self.name)

__lt__(__o)

Implemented to support sorting.

Source code in dapla_team_cli/gcp/__init__.py
35
36
37
38
39
def __lt__(self, __o: object) -> bool:
    """Implemented to support sorting."""
    if not isinstance(__o, GCPRole):
        raise NotImplementedError
    return self.name < __o.name

GCPRoleValidator

Bases: Validator

Questionary Validator used for checking if the user provided GCP role is properly formatted.

Source code in dapla_team_cli/gcp/__init__.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class GCPRoleValidator(q.Validator):
    """Questionary Validator used for checking if the user provided GCP role is properly formatted."""

    def validate(self, document: Document) -> None:
        """Validate that a GCP role name is appropriately formatted.

        Args:
            document: The document to validate

        Raises:
             ValidationError: if input does not adhere to the naming convention.
        """
        ok = not document.text or "roles/" in document.text and document.text in gcp_project_roles.keys()
        if not ok:
            raise q.ValidationError(message="Please choose a GCP Role", cursor_position=len(document.text))

validate(document)

Validate that a GCP role name is appropriately formatted.

Parameters:

Name Type Description Default
document Document

The document to validate

required

Raises:

Type Description
ValidationError

if input does not adhere to the naming convention.

Source code in dapla_team_cli/gcp/__init__.py
49
50
51
52
53
54
55
56
57
58
59
60
def validate(self, document: Document) -> None:
    """Validate that a GCP role name is appropriately formatted.

    Args:
        document: The document to validate

    Raises:
         ValidationError: if input does not adhere to the naming convention.
    """
    ok = not document.text or "roles/" in document.text and document.text in gcp_project_roles.keys()
    if not ok:
        raise q.ValidationError(message="Please choose a GCP Role", cursor_position=len(document.text))