예제 #1
0
def AddParentArgs(parser):
    parent_group = parser.add_mutually_exclusive_group(required=True)
    common_args.ProjectArgument(
        help_text_to_prepend='The project which is the root asset.'
    ).AddToParser(parent_group)
    AddOrganizationArgs(parent_group)
    AddFolderArgs(parent_group)
예제 #2
0
def AddParentFlagsToParser(parser):
    """Adding argument mutex group project, billing-account, folder, organization to parser.

  Args:
      parser: An argparse parser that you can use to add arguments that go on
        the command line after this command.
  """
    resource_group = parser.add_mutually_exclusive_group(
        required=True,
        help=
        'Resource that is associated with cloud entity type. Currently four mutually exclusive flags are supported, --project, --billing-account, --folder, --organization.'
    )
    common_args.ProjectArgument(
        help_text_to_overwrite='The Google Cloud Platform project ID.'
    ).AddToParser(resource_group)
    resource_group.add_argument(
        '--billing-account',
        metavar='BILLING_ACCOUNT',
        help=
        'The Google Cloud Platform Billing Account ID to use for this invocation.'
    )
    resource_group.add_argument(
        '--organization',
        metavar='ORGANIZATION_ID',
        help=
        'The Google Cloud Platform Organization ID to use for this invocation.'
    )
    resource_group.add_argument('--folder',
                                metavar='FOLDER_ID',
                                help='Folder ID to use for this invocation.')
예제 #3
0
def AddParentArgs(parser, help_string):
    """Adds arguments for parent of the entities.

  Args:
    parser: parser to which arguments are added.
    help_string: text that is prepended to help for each argument.
  """
    entity_group = parser.add_mutually_exclusive_group()
    entity_group.add_argument(
        '--organization',
        required=False,
        metavar='ORGANIZATION_ID',
        completer=completers.OrganizationCompleter,
        help='{0} associated with this organization.'.format(help_string))

    entity_group.add_argument(
        '--folder',
        required=False,
        metavar='FOLDER_ID',
        help='{0} associated with this folder.'.format(help_string))

    entity_group.add_argument(
        '--billing-account',
        required=False,
        metavar='BILLING_ACCOUNT_ID',
        help='{0} associated with this billing account.'.format(help_string))

    common_args.ProjectArgument(
        help_text_to_prepend='{0} associated with this project.'.format(
            help_string)).AddToParser(entity_group)
예제 #4
0
def AddEntityFlagsToParser(parser, entities):
    """Adds argument mutex group of specified entities to parser.

  Args:
      parser: An argparse parser that you can use to add arguments that go on
        the command line after this command.
      entities: The entities to add.
  """
    resource_group = parser.add_mutually_exclusive_group(
        required=True,
        help='Resource that is associated with cloud entity type.')
    if base.EntityType.ORGANIZATION in entities:
        resource_group.add_argument(
            '--organization',
            metavar='ORGANIZATION_ID',
            help='The Google Cloud Organization ID to use for this invocation.'
        )
    if base.EntityType.FOLDER in entities:
        resource_group.add_argument(
            '--folder',
            metavar='FOLDER_ID',
            help='The Google Cloud Folder ID to use for this invocation.')
    if base.EntityType.BILLING_ACCOUNT in entities:
        resource_group.add_argument(
            '--billing-account',
            metavar='BILLING_ACCOUNT',
            help=
            'The Google Cloud Billing Account ID to use for this invocation.')
    if base.EntityType.PROJECT in entities:
        common_args.ProjectArgument(
            help_text_to_overwrite='The Google Cloud Project ID.').AddToParser(
                resource_group)
예제 #5
0
 def Args(parser):
     flags.GetClusterFlag(positional=True,
                          help_override='The cluster name from '
                          'which to export the '
                          'configurations.').AddToParser(parser)
     flags.GetLocationFlag().AddToParser(parser)
     flags.GetOutputDirFlag().AddToParser(parser)
     common_args.ProjectArgument(
         help_text_to_overwrite='Project ID.').AddToParser(parser)
예제 #6
0
 def Args(parser):
     parent_group = parser.add_mutually_exclusive_group(required=True)
     flags.AddOrganizationArgs(parent_group)
     common_args.ProjectArgument(
         help_text_to_prepend='The project which is the root asset.'
     ).AddToParser(parent_group)
     flags.AddAssetNamesArgs(parser)
     flags.AddContentTypeArgs(parser, required=True)
     flags.AddStartTimeArgs(parser)
     flags.AddEndTimeArgs(parser)
