Skip to content

GCP Configuration

Tracks basic GCP config information, like project name, ID, region, and service account name.

from cloudy.google import configs

GoogleCloudConfig dataclass

Configuration to ensure consistent (and correct) interfaces with Google service code.

Examples:

config = GoogleCloudConfig( project_name=salo-planetary-computer, project_id=long-semiotic-123456, project_region=us-west2 service_account_name=forest-project-x )

Attributes:

Name Type Description
project_name str

the name of the GCP project.

project_id str

the unique ID that corresponds to the project_name.

project_region str

the geographic region.

service_account_name str

the name of the service account for submitting requests.

Source code in cloudy/google/configs.py
class GoogleCloudConfig(object):
    """Configuration to ensure consistent (and correct) interfaces with Google service code.

    Example:
        config = GoogleCloudConfig(
            project_name=salo-planetary-computer,
            project_id=long-semiotic-123456,
            project_region=us-west2
            service_account_name=forest-project-x
        )

    Attributes:
      project_name (str): the name of the GCP project.
      project_id (str): the unique ID that corresponds to the project_name.
      project_region (str): the geographic region.
      service_account_name (str): the name of the service account for submitting requests.
    """

    project_name: str
    project_id: str
    service_account_name: str
    project_region: str = DEFAULT_CLOUD_TASKS_REGION

    def __post_init__(self):
        assert (
            "@" not in self.service_account_name and ".com" not in self.service_account_name
        ), "This class expects you to pass the service account name, not the service account email. It constructs the email address by referencing the project name in the Google Config. This helps to enforce the standard that service accounts should only have access to resources in their own projects, rather than also in different projects."
        self.service_account_email = "{}@{}.iam.gserviceaccount.com".format(self.service_account_name, self.project_id)
Back to top