Ejemplo n.º 1
0
 def testCertificateAuthorityInUnsupportedLocationRaisesException(self, _):
     args = self.parser.parse_args([
         'new-ca',
         '--location=us-central1',
         '--kms-key-version',
         _KmsKeyVersion(location='us-central1'),
     ] + self.other_args)
     with self.AssertRaisesExceptionMatches(
             exceptions.InvalidArgumentException, 'unsupported location'):
         create_utils._ParseCAResourceArgs(args)
Ejemplo n.º 2
0
 def testKmsKeyVersionInDifferentLocationRaisesException(self, _):
     args = self.parser.parse_args([
         'new-ca',
         '--kms-key-version=1',
         '--kms-key=k1',
         '--kms-keyring=kr1',
         '--kms-location=us-europe-west1',
     ] + self.other_args)
     with self.AssertRaisesExceptionMatches(
             exceptions.InvalidArgumentException,
             'KMS key must be in the same location'):
         create_utils._ParseCAResourceArgs(args)
Ejemplo n.º 3
0
    def testUnderSpecifiedIssuerFails(self, location_mock):
        properties.VALUES.privateca.location.Set(None)
        args = self.parser.parse_args([
            'new-ca',
            '--location=us-west1',
            '--issuer=my-root',
        ])

        expected_error = """The [Issuer] resource is not properly specified.
Failed to find attribute [location]. The attribute can be set in the following ways:
- provide the argument [--issuer-location] on the command line
- set the property [privateca/location]"
"""
        with self.assertRaises(handlers.ParseError, msg=expected_error):
            create_utils._ParseCAResourceArgs(args)
Ejemplo n.º 4
0
    def testUnderSpecifiedSourceRaisesException(self, _):
        properties.VALUES.privateca.location.Set(None)
        args = self.parser.parse_args([
            'new-ca',
            '--location=us-west1',
            '--from-ca=source',
        ] + self.other_args)

        expected_error = """The [source CA] resource is not properly specified.
Failed to find attribute [location]. The attribute can be set in the following ways:
- provide the argument [--from-ca-location] on the command line
- set the property [privateca/location]"
"""
        with self.assertRaises(handlers.ParseError, msg=expected_error):
            create_utils._ParseCAResourceArgs(args)
Ejemplo n.º 5
0
    def testUnderSpecifiedKmsKeyVersionRaisesException(self, _):
        properties.VALUES.privateca.location.Set(None)
        args = self.parser.parse_args([
            'new-ca',
            '--location=us-west1',
            '--kms-key-version=1',
        ] + self.other_args)

        expected_error = """googlecloudsdk.calliope.concepts.handlers.ParseError: Error parsing [kms_key_version].
The [key version] resource is not properly specified.
Failed to find attribute [kms-keyring]. The attribute can be set in the following ways:
- provide the argument [--kms-keyring] on the command line
"""
        with self.assertRaises(handlers.ParseError, msg=expected_error):
            create_utils._ParseCAResourceArgs(args)
Ejemplo n.º 6
0
 def testParseCertificateAuthorityWithImplicitLocation(self, _):
     args = self.parser.parse_args([
         'new-ca',
         '--kms-key-version',
         _KmsKeyVersion(),
     ] + self.other_args)
     ca_ref, _, _ = create_utils._ParseCAResourceArgs(args)
     self.assertEqual(ca_ref.locationsId, _DEFAULT_LOCATION)
     self.assertEqual(ca_ref.certificateAuthoritiesId, 'new-ca')
Ejemplo n.º 7
0
 def testParseCertificateAuthorityWithComponentizedLocation(self, _):
     args = self.parser.parse_args([
         'new-ca',
         '--location=us-east1',
         '--kms-key-version',
         _KmsKeyVersion(location='us-east1'),
     ] + self.other_args)
     ca_ref, _, _ = create_utils._ParseCAResourceArgs(args)
     self.assertEqual(ca_ref.locationsId, 'us-east1')
     self.assertEqual(ca_ref.certificateAuthoritiesId, 'new-ca')
