Beispiel #1
0
def delete_customer(client: CloudChannelServiceClient, customer: types.customers.Customer) -> None:
    """Delete the Customer.

    Args:
      customer: a Customer to delete
    """
    # [START channel_delete_customer]
    request = channel.DeleteCustomerRequest(name=customer.name)

    client.delete_customer(request)

    print("=== Deleted customer")
Beispiel #2
0
def create_customer(client: CloudChannelServiceClient, account_name: str, customer_domain: str) -> Any:
    """Create the Customer resource, with a cloud identity.

    Args:
      customer_domain: primary domain used by the customer]

    Returns:
      The created Channel API Customer
    """
    # [START channel_create_customer]
    # Create the Customer resource
    request = channel.CreateCustomerRequest(
        parent=account_name,
        customer={
            "org_display_name": "Acme Corp",
            "domain": customer_domain,
            "org_postal_address": {
                "address_lines": ["1800 Amphibious Blvd"],
                "postal_code": "94045",
                "region_code": "US"
            }
        })
    # Distributors need to also pass the following field for the `customer`
    # "channel_partner_id": channel_partner_link_id

    customer = client.create_customer(request)

    print("=== Created customer")
    print(customer)
    # [END channel_create_customer]

    # [START channel_provision_cloud_identity]
    cloud_identity_info = channel.CloudIdentityInfo(
        alternate_email="*****@*****.**", language_code="en-US")

    admin_user = channel.AdminUser(
        given_name="John", family_name="Doe", email="admin@" + customer_domain)

    cloud_identity_request = channel.ProvisionCloudIdentityRequest(
        customer=customer.name,
        cloud_identity_info=cloud_identity_info,
        user=admin_user)

    # This call returns a long-running operation.
    operation = client.provision_cloud_identity(cloud_identity_request)

    # Wait for the long-running operation and get the result.
    customer = operation.result(TIMEOUT)

    print("=== Provisioned cloud identity")
    # [END channel_provision_cloud_identity]

    return customer
Beispiel #3
0
def select_offer(client: CloudChannelServiceClient, account_name: str) -> types.offers.Offer:
    """Selects a Workspace offer.

    Returns:
      A Channel API Offer for Workspace
    """
    # [START channel_select_offer]
    request = channel.ListOffersRequest(parent=account_name)
    offers = client.list_offers(request)

    # For the purpose of this codelab, the code lists all offers and selects
    # the first offer for Google Workspace Business Standard on an Annual
    # plan. This is needed because offerIds vary from one account to another,
    # but this is not a recommended model for your production integration
    sample_offer = "Google Workspace Business Standard"
    sample_plan = types.offers.PaymentPlan.COMMITMENT
    selected_offer = None
    for offer in offers:
        if offer.sku.marketing_info.display_name == sample_offer and \
          offer.plan.payment_plan == sample_plan:
            selected_offer = offer
            break

    print("=== Selected offer")
    print(selected_offer)
    # [END channel_select_offer]

    return selected_offer
Beispiel #4
0
def transfer_entitlement(client: CloudChannelServiceClient, customer: types.customers.Customer, entitlement: types.entitlements.Entitlement) -> Any:
    """Transfer the Channel API Entitlement to Google.

    Args:
      entitlement: an Entitlement to transfer

    Returns:
      google.protobuf.Empty on success
    """
    # [START channel_transfer_entitlement]
    request = channel.TransferEntitlementsToGoogleRequest(
      parent=customer.name,
      entitlements=[entitlement])

    # This call returns a long-running operation.
    operation = client.transfer_entitlements_to_google(request)

    # Wait for the long-running operation and get the result.
    result = operation.result(TIMEOUT)

    print("=== Transfered entitlement")
    print(result)
    # [END channel_transfer_entitlement]

    return result
Beispiel #5
0
def create_entitlement(client: CloudChannelServiceClient, customer: types.customers.Customer, selected_offer: types.offers.Offer) -> Any:
    """Create the Channel API Entitlement.

    Args:
      customer: a Customer resource
      selected_offer: an Offer

    Returns:
      The created Entitlement
    """
    # [START channel_create_entitlement]
    request = channel.CreateEntitlementRequest(
        parent=customer.name,
        entitlement={
            "offer": selected_offer.name,
            # Setting 5 seats for this Annual offer
            "parameters": [{
                "name": "num_units",
                "value": {
                    "int64_value": 5
                }
            }],
            "commitment_settings": {
                "renewal_settings": {
                    # Setting renewal settings to auto renew
                    "enable_renewal": True,
                    "payment_plan": "COMMITMENT",
                    "payment_cycle": {
                        "period_type": "YEAR",
                        "duration": 1
                    }
                }
            },
            # A string of up to 80 characters.
            # We recommend an internal transaction ID or
            # identifier for this customer in this field.
            "purchase_order_id": "A codelab test"
        })

    # This call returns a long-running operation.
    operation = client.create_entitlement(request)

    # Wait for the long-running operation and get the result.
    entitlement = operation.result(TIMEOUT)

    print("=== Created entitlement")
    print(entitlement)
    # [END channel_create_entitlement]

    return entitlement
Beispiel #6
0
def check_exists(client: CloudChannelServiceClient, account_name: str, customer_domain: str) -> None:
    """Determine if customer already has a cloud identity.

    Raises:
      Exception: if the domain is already in use
    """
    # [START channel_check_exists]
    # Determine if customer already has a cloud identity
    request = channel.CheckCloudIdentityAccountsExistRequest(
      parent=account_name, domain=customer_domain)

    response = client.check_cloud_identity_accounts_exist(request)

    if response.cloud_identity_accounts:
        raise Exception(
          "Cloud identity already exists. Customer must be transferred. " +
          "Out of scope for this codelab")
Beispiel #7
0
def suspend_entitlement(client: CloudChannelServiceClient, entitlement: types.entitlements.Entitlement) -> Any:
    """Suspend the Channel API Entitlement.

    Args:
      entitlement: an Entitlement to suspend

    Returns:
      The suspended Entitlement
    """
    # [START channel_suspend_entitlement]
    request = channel.SuspendEntitlementRequest(name=entitlement.name)

    # This call returns a long-running operation.
    operation = client.suspend_entitlement(request)

    # Wait for the long-running operation and get the result.
    result = operation.result(TIMEOUT)

    print("=== Suspended entitlement")
    print(result)
    # [END channel_suspend_entitlement]

    return result