def _Run(args, supports_deprecated_event_config_flags=False): """Creates a new Cloud IoT Device Registry.""" client = registries.RegistriesClient() registry_ref = args.CONCEPTS.registry.Parse() location_ref = registry_ref.Parent() mqtt_state = util.ParseEnableMqttConfig(args.enable_mqtt_config, client=client) http_state = util.ParseEnableHttpConfig(args.enable_http_config, client=client) event_pubsub_topic = None if supports_deprecated_event_config_flags: event_pubsub_topic = args.event_pubsub_topic event_notification_configs = util.ParseEventNotificationConfig( args.event_notification_configs, event_pubsub_topic) state_pubsub_topic_ref = util.ParsePubsubTopic(args.state_pubsub_topic) credentials = [] if args.public_key_path: credentials.append(util.ParseRegistryCredential(args.public_key_path)) response = client.Create( location_ref, registry_ref.registriesId, credentials=credentials, event_notification_configs=event_notification_configs, state_pubsub_topic=state_pubsub_topic_ref, mqtt_enabled_state=mqtt_state, http_enabled_state=http_state) log.CreatedResource(registry_ref.registriesId, 'registry') return response
def Run(self, args): client = registries.RegistriesClient() location_ref = util.ParseLocation(region=args.region) mqtt_state = util.ParseEnableMqttConfig(args.enable_mqtt_config, client=client) http_state = util.ParseEnableHttpConfig(args.enable_http_config, client=client) event_pubsub_topic = args.pubsub_topic or args.event_pubsub_topic event_pubsub_topic_ref = util.ParsePubsubTopic(event_pubsub_topic) state_pubsub_topic_ref = util.ParsePubsubTopic(args.state_pubsub_topic) credentials = [] if args.public_key_path: credentials.append( util.ParseRegistryCredential(args.public_key_path)) response = client.Create(location_ref, args.id, credentials=credentials, event_pubsub_topic=event_pubsub_topic_ref, state_pubsub_topic=state_pubsub_topic_ref, mqtt_enabled_state=mqtt_state, http_enabled_state=http_state) log.CreatedResource(args.id, 'registry') return response
def testParseRegistryCredential_UnreadableKeyFile(self): bad_key_path = os.path.join(self.temp_path, 'bad.pub') with self.assertRaisesRegex( util.InvalidKeyFileError, re.escape( ('Could not read key file [{}]:').format(bad_key_path))): util.ParseRegistryCredential(bad_key_path, messages=self.messages)
def testParseRegistryCredential(self): public_key_path = self.Touch(self.temp_path, 'cert1.pub', contents=_DUMMY_X509_CERT_CONTENTS) self.assertEqual( self._CreateRegistryCredential(_DUMMY_X509_CERT_CONTENTS), util.ParseRegistryCredential(public_key_path, messages=self.messages))
def Run(self, args): client = registries.RegistriesClient() registry_ref = args.CONCEPTS.registry.Parse() new_credential = util.ParseRegistryCredential(args.path, messages=client.messages) credentials = client.Get(registry_ref).credentials credentials.append(new_credential) response = client.Patch(registry_ref, credentials=credentials) log.CreatedResource(registry_ref.Name(), 'credentials for registry') return response