Ejemplo n.º 8
0
 def testParseCertificateAuthorityWithFullResourceName(self, _):
     args = self.parser.parse_args([
         'projects/different/locations/us-east1/certificateAuthorities/new-ca',
         '--kms-key-version',
         _KmsKeyVersion(location='us-east1'),
     ] + self.other_args)
     ca_ref, _, _ = create_utils._ParseCAResourceArgs(args)
     self.assertEqual(ca_ref.projectsId, 'different')
     self.assertEqual(ca_ref.locationsId, 'us-east1')
     self.assertEqual(ca_ref.certificateAuthoritiesId, 'new-ca')
Ejemplo n.º 9
0
 def testParseSourceWithComponentizedResourceFlags(self, _):
     args = self.parser.parse_args([
         'new-ca', '--kms-key-version',
         _KmsKeyVersion(), '--from-ca=source-root',
         '--from-ca-location=europe-west1', '--from-ca-project=bar'
     ] + self.other_args)
     _, ca_source_ref, _ = create_utils._ParseCAResourceArgs(args)
     self.assertEqual(ca_source_ref.projectsId, 'bar')
     self.assertEqual(ca_source_ref.locationsId, 'europe-west1')
     self.assertEqual(ca_source_ref.certificateAuthoritiesId, 'source-root')
Ejemplo n.º 10
0
 def testIssuerInDifferentLocationWorks(self, location_mock):
     args = self.parser.parse_args([
         'new-ca',
         '--issuer=my-root',
         '--issuer-location=europe-west1',
         '--kms-key-version',
         _KmsKeyVersion(),
     ])
     _, _, issuer_ref = create_utils._ParseCAResourceArgs(args)
     self.assertEqual(issuer_ref.locationsId, 'europe-west1')
     self.assertEqual(issuer_ref.certificateAuthoritiesId, 'my-root')
Ejemplo n.º 11
0
 def testParseIssuerWithFullResourceName(self, _):
     args = self.parser.parse_args([
         'new-ca',
         '--issuer=projects/different/locations/us-west1/certificateAuthorities/my-root',
         '--kms-key-version',
         _KmsKeyVersion(),
     ])
     _, _, issuer_ref = create_utils._ParseCAResourceArgs(args)
     self.assertEqual(issuer_ref.projectsId, 'different')
     self.assertEqual(issuer_ref.locationsId, 'us-west1')
     self.assertEqual(issuer_ref.certificateAuthoritiesId, 'my-root')
Ejemplo n.º 12
0
 def testParseIssuerWithComponentizedResourceName(self, _):
     args = self.parser.parse_args([
         'new-ca',
         '--issuer=my-root',
         '--issuer-location=us-west1',
         '--kms-key-version',
         _KmsKeyVersion(),
     ])
     _, _, issuer_ref = create_utils._ParseCAResourceArgs(args)
     self.assertEqual(issuer_ref.locationsId, 'us-west1')
     self.assertEqual(issuer_ref.certificateAuthoritiesId, 'my-root')
Ejemplo n.º 13
0
 def testParseSourceWithFullResourceName(self, _):
     args = self.parser.parse_args([
         'new-ca',
         '--from-ca=projects/foo/locations/us-west1/certificateAuthorities/source-root',
         '--kms-key-version',
         _KmsKeyVersion(),
     ] + self.other_args)
     _, ca_source_ref, _ = create_utils._ParseCAResourceArgs(args)
     self.assertEqual(ca_source_ref.projectsId, 'foo')
     self.assertEqual(ca_source_ref.locationsId, 'us-west1')
     self.assertEqual(ca_source_ref.certificateAuthoritiesId, 'source-root')
Ejemplo n.º 14
0
 def testParseSourceWithImplicitLocation(self, _):
     properties.VALUES.privateca.location.Set('europe-west1')
     args = self.parser.parse_args([
         'new-ca',
         '--location=us-west1',
         '--kms-key-version',
         _KmsKeyVersion(),
         '--from-ca=source-root',
     ] + self.other_args)
     _, ca_source_ref, _ = create_utils._ParseCAResourceArgs(args)
     self.assertEqual(ca_source_ref.locationsId, 'europe-west1')
     self.assertEqual(ca_source_ref.certificateAuthoritiesId, 'source-root')
Ejemplo n.º 15
0
 def testSupportsMissingKmsKeyVersion(self, _):
     args = self.parser.parse_args([
         'new-ca',
         '--key-algorithm=rsa-pss-2048-sha256',
     ] + self.other_args)
     create_utils._ParseCAResourceArgs(args)