Beispiel #1
0
 def testValidationPassesForKmsKeyVersionInSupportedLocations(
         self, mock_fn):
     mock_fn.return_value = ['us-west1', 'europe-west1']
     for location in ['us-west1', 'europe-west1']:
         resource_ref = GetSampleCertificateAuthority(location)
         resource_args.ValidateResourceLocation(resource_ref,
                                                'CERTIFICATE_AUTHORITY')
Beispiel #2
0
def _ParseCAResourceArgs(args):
  """Parses, validates and returns the resource args from the CLI.

  Args:
    args: The parsed arguments from the command-line.

  Returns:
    Tuple containing the Resource objects for (CA, source CA, issuer).
  """
  resource_args.ValidateResourceIsCompleteIfSpecified(args, 'kms_key_version')
  resource_args.ValidateResourceIsCompleteIfSpecified(args, 'issuer')
  resource_args.ValidateResourceIsCompleteIfSpecified(args, 'from_ca')

  ca_ref = args.CONCEPTS.certificate_authority.Parse()
  resource_args.ValidateResourceLocation(ca_ref, 'CERTIFICATE_AUTHORITY')

  kms_key_version_ref = args.CONCEPTS.kms_key_version.Parse()
  if kms_key_version_ref and ca_ref.locationsId != kms_key_version_ref.locationsId:
    raise exceptions.InvalidArgumentException(
        '--kms-key-version',
        'KMS key must be in the same location as the Certificate Authority '
        '({}).'.format(ca_ref.locationsId))

  issuer_ref = args.CONCEPTS.issuer.Parse() if hasattr(args, 'issuer') else None
  source_ca_ref = args.CONCEPTS.from_ca.Parse()

  return (ca_ref, source_ca_ref, issuer_ref)
Beispiel #3
0
 def testValidationFailsForKmsKeyVersionInUnsupportedLocation(
         self, mock_fn):
     mock_fn.return_value = ['us-west1', 'europe-west1']
     resource_ref = GetSampleCertificateAuthority('us')
     with self.AssertRaisesExceptionMatches(
             exceptions.InvalidArgumentException, 'CERTIFICATE_AUTHORITY'):
         resource_args.ValidateResourceLocation(resource_ref,
                                                'CERTIFICATE_AUTHORITY')