예제 #1
0
    def Run(self, args):
        conn_context = connection_context.EventsConnectionContext(args)

        with eventflow_operations.Connect(conn_context) as client:
            source_crds = client.ListSourceCustomResourceDefinitions()
            return util.EventTypeFromTypeString(source_crds, args.event_type,
                                                args.source)
예제 #2
0
    def Run(self, args):
        """Executes when the user runs the describe command."""
        conn_context = connection_context.EventsConnectionContext(args)

        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)
예제 #3
0
  def Run(self, args):
    conn_context = connection_context.EventsConnectionContext(args)
    namespace_ref = args.CONCEPTS.namespace.Parse()

    with eventflow_operations.Connect(conn_context) as client:
      brokers = client.ListBrokers(namespace_ref.RelativeName())
      return brokers
예제 #4
0
    def Run(self, args):
        conn_context = connection_context.EventsConnectionContext(args)

        with eventflow_operations.Connect(conn_context) as client:
            source_crds = client.ListSourceCustomResourceDefinitions()
            event_types = []
            for crd in source_crds:
                if not args.IsSpecified(
                        'source') or args.source == crd.source_kind:
                    event_types.extend(crd.event_types)
            return event_types
예제 #5
0
    def Run(self, args):
        """Executes when the user runs the describe command."""
        conn_context = connection_context.EventsConnectionContext(args)

        namespace_ref = args.CONCEPTS.namespace.Parse()
        broker_name = args.BROKER
        broker_full_name = namespace_ref.RelativeName(
        ) + '/brokers/' + broker_name

        with eventflow_operations.Connect(conn_context) as client:
            broker_obj = client.GetBroker(broker_full_name)

        if not broker_obj:
            raise exceptions.BrokerNotFound(
                'Broker [{}] not found.'.format(broker_name))
        return broker_obj
예제 #6
0
    def Run(self, args):
        """Executes when the user runs the delete command."""
        conn_context = connection_context.EventsConnectionContext(args)

        namespace_ref = args.CONCEPTS.namespace.Parse()
        broker_name = args.BROKER

        console_io.PromptContinue(
            message='Broker [{}] will be deleted.'.format(broker_name),
            throw_if_unattended=True,
            cancel_on_no=True)

        with eventflow_operations.Connect(conn_context) as client:
            client.DeleteBroker(namespace_ref.Name(), broker_name)

        log.DeletedResource(broker_name, 'broker')
예제 #7
0
    def Run(self, args):
        """Executes when the user runs the delete command."""
        conn_context = connection_context.EventsConnectionContext(args)

        trigger_ref = args.CONCEPTS.trigger.Parse()
        console_io.PromptContinue(
            message='Trigger [{}] will be deleted.'.format(trigger_ref.Name()),
            throw_if_unattended=True,
            cancel_on_no=True)

        with eventflow_operations.Connect(conn_context) as client:
            trigger_ref = resources.REGISTRY.Parse(
                trigger_ref.RelativeName(),
                collection=util.ANTHOS_TRIGGER_COLLECTION_NAME,
                api_version=client.api_version)
            client.DeleteTrigger(trigger_ref)

        log.DeletedResource(trigger_ref.Name(), 'trigger')
예제 #8
0
    def Run(self, args):
        """Executes when the user runs the create command."""
        conn_context = connection_context.EventsConnectionContext(args)

        namespace_ref = args.CONCEPTS.namespace.Parse()

        with eventflow_operations.Connect(conn_context) as client:
            client.CreateBroker(namespace_ref.Name(), args.BROKER)

            broker_full_name = 'namespaces/{}/brokers/{}'.format(
                namespace_ref.Name(), args.BROKER)

            with progress_tracker.StagedProgressTracker(
                    'Creating Broker...',
                [progress_tracker.Stage('Creating Broker...')]) as tracker:
                client.PollBroker(broker_full_name, tracker)

        log.status.Print('Created broker [{}] in namespace [{}].'.format(
            args.BROKER, namespace_ref.Name()))
예제 #9
0
    def Run(self, args):
        """Executes when user runs the init command."""
        conn_context = connection_context.EventsConnectionContext(args)
        namespace_ref = args.CONCEPTS.namespace.Parse()

        with eventflow_operations.Connect(conn_context) as client:
            product_type = init_shared.determine_product_type(
                client, args.authentication)

            if not client.GetNamespace(namespace_ref):
                client.CreateNamespace(namespace_ref)

            if args.authentication == 'secrets':
                client.CreateOrReplaceSourcesSecret(namespace_ref,
                                                    product_type)

        log.status.Print(
            'Initialized namespace [{}] for Cloud Run eventing with '
            'secret {}'.format(namespace_ref.Name(),
                               anthosevents_operations.SOURCES_KEY))
예제 #10
0
    def Run(self, args):
        """Executes when the user runs the init command."""
        project = properties.VALUES.core.project.Get(required=True)
        conn_context = connection_context.EventsConnectionContext(args)

        with eventflow_operations.Connect(conn_context) as client:
            operator.install_eventing_via_operator(client, self.ReleaseTrack())

            # Eventing has been installed and enabled, but not initialized yet.
            product_type = init_shared.determine_product_type(
                client, args.authentication)

            if client.IsClusterInitialized(product_type):
                console_io.PromptContinue(
                    message='This cluster has already been initialized.',
                    prompt_string='Would you like to re-run initialization?',
                    cancel_on_no=True)

            _EnableMissingServices(project)

            if args.authentication == events_constants.AUTH_SECRETS:
                # Create secrets for each Google service account and adds to cluster.
                gsa_emails = init_shared.construct_service_accounts(
                    args, product_type)
                init_shared.initialize_eventing_secrets(
                    client, gsa_emails, product_type)

            elif args.authentication == events_constants.AUTH_WI_GSA:
                # Bind controller and broker GSA to KSA via workload identity.
                gsa_emails = init_shared.construct_service_accounts(
                    args, product_type)
                init_shared.initialize_workload_identity_gsa(
                    client, gsa_emails)
            else:
                log.status.Print('Skipped initializing cluster.')

        log.status.Print(
            _InitializedMessage(self.ReleaseTrack(), conn_context.cluster_name,
                                args.authentication))
예제 #11
0
    def Run(self, args):
        conn_context = connection_context.EventsConnectionContext(args)

        with eventflow_operations.Connect(conn_context) as client:
            source_crds = client.ListSourceCustomResourceDefinitions()
            return [crd for crd in source_crds if crd.event_types]