예제 #7
0
 def Args(parser):
     parent_group = parser.add_mutually_exclusive_group(required=True)
     flags.AddOrganizationArgs(
         parent_group,
         'The ID of the organization which is the root asset.')
     common_args.ProjectArgument(
         help_text_to_prepend='The project which is the root asset.'
     ).AddToParser(parent_group)
     flags.AddSnapshotTimeArgs(parser)
     flags.AddAssetTypesArgs(parser)
     flags.AddListContentTypeArgs(parser)
     base.URI_FLAG.RemoveFromParser(parser)
    def Args(parser):
        parent_group = parser.add_mutually_exclusive_group(required=True)
        flags.AddOrganizationArgs(
            parent_group,
            'The ID of the organization which is the root asset.')
        common_args.ProjectArgument(
            help_text_to_prepend='The project which is the root asset.'
        ).AddToParser(parent_group)
        flags.AddFolderArgs(parent_group,
                            'The ID of the folder which is the root asset.')
        flags.AddStatementArgs(parser)
        flags.AddJobReferenceArgs(parser)
        flags.AddPageSize(parser)
        flags.AddPageToken(parser)
        flags.AddTimeout(parser)

        parser.display_info.AddFormat(
            asset_query_printer.ASSET_QUERY_PRINTER_FORMAT)

        asset_query_printer.AssetQueryPrinter.Register(parser)
예제 #9
0
def AddResourceFlagsToParser(parser):
    """Adds flags for the resource ID to the parser.

  Adds --organization, --folder, and --project flags to the parser. The flags
  are added as a required group with a mutex condition, which ensures that the
  user passes in exactly one of the flags.

  Args:
    parser: ArgumentInterceptor, An argparse parser.
  """
    resource_group = parser.add_mutually_exclusive_group(
        required=True,
        help='Resource that is associated with the resource settings.')
    resource_group.add_argument('--organization',
                                metavar='ORGANIZATION_ID',
                                completer=completers.OrganizationCompleter,
                                help='Organization ID.')
    resource_group.add_argument('--folder',
                                metavar='FOLDER_ID',
                                help='Folder ID.')
    common_args.ProjectArgument(
        help_text_to_overwrite='Project ID.').AddToParser(resource_group)
예제 #10
0
def AddResourceParentArgs(parser, noun, verb):
    """Adds project, folder, and organization flags to the parser."""
    parent_resource_group = parser.add_group(
        help='The scope of the {} which defaults to project if unspecified.'.
        format(noun),
        mutex=True,
    )
    common_args.ProjectArgument(
        help_text_to_prepend='The project of the {} {}.'.format(
            noun, verb)).AddToParser(parent_resource_group)
    parent_resource_group.add_argument(
        '--folder',
        metavar='FOLDER_ID',
        type=str,
        help='The folder of the {} {}.'.format(noun, verb),
    )
    parent_resource_group.add_argument(
        '--organization',
        metavar='ORGANIZATION_ID',
        type=str,
        help='The organization of the {} {}.'.format(noun, verb),
    )
예제 #11
0
def AddResourceParentArgs(parser, noun, verb):
  """Adds project, folder, and organization flags to the parser."""
  parent_resource_group = parser.add_group(
      help="""\
      The scope of the {}. If a scope is not specified, the current project is
      used as the default.""".format(noun),
      mutex=True,
  )
  common_args.ProjectArgument(
      help_text_to_prepend='The project of the {} {}.'.format(noun, verb),
      help_text_to_overwrite="""\
      The project name to use. If a project name is not specified, then the
      current project is used. The current project can be listed using gcloud
      config list --format='text(core.project)' and can be set using gcloud
      config set project PROJECTID.

      `--project` and its fallback `{core_project}` property play two roles. It
      specifies the project of the resource to operate on, and also specifies
      the project for API enablement check, quota, and billing. To specify a
      different project for quota and billing, use `--billing-project` or
      `{billing_project}` property.
      """.format(
          core_project=properties.VALUES.core.project,
          billing_project=properties.VALUES.billing.quota_project)).AddToParser(
              parent_resource_group)
  parent_resource_group.add_argument(
      '--folder',
      metavar='FOLDER_ID',
      type=str,
      help='The folder of the {} {}.'.format(noun, verb),
  )
  parent_resource_group.add_argument(
      '--organization',
      metavar='ORGANIZATION_ID',
      type=str,
      help='The organization of the {} {}.'.format(noun, verb),
  )
 def Args(cls, parser):
     parser.display_info.AddFormat(_FORMAT)
     parser.display_info.AddUriFunc(flags.MakeGetUriFunc(
         cls.ReleaseTrack()))
     common_args.ProjectArgument().AddToParser(parser)
