def Display(self, unused_args, result): """This method is called to print the result of the Run() method. Args: unused_args: The arguments that command was run with. result: The value returned from the Run() method. """ list_printer.PrintResourceList('logging.typedSinks', [result]) util.PrintPermissionInstructions(result.destination)
def Epilog(self, unused_resources_were_displayed): if hasattr(self, '_epilog_result_destination'): util.PrintPermissionInstructions(self._epilog_result_destination, self._epilog_writer_identity)
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: The updated sink with its new destination. """ if args.output_version_format: log.warn( '--output-version-format is deprecated and will soon be removed.' ) # One of the flags is required to update the sink. # log_filter can be an empty string, so check explicitly for None. if not (args.destination or args.log_filter is not None or args.output_version_format): raise calliope_exceptions.ToolException( '[destination], --log-filter or --output-version-format is required' ) sink_ref = resources.REGISTRY.Parse( args.sink_name, params={'projectsId': properties.VALUES.core.project.GetOrFail}, collection='logging.projects.sinks') # Calling Update on a non-existing sink creates it. # We need to make sure it exists, otherwise we would create it. try: sink = self.GetSink(util.GetParentFromArgs(args), sink_ref) except apitools_exceptions.HttpError as error: if exceptions.HttpException(error).payload.status_code == 404: log.status.Print('Sink was not found.') raise error # Only update fields that were passed to the command. if args.destination: destination = args.destination else: destination = sink.destination if args.log_filter is not None: log_filter = args.log_filter else: log_filter = sink.filter if args.output_version_format: output_format = args.output_version_format else: output_format = sink.outputVersionFormat.name sink_data = { 'name': sink_ref.sinksId, 'destination': destination, 'filter': log_filter, 'outputVersionFormat': output_format, 'includeChildren': sink.includeChildren, 'startTime': sink.startTime, 'endTime': sink.endTime } # Check for legacy configuration, and let users decide if they still want # to update the sink with new settings. if 'cloud-logs@' in sink.writerIdentity: console_io.PromptContinue( 'This update will create a new writerIdentity (service account) for ' 'the sink. In order for the sink to continue working, grant that ' 'service account correct permission on the destination. The service ' 'account will be displayed after a successful update operation.', cancel_on_no=True, default=False) result = util.TypedLogSink( self.UpdateSink(util.GetParentFromArgs(args), sink_data)) log.UpdatedResource(sink_ref, kind='sink') util.PrintPermissionInstructions(result.destination, result.writer_identity) return result
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: The updated sink with its new destination. """ util.CheckSinksCommandArguments(args) # One of the flags is required to update the sink. # log_filter can be an empty string, so check explicitly for None. if not (args.destination or args.log_filter is not None or args.output_version_format): raise calliope_exceptions.ToolException( '[destination], --log-filter or --output-version-format is required' ) # Calling Update on a non-existing sink creates it. # We need to make sure it exists, otherwise we would create it. try: if args.log: sink = self.GetLogSink() elif args.service: sink = self.GetLogServiceSink() else: sink = self.GetProjectSink() except apitools_exceptions.HttpError as error: project_sink = not args.log and not args.service # Suggest the user to add --log or --log-service flag. if project_sink and exceptions.HttpException( error).payload.status_code == 404: log.status.Print( ('Project sink was not found. ' 'Did you forget to add --log or --log-service flag?')) raise error # Only update fields that were passed to the command. if args.destination: destination = args.destination else: destination = sink.destination if args.log_filter is not None: log_filter = args.log_filter else: log_filter = sink.filter sink_ref = self.context['sink_reference'] sink_data = { 'name': sink_ref.sinksId, 'destination': destination, 'filter': log_filter } if args.log: result = util.TypedLogSink(self.UpdateLogSink(sink_data), log_name=args.log) kind = 'log sink' elif args.service: result = util.TypedLogSink(self.UpdateLogServiceSink(sink_data), service_name=args.service) kind = 'service log sink' else: if args.output_version_format: sink_data['outputVersionFormat'] = args.output_version_format else: sink_data[ 'outputVersionFormat'] = sink.outputVersionFormat.name result = util.TypedLogSink(self.UpdateProjectSink(sink_data)) kind = 'project sink' log.UpdatedResource(sink_ref, kind=kind) util.PrintPermissionInstructions(result.destination, result.writer_identity) return result
def Epilog(self, unused_resources_were_displayed): util.PrintPermissionInstructions(self._epilog_result_destination, self._epilog_writer_identity, self._epilog_is_dlp_sink)
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Returns: The updated sink with its new destination. """ if not args.unique_writer_identity: log.warn( '--unique-writer-identity is deprecated and will soon be removed.') # One of the flags is required to update the sink. # log_filter can be an empty string, so check explicitly for None. if not (args.destination or args.log_filter is not None or args.output_version_format): raise calliope_exceptions.ToolException( '[destination], --log-filter or --output-version-format is required') sink_ref = resources.REGISTRY.Parse( args.sink_name, collection='logging.projects.sinks') # Calling Update on a non-existing sink creates it. # We need to make sure it exists, otherwise we would create it. try: sink = self.GetSink(util.GetParentFromArgs(args), sink_ref) except apitools_exceptions.HttpError as error: if exceptions.HttpException(error).payload.status_code == 404: log.status.Print('Sink was not found.') raise error # Only update fields that were passed to the command. if args.destination: destination = args.destination else: destination = sink.destination if args.log_filter is not None: log_filter = args.log_filter else: log_filter = sink.filter if args.output_version_format: output_format = args.output_version_format else: output_format = sink.outputVersionFormat.name sink_data = { 'name': sink_ref.sinksId, 'destination': destination, 'filter': log_filter, 'outputVersionFormat': output_format } result = util.TypedLogSink( self.UpdateSink( util.GetParentFromArgs(args), sink_data, args.unique_writer_identity)) log.UpdatedResource(sink_ref, kind='sink') util.PrintPermissionInstructions(result.destination, result.writer_identity) return result
def Epilog(self, unused_resources_were_displayed): util.PrintPermissionInstructions(self._epilog_result_destination)