def testGenerateServiceIdentityCall_PermissionDenied(self):
    """Test EnableApiCall returns operation when successful."""
    server_error = http_error.MakeDetailedHttpError(code=403, message='Error.')
    self.ExpectGenerateServiceIdentityCall(None, None, error=server_error)

    with self.assertRaisesRegex(
        exceptions.GenerateServiceIdentityPermissionDeniedException, r'Error.'):
      serviceusage.GenerateServiceIdentity(self.PROJECT_NAME,
                                           self.DEFAULT_SERVICE)
  def testGenerateServiceIdentityCall_Success(self):
    """Test EnableApiCall returns operation when successful."""
    email = '*****@*****.**'
    unique_id = 'hello-uid'
    self.ExpectGenerateServiceIdentityCall(email, unique_id)

    got_email, got_unique_id = serviceusage.GenerateServiceIdentity(
        self.PROJECT_NAME, self.DEFAULT_SERVICE)

    self.assertEqual(got_email, email)
    self.assertEqual(got_unique_id, unique_id)
Exemple #3
0
def GetOrCreate(project_ref):
  """Gets (or creates) the P4SA for Private CA in the given project.

  If the P4SA does not exist for this project, it will be created. Otherwise,
  the email address of the existing P4SA will be returned.

  Args:
    project_ref: resources.Resource reference to the project for the P4SA.

  Returns:
    Email address of the Private CA P4SA for the given project.
  """
  service_name = privateca_base.GetServiceName()
  email, _ = serviceusage.GenerateServiceIdentity(project_ref.Name(),
                                                  service_name)
  return email
Exemple #4
0
  def Run(self, args):
    """Run 'services identity create'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
        with.

    Returns:
      Nothing.
    """
    project = properties.VALUES.core.project.Get(required=True)
    email, _ = serviceusage.GenerateServiceIdentity(project, args.service)
    if not email:
      raise exceptions.Error('Service identity not created successfully')
    else:
      log.status.Print('Service identity created: {0}'.format(email))
def _GetOrCreateP4SA(service_name):
    """Gets (or creates) the P4SA for Eventarc in the given project.

  If the P4SA does not exist for this project, it will be created. Otherwise,
  the email address of the existing P4SA will be returned.

  Args:
    service_name: str, name of the service for the P4SA, e.g.
      eventarc.googleapis.com

  Returns:
    Email address of the Eventarc P4SA for the given project.
  """
    project_name = properties.VALUES.core.project.Get(required=True)
    response = serviceusage.GenerateServiceIdentity(project_name, service_name)
    return response['email']
    def Run(self, args):
        """Run 'services identity create'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
        with.

    Returns:
      response with service identity email and uniqueId.
    """
        project = properties.VALUES.core.project.Get(required=True)
        response = serviceusage.GenerateServiceIdentity(project, args.service)
        if 'email' not in response:
            # Print generic message when email not provided in response.
            # Error in GenerateServiceIdentity indicated by thrown exception.
            log.status.Print('Service identity created')
        else:
            log.status.Print('Service identity created: {0}'.format(
                response['email']))
        return response