Exemplo n.º 1
0
def ParseIapResource(release_track, args):
    """Parse an IAP resource from the input arguments.

  Args:
    release_track: base.ReleaseTrack, release track of command.
    args: an argparse namespace. All the arguments that were provided to this
      command invocation.

  Raises:
    calliope_exc.InvalidArgumentException: if `--version` was specified with
        resource type 'backend-services'.
    iap_exc.InvalidIapIamResourceError: if an IapIamResource could not be parsed
        from the arguments.

  Returns:
    The specified IapIamResource
  """
    project = properties.VALUES.core.project.GetOrFail()
    if args.resource_type:
        if args.resource_type == APP_ENGINE_RESOURCE_TYPE:
            if args.service:
                raise calliope_exc.InvalidArgumentException(
                    '--service', '`--service` cannot be specified for '
                    '`--resource-type=app-engine`.')
            return iap_api.AppEngineApplication(release_track, project)
        elif args.resource_type == BACKEND_SERVICES_RESOURCE_TYPE:
            if not args.service:
                raise calliope_exc.RequiredArgumentException(
                    '--service', '`--service` must be specified for '
                    '`--resource-type=backend-services`.')
            return iap_api.BackendService(release_track, project, args.service)

    raise iap_exc.InvalidIapIamResourceError('Could not parse IAP resource.')
Exemplo n.º 2
0
def ParseIapIamResource(release_track, args):
    """Parse an IAP IAM resource from the input arguments.

  Args:
    release_track: base.ReleaseTrack, release track of command.
    args: an argparse namespace. All the arguments that were provided to this
      command invocation.

  Raises:
    calliope_exc.InvalidArgumentException: if a provided argument does not apply
        to the specified resource type.
    iap_exc.InvalidIapIamResourceError: if an IapIamResource could not be parsed
        from the arguments.

  Returns:
    The specified IapIamResource
  """
    project = properties.VALUES.core.project.GetOrFail()
    if not args.resource_type:
        if args.service:
            raise calliope_exc.InvalidArgumentException(
                '--service',
                '`--service` cannot be specified without `--resource-type`.')
        if args.version:
            raise calliope_exc.InvalidArgumentException(
                '--version',
                '`--version` cannot be specified without `--resource-type`.')
        return iap_api.IAPWeb(release_track, project)
    elif args.resource_type == APP_ENGINE_RESOURCE_TYPE:
        if args.service and args.version:
            return iap_api.AppEngineServiceVersion(release_track, project,
                                                   args.service, args.version)
        elif args.service:
            return iap_api.AppEngineService(release_track, project,
                                            args.service)
        if args.version:
            raise calliope_exc.InvalidArgumentException(
                '--version',
                '`--version` cannot be specified without `--service`.')
        return iap_api.AppEngineApplication(release_track, project)
    elif args.resource_type == BACKEND_SERVICES_RESOURCE_TYPE:
        if args.version:
            raise calliope_exc.InvalidArgumentException(
                '--version', '`--version` cannot be specified for '
                '`--resource-type=backend-services`.')
        if args.service:
            return iap_api.BackendService(release_track, project, args.service)
        return iap_api.BackendServices(release_track, project)

    # This shouldn't be reachable, based on the IAP IAM resource parsing logic.
    raise iap_exc.InvalidIapIamResourceError(
        'Could not parse IAP IAM resource.')