예제 #13
0
 def Args(parser):
   flags.GetLocalDirFlag(
       help_override='Directory of package to apply.').AddToParser(parser)
   common_args.ProjectArgument(
       help_text_to_overwrite='Project ID.').AddToParser(parser)
예제 #14
0
    def Args(parser):
        parser.add_argument(
            '--account',
            metavar='ACCOUNT',
            category=base.COMMONLY_USED_FLAGS,
            help='Google Cloud Platform user account to use for invocation.',
            action=actions.StoreProperty(properties.VALUES.core.account))

        # Ideally this would be on the alpha group (since it's alpha) but there are
        # a bunch of problems with doing that. Global flags are treated differently
        # than other flags and flags on the Alpha group are not treated as global.
        # The result is that the flag shows up on every man page as if it was part
        # of the individual command (which is undesirable and breaks every surface
        # spec).
        parser.add_argument(
            '--impersonate-service-account',
            metavar='SERVICE_ACCOUNT_EMAIL',
            help='For this gcloud invocation, all API requests will be '
            'made as the given service account instead of the currently '
            'selected account. This is done without needing to create, '
            'download, and activate a key for the account. In order to '
            'perform operations as the service account, your currently '
            'selected account must have an IAM role that includes the '
            'iam.serviceAccounts.getAccessToken permission for the service '
            'account. The roles/iam.serviceAccountTokenCreator role has '
            'this permission or you may create a custom role.',
            action=actions.StoreProperty(
                properties.VALUES.auth.impersonate_service_account))
        common_args.ProjectArgument().AddToParser(parser)
        parser.add_argument(
            '--billing-project',
            metavar='BILLING_PROJECT',
            category=base.COMMONLY_USED_FLAGS,
            help=
            'The Google Cloud Platform project that will be charged quota for '
            'operations performed in gcloud. If you need to operate on one '
            'project, but need quota against a different project, you can use '
            'this flag to specify the billing project. If both '
            '`billing/quota_project` and `--billing-project` are specified, '
            '`--billing-project` takes precedence. '
            'Run `$ gcloud config set --help` to see more information about '
            '`billing/quota_project`.',
            action=actions.StoreProperty(
                properties.VALUES.billing.quota_project))
        # Must have a None default so properties are not always overridden when the
        # arg is not provided.
        parser.add_argument('--quiet',
                            '-q',
                            default=None,
                            category=base.COMMONLY_USED_FLAGS,
                            action=actions.StoreConstProperty(
                                properties.VALUES.core.disable_prompts, True),
                            help="""\
        Disable all interactive prompts when running gcloud commands. If input
        is required, defaults will be used, or an error will be raised.
        Overrides the default core/disable_prompts property value for this
        command invocation. Must be used at the beginning of commands. This
        is equivalent to setting the environment variable
        `CLOUDSDK_CORE_DISABLE_PROMPTS` to 1.
        """)

        trace_group = parser.add_mutually_exclusive_group()
        trace_group.add_argument(
            '--trace-token',
            default=None,
            action=actions.StoreProperty(properties.VALUES.core.trace_token),
            help=
            'Token used to route traces of service requests for investigation'
            ' of issues.')
        trace_group.add_argument('--trace-email',
                                 metavar='USERNAME',
                                 default=None,
                                 action=actions.StoreProperty(
                                     properties.VALUES.core.trace_email),
                                 hidden=True,
                                 help='THIS ARGUMENT NEEDS HELP TEXT.')
        trace_group.add_argument('--trace-log',
                                 default=None,
                                 action=actions.StoreBooleanProperty(
                                     properties.VALUES.core.trace_log),
                                 hidden=True,
                                 help='THIS ARGUMENT NEEDS HELP TEXT.')
