def Args(parser): flags.AddConcepts( parser, flags.GetAttestorPresentationSpec( required=True, positional=False, group_help=( 'The attestor on which the public key should be updated.'), ), ) parser.add_argument( 'public_key_fingerprint', help='The fingerprint of the public key to update.') parser.add_argument('--public-key-file', type=arg_parsers.BufferedFileInput(), help='The path to the file containing the ' 'new ASCII-armored PGP public key.') parser.add_argument('--comment', help='The comment describing the public key.')
def Args(parser): """Register flags for this command.""" parser.add_argument('metric_name', help='The name of the new metric.') config_group = parser.add_argument_group( help='Data about the new metric.', mutex=True, required=True) legacy_mode_group = config_group.add_argument_group( help=('A group of arguments to specify simple counter logs-based ' 'metrics. ')) legacy_mode_group.add_argument('--description', required=True, help='The metric\'s description.') legacy_mode_group.add_argument('--log-filter', required=True, help='The metric\'s filter expression.') config_group.add_argument( '--config-from-file', help=('A path to a YAML file specifying the logs-' 'based metric to create.'), type=arg_parsers.BufferedFileInput())
def _AddConditionFlagsForAddBindingToIamPolicy(parser): """Create flags for condition and add to parser.""" condition_intro = """ Condition of the binding to be added. When condition is explicitly specified as `None` (e.g. --condition=None), a binding without a condition is added.""" help_str_condition = _ConditionHelpText(condition_intro) help_str_condition_from_file = """ Path to a local JSON or YAML file that defines the condition. To see available fields, see the help for `--condition`.""" condition_group = parser.add_mutually_exclusive_group() condition_group.add_argument('--condition', type=_ConditionArgDict(), metavar='KEY=VALUE', help=help_str_condition) condition_group.add_argument('--condition-from-file', type=arg_parsers.BufferedFileInput(), help=help_str_condition_from_file)
def AddPolicySettingsFlags(parser, update=False): """Adds policy settings flags to the parser.""" policy_settings_group = parser.add_group(help="""\ Policy Settings. If any of these are specified, they will overwrite fields in the `--policy` or `--policy-from-file` flags if specified.""") AddDisplayNameFlag(policy_settings_group, resource='Alert Policy') enabled_kwargs = { 'action': arg_parsers.StoreTrueFalseAction if update else 'store_true' } if not update: # Can't specify default if using StoreTrueFalseAction. enabled_kwargs['default'] = True policy_settings_group.add_argument('--enabled', help='If the policy is enabled.', **enabled_kwargs) documentation_group = policy_settings_group.add_group(help='Documentation') documentation_group.add_argument( '--documentation-format', default='text/markdown' if not update else None, help='The MIME type that should be used with `--documentation` or ' '`--documentation-from-file`. Currently, only "text/markdown" is ' 'supported.') documentation_string_group = documentation_group.add_group(mutex=True) documentation_string_group.add_argument( '--documentation', help='The documentation to be included with the policy.') documentation_string_group.add_argument( '--documentation-from-file', type=arg_parsers.BufferedFileInput(), help='The path to a file containing the documentation to be included ' 'with the policy.') if update: repeated.AddPrimitiveArgs(policy_settings_group, 'Alert Policy', 'notification-channels', 'Notification Channels') AddUpdateLabelsFlags('user-labels', policy_settings_group, group_text='User Labels') else: AddCreateLabelsFlag(policy_settings_group, 'user-labels', 'policy')
def GeneratePublicKeyDataFromFile(path): """Generate public key data from a path. Args: path: (bytes) the public key file path given by the command. Raises: InvalidArgumentException: if the public key file path provided does not exist or is too large. Returns: A public key encoded using the UTF-8 charset. """ try: public_key_data = arg_parsers.BufferedFileInput()(path).strip() except arg_parsers.ArgumentTypeError as e: raise gcloud_exceptions.InvalidArgumentException( 'public_key_file', '{}. Please double check your input and try again.'.format(e)) return public_key_data.encode('utf-8')
def Args(parser): """Register flags for this command.""" parser.add_argument( 'metric_name', help='The name of the log-based metric to update.') config_group = parser.add_argument_group( help='Data about the metric to update.', mutex=True, required=True) legacy_mode_group = config_group.add_argument_group( help=('Arguments to specify information about simple counter logs-' 'based metrics.')) legacy_mode_group.add_argument( '--description', required=False, help=('A new description for the metric. ' 'If omitted, the description is not changed.')) legacy_mode_group.add_argument( '--log-filter', required=False, help=('A new filter string for the metric. ' 'If omitted, the filter is not changed.')) config_group.add_argument('--config-from-file', help=('A path to a YAML file specifying the ' 'updates to be made to the logs-based ' 'metric.'), type=arg_parsers.BufferedFileInput())
def AddAllocationArgGroup(parser): """Adds all flags needed for allocation(s) creation.""" allocations_manage_group = parser.add_group( 'Manage the allocations to be created with the commitment.', mutex=True) allocations_manage_group.add_argument( '--allocations-from-file', type=arg_parsers.BufferedFileInput(), help='The path to a YAML file of multiple allocations\' configuration.') single_allocation_group = allocations_manage_group.add_argument_group( help='Manage the allocation to be created with the commitment.') resource_args.GetAllocationResourceArg( positional=False).AddArgument(single_allocation_group) single_allocation_group.add_argument( '--allocation-type', hidden=True, choices=['specific'], default='specific', help='The type of the allocation to be created.') specific_sku_allocation_group = single_allocation_group.add_argument_group( help='Manage the specific SKU allocation properties to create.') AddFlagsToSpecificSkuGroup(specific_sku_allocation_group)
def ParseMessageBodyFromFile(path): return ParseMessageBody(arg_parsers.BufferedFileInput()(path))
def AddCycleFrequencyArgs(parser, flag_suffix, start_time_help, cadence_help, supports_hourly=False, has_restricted_start_times=False, supports_weekly=False): """Add Cycle Frequency args for Resource Policies.""" freq_group = parser.add_argument_group('Cycle Frequency Group.', required=True, mutex=True) if has_restricted_start_times: start_time_help += """\ Valid choices are 00:00, 04:00, 08:00,12:00, 16:00 and 20:00 UTC. For example, `--start-time="03:00-05"` (which gets converted to 08:00 UTC).""" freq_flags_group = freq_group.add_group( 'From flags:' if supports_weekly else '') freq_flags_group.add_argument('--start-time', required=True, type=arg_parsers.Datetime.Parse, help=start_time_help) cadence_group = freq_flags_group.add_group(mutex=True, required=True) cadence_group.add_argument( '--daily-{}'.format(flag_suffix), dest='daily_cycle', action='store_true', help='{} starts daily at START_TIME.'.format(cadence_help)) if supports_hourly: cadence_group.add_argument( '--hourly-{}'.format(flag_suffix), metavar='HOURS', dest='hourly_cycle', type=arg_parsers.BoundedInt(lower_bound=1), help='{} occurs every n hours starting at START_TIME.'.format( cadence_help)) if supports_weekly: base.ChoiceArgument( '--weekly-{}'.format(flag_suffix), dest='weekly_cycle', choices=[ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ], help_str='{} occurs weekly on WEEKLY_{} at START_TIME.'.format( cadence_help, flag_suffix.upper())).AddToParser(cadence_group) freq_file_group = freq_group.add_group('From file:') freq_file_group.add_argument( '--weekly-{}-from-file'.format(flag_suffix), dest='weekly_cycle_from_file', type=arg_parsers.BufferedFileInput(), help="""\ A JSON/YAML file which specifies a weekly schedule. It should be a list of objects with the following fields: day: Day of the week with the same choices as `--weekly-{}`. startTime: Start time of the snapshot schedule with the same format as --start-time. """.format(flag_suffix))