Пример #1
0
    def KubernetesConfig(self):
        """Create a kubernetes config file.

    Returns:
      Text of a kubernetes config file.
    """
        deployment = local.CreateDeployment(self._settings.service_name,
                                            self._settings.image_name)
        if self._settings.env_vars:
            local.AddEnvironmentVariables(
                deployment, self._settings.service_name + '-container',
                self._settings.env_vars)
        kubernetes_configs = [
            deployment,
            local.CreateService(self._settings.service_name)
        ]

        if self._settings.service_account:
            service_account = local.CreateDevelopmentServiceAccount(
                self._settings.service_account)
            private_key_json = local.CreateServiceAccountKey(service_account)
            secret_yaml = local.LocalDevelopmentSecretSpec(private_key_json)
            kubernetes_configs.append(secret_yaml)
            local.AddServiceAccountSecret(kubernetes_configs)

        return yaml.dump_all(kubernetes_configs)
Пример #2
0
    def testUserCancelsCreateKey(self):
        with mock.patch.object(os.path, 'exists') as mock_exists:
            mock_exists.return_value = False

            self.WriteInput('n')
            with self.assertRaises(console_io.OperationCancelledError):
                local.CreateServiceAccountKey('lalala')
Пример #3
0
  def testUseCachedKey(self):
    patch_read = mock.patch.object(files, 'ReadFileContents')
    patch_exists = mock.patch.object(os.path, 'exists')

    with patch_read as mock_read, patch_exists as mock_exists:
      mock_exists.return_Value = True
      mock_read.return_value = 'BlahBlah'

      self.assertEqual(local.CreateServiceAccountKey('lalala'), 'BlahBlah')
Пример #4
0
  def KubernetesConfig(self):
    """Create a kubernetes config file.

    Returns:
      Text of a kubernetes config file.
    """
    kubernetes_configs = local.CreatePodAndService(self._settings.service_name,
                                                   self._settings.image_name)
    if self._settings.service_account:
      service_account = local.CreateDevelopmentServiceAccount(
          self._settings.service_account)
      private_key_json = local.CreateServiceAccountKey(service_account)
      secret_yaml = local.LocalDevelopmentSecretSpec(private_key_json)
      kubernetes_configs.append(secret_yaml)
      local.AddServiceAccountSecret(kubernetes_configs)

    return yaml.dump_all(kubernetes_configs)
Пример #5
0
  def testCreateServiceAccountKey(self):
    create_key_request = (
        IAM_MESSAGE_MODULE.IamProjectsServiceAccountsKeysCreateRequest(
            name='lalala',
            createServiceAccountKeyRequest=IAM_MESSAGE_MODULE
            .CreateServiceAccountKeyRequest(
                privateKeyType=IAM_MESSAGE_MODULE.CreateServiceAccountKeyRequest
                .PrivateKeyTypeValueValuesEnum.TYPE_GOOGLE_CREDENTIALS_FILE)))
    self.mock_iam_client.projects_serviceAccounts_keys.Create.Expect(
        create_key_request,
        response=IAM_MESSAGE_MODULE.ServiceAccountKey(privateKeyData=b'blah'))

    patch_write = mock.patch.object(files, 'WriteFileContents')
    patch_exists = mock.patch.object(os.path, 'exists')

    with patch_write as mock_write, patch_exists as mock_exists:
      mock_exists.return_value = False

      self.assertEqual(local.CreateServiceAccountKey('lalala'), 'blah')
      mock_write.assert_called_with(mock.ANY, b'blah')