def testParseCredentials_MissingRequiredKey(self): with self.assertRaisesRegex( util.InvalidPublicKeySpecificationError, re.escape('--public-key argument missing value for `path`')): util.ParseCredentials([{ 'type': 'rsa-x509-pem' }], messages=self.messages) with self.assertRaisesRegex( util.InvalidPublicKeySpecificationError, re.escape('--public-key argument missing value for `type`')): util.ParseCredentials([{ 'path': self.rsa_key_path }], messages=self.messages)
def testParseCredentials_RsaKeyUnreadableKeyFile(self): with self.assertRaisesRegex( util.InvalidKeyFileError, re.escape(('Could not read key file [{}]:').format( self.bad_key_path))): util.ParseCredentials([{ 'type': 'rsa-x509-pem', 'path': self.bad_key_path }], messages=self.messages)
def testParseCredentials_BadKeyType(self): with self.assertRaisesRegex( ValueError, re.escape('Invalid key type [invalid-type]')): util.ParseCredentials([ { 'type': 'invalid-type', 'path': self.rsa_key_path }, ], messages=self.messages)
def testParseCredentials_OneKey(self): self.assertEqual( util.ParseCredentials([{ 'type': 'rsa-x509-pem', 'path': self.rsa_key_path }], messages=self.messages), [ self.messages.DeviceCredential( publicKey=self.messages.PublicKeyCredential( format=self.format_enum.RSA_X509_PEM, key=_DUMMY_RSA_FILE_CONTENTS)) ])
def Run(self, args): client = devices.DevicesClient() registry_ref = util.ParseRegistry(args.registry, region=args.region) enabled_state = util.ParseEnableDevice(args.enable_device, client=client) credentials = util.ParseCredentials(args.public_keys, messages=client.messages) return client.Create(registry_ref, args.id, enabled_state=enabled_state, credentials=credentials)
def testParseCredentials_ExtraInvalidKeys(self): with self.assertRaisesRegex( TypeError, (r'Unrecognized keys \[badkey[12], badkey[12]] for public key ' r'specification')): util.ParseCredentials([ { 'type': 'rsa-x509-pem', 'path': self.rsa_key_path, 'badkey1': None, 'badkey2': None }, ], messages=self.messages)
def Run(self, args): client = devices.DevicesClient() device_ref = args.CONCEPTS.device.Parse() registry_ref = device_ref.Parent() credentials = util.ParseCredentials(args.public_keys, messages=client.messages) metadata = util.ParseMetadata(args.metadata, args.metadata_from_file, client.messages) response = client.Create(registry_ref, device_ref.devicesId, blocked=args.blocked, credentials=credentials, metadata=metadata) log.CreatedResource(device_ref.devicesId, 'device') return response
def testParseCredentials_TooManyValues(self): with self.assertRaisesRegex( util.InvalidPublicKeySpecificationError, re.escape('Too many public keys specified: [4] given, ' 'but maximum [3] allowed.')): util.ParseCredentials([{ 'type': 'rsa-x509-pem', 'path': self.rsa_key_path }, { 'type': 'es256-pem', 'path': self.ecdsa_key_path }, { 'type': 'rsa-x509-pem', 'path': self.rsa_key_path }, { 'type': 'es256-pem', 'path': self.ecdsa_key_path }], messages=self.messages)
def Run(self, args): client = devices.DevicesClient() registry_ref = util.ParseRegistry(args.registry, region=args.region) # Defaults are set here because right now with nested groups, help text # isn't being generated correctly. args_blocked = False if args.blocked is None else args.blocked args_enabled = True if args.enable_device is None else args.enable_device blocked = util.ParseDeviceBlocked(args_blocked, args_enabled) credentials = util.ParseCredentials(args.public_keys, messages=client.messages) metadata = util.ParseMetadata(args.metadata, args.metadata_from_file, client.messages) response = client.Create( registry_ref, args.id, blocked=blocked, credentials=credentials, metadata=metadata ) log.CreatedResource(args.id, 'device') return response
def testParseCredentials_Empty(self): self.assertEqual(util.ParseCredentials([], messages=self.messages), [])