def Run(self, args): """Executes when the user runs the describe command.""" conn_context = connection_context.GetConnectionContext( args, product=connection_context.Product.EVENTS) trigger_ref = args.CONCEPTS.trigger.Parse() with eventflow_operations.Connect(conn_context) as client: trigger_obj = client.GetTrigger(trigger_ref) source_obj = None if trigger_obj is not None: source_crds = client.ListSourceCustomResourceDefinitions() source_ref, source_crd = util.GetSourceRefAndCrdForTrigger( trigger_obj, source_crds) if source_ref and source_crd: source_obj = client.GetSource(source_ref, source_crd) if not trigger_obj: raise exceptions.TriggerNotFound( 'Trigger [{}] not found.'.format(trigger_ref.Name())) if not source_obj: log.warning('No matching event source for trigger [{}].'.format( trigger_ref.Name())) return SerializedTriggerAndSource( trigger_obj.MakeSerializable(), source_obj.MakeSerializable() if source_obj else None)
def Run(self, args): """Executes when the user runs the describe command.""" conn_context = connection_context.GetConnectionContext( args, product=connection_context.Product.EVENTS) if conn_context.supports_one_platform: raise exceptions.UnsupportedArgumentError( 'Events are only available with Cloud Run for Anthos.') trigger_ref = args.CONCEPTS.trigger.Parse() with eventflow_operations.Connect(conn_context) as client: trigger_obj = client.GetTrigger(trigger_ref) source_obj = None if trigger_obj is not None: source_crds = client.ListSourceCustomResourceDefinitions() source_obj_ref = trigger_obj.dependency source_crd = next((s for s in source_crds if s.source_kind == source_obj_ref.kind), None) if source_crd is not None: source_ref = util.GetSourceRef(source_obj_ref.name, source_obj_ref.namespace, source_crd) source_obj = client.GetSource(source_ref, source_crd) if not trigger_obj: raise exceptions.TriggerNotFound('Trigger [{}] not found.'.format( trigger_ref.Name())) if not source_obj: log.warning('No matching event source for trigger [{}].'.format( trigger_ref.Name())) return SerializedTriggerAndSource( trigger_obj.MakeSerializable(), source_obj.MakeSerializable() if source_obj else None)
def Run(self, args): """Executes when the user runs the describe command.""" conn_context = connection_context.GetConnectionContext( args, serverless_flags.Product.EVENTS, self.ReleaseTrack()) trigger_ref = args.CONCEPTS.trigger.Parse() with eventflow_operations.Connect(conn_context) as client: if client.IsCluster(): trigger_ref = resources.REGISTRY.Parse( trigger_ref.RelativeName(), collection=util.ANTHOS_TRIGGER_COLLECTION_NAME, api_version=client.api_version) trigger_obj = client.GetTrigger(trigger_ref) source_obj = None if trigger_obj is not None: source_crds = client.ListSourceCustomResourceDefinitions() source_ref, source_crd = util.GetSourceRefAndCrdForTrigger( trigger_obj, source_crds, client.IsCluster()) if source_ref and source_crd: source_obj = client.GetSource(source_ref, source_crd) if not trigger_obj: raise exceptions.TriggerNotFound('Trigger [{}] not found.'.format( trigger_ref.Name())) if not source_obj: log.warning('No matching event source for trigger [{}].'.format( trigger_ref.Name())) return SerializedTriggerAndSource( trigger_obj.MakeSerializable(), source_obj.MakeSerializable() if source_obj else None)
def DeleteTrigger(self, trigger_ref): """Deletes the referenced trigger.""" request = self.messages.AnthoseventsNamespacesTriggersDeleteRequest( name=trigger_ref.RelativeName()) try: with metrics.RecordDuration(metric_names.DELETE_TRIGGER): self._client.namespaces_triggers.Delete(request) except api_exceptions.HttpNotFoundError: raise exceptions.TriggerNotFound('Trigger [{}] not found.'.format( trigger_ref.Name()))
def Run(self, args): """Executes when the user runs the describe command.""" conn_context = connection_context.GetConnectionContext(args) if conn_context.supports_one_platform: raise exceptions.UnsupportedArgumentError( 'Events are only available with Cloud Run for Anthos.') trigger_ref = args.CONCEPTS.trigger.Parse() with eventflow_operations.Connect(conn_context) as client: trigger_obj = client.GetTrigger(trigger_ref) if not trigger_obj: raise exceptions.TriggerNotFound('Trigger [{}] not found.'.format( trigger_ref.Name())) return trigger_obj