예제 #15
0
    def Args(parser):
        parser.add_argument(
            '--account',
            metavar='ACCOUNT',
            category=base.COMMONLY_USED_FLAGS,
            help='Google Cloud user account to use for invocation.',
            action=actions.StoreProperty(properties.VALUES.core.account))

        # Ideally this would be on the alpha group (since it's alpha) but there are
        # a bunch of problems with doing that. Global flags are treated differently
        # than other flags and flags on the Alpha group are not treated as global.
        # The result is that the flag shows up on every man page as if it was part
        # of the individual command (which is undesirable and breaks every surface
        # spec).
        parser.add_argument(
            '--impersonate-service-account',
            metavar='SERVICE_ACCOUNT_EMAILS',
            help="""\
             For this `gcloud` invocation, all API requests will be
             made as the given service account or target service account in an
             impersonation delegation chain instead of the currently selected
             account. You can specify either a single service account as the
             impersonator, or a comma-separated list of service accounts to
             create an impersonation delegation chain. The impersonation is done
             without needing to create, download, and activate a key for the
             service account or accounts.

             In order to make API requests as a service account, your
             currently selected account must have an IAM role that includes
             the `iam.serviceAccounts.getAccessToken` permission for the
             service account or accounts.

             The `roles/iam.serviceAccountTokenCreator` role has
             the `iam.serviceAccounts.getAccessToken permission`. You can
             also create a custom role.

             You can specify a list of service accounts, separated with
             commas. This creates an impersonation delegation chain in which
             each service account delegates its permissions to the next
             service account in the chain. Each service account in the list
             must have the `roles/iam.serviceAccountTokenCreator` role on the
             next service account in the list. For example, when
             `--impersonate-service-account=`
             ``SERVICE_ACCOUNT_1'',``SERVICE_ACCOUNT_2'',
             the active account must have the
             `roles/iam.serviceAccountTokenCreator` role on
             ``SERVICE_ACCOUNT_1'', which must have the
             `roles/iam.serviceAccountTokenCreator` role on
             ``SERVICE_ACCOUNT_2''.
             ``SERVICE_ACCOUNT_1'' is the impersonated service
             account and ``SERVICE_ACCOUNT_2'' is the delegate.
             """,
            action=actions.StoreProperty(
                properties.VALUES.auth.impersonate_service_account))
        parser.add_argument('--access-token-file',
                            metavar='ACCESS_TOKEN_FILE',
                            help="""\
        A file path to read the access token. Use this flag to
        authenticate `gcloud` with an access token. The credentials of
        the active account (if exists) will be ignored. The file should
        only contain an access token with no other information.
        """,
                            action=actions.StoreProperty(
                                properties.VALUES.auth.access_token_file))
        common_args.ProjectArgument().AddToParser(parser)
        parser.add_argument('--billing-project',
                            metavar='BILLING_PROJECT',
                            category=base.COMMONLY_USED_FLAGS,
                            help="""\
             The Google Cloud project that will be charged quota for
             operations performed in `gcloud`. If you need to operate on one
             project, but need quota against a different project, you can use
             this flag to specify the billing project. If both
             `billing/quota_project` and `--billing-project` are specified,
             `--billing-project` takes precedence.
             Run `$ gcloud config set --help` to see more information about
             `billing/quota_project`.
             """,
                            action=actions.StoreProperty(
                                properties.VALUES.billing.quota_project))
        # Must have a None default so properties are not always overridden when the
        # arg is not provided.
        parser.add_argument('--quiet',
                            '-q',
                            default=None,
                            category=base.COMMONLY_USED_FLAGS,
                            action=actions.StoreConstProperty(
                                properties.VALUES.core.disable_prompts, True),
                            help="""\
        Disable all interactive prompts when running `gcloud` commands. If input
        is required, defaults will be used, or an error will be raised.

        Overrides the default core/disable_prompts property value for this
        command invocation. This is equivalent to setting the environment
        variable `CLOUDSDK_CORE_DISABLE_PROMPTS` to 1.
        """)

        trace_group = parser.add_mutually_exclusive_group()
        trace_group.add_argument(
            '--trace-token',
            default=None,
            action=actions.StoreProperty(properties.VALUES.core.trace_token),
            help=
            'Token used to route traces of service requests for investigation'
            ' of issues.')
        trace_group.add_argument('--trace-email',
                                 metavar='USERNAME',
                                 default=None,
                                 action=actions.StoreProperty(
                                     properties.VALUES.core.trace_email),
                                 hidden=True,
                                 help='THIS ARGUMENT NEEDS HELP TEXT.')
        trace_group.add_argument('--trace-log',
                                 default=None,
                                 action=actions.StoreBooleanProperty(
                                     properties.VALUES.core.trace_log),
                                 hidden=True,
                                 help='THIS ARGUMENT NEEDS HELP TEXT.')
예제 #16
0
def AddParentArgs(parser, project_help_text, org_help_text, folder_help_text):
    parent_group = parser.add_mutually_exclusive_group(required=True)
    common_args.ProjectArgument(
        help_text_to_prepend=project_help_text).AddToParser(parent_group)
    AddOrganizationArgs(parent_group, org_help_text)
    AddFolderArgs(parent_group, folder_help_text)
예제 #17
0
def GetProjectFlag(verb):
    help_text = 'The project of the role you want to {0}.'.format(verb)
    return common_args.ProjectArgument(help_text_to_prepend=help_text)