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.')
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.')
def ParseIapSettingsResource(release_track, args): """Parse an IAP setting 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'. Returns: The specified IapSettingsResource """ if args.organization: if args.resource_type: raise calliope_exc.InvalidArgumentException( '--resource-type', '`--resource-type` should not be specified at organization level' ) if args.project: raise calliope_exc.InvalidArgumentException( '--project', '`--project` should not be specified at organization level') return iap_api.IapSettingsResource( release_track, 'organizations/{0}'.format(args.organization)) if args.folder: if args.resource_type: raise calliope_exc.InvalidArgumentException( '--resource-type', '`--resource-type` should not be specified at folder level') if args.project: raise calliope_exc.InvalidArgumentException( '--project', '`--project` should not be specified at folder level') return iap_api.IapSettingsResource(release_track, 'folders/{0}'.format(args.folder)) if args.project: if not args.resource_type: return iap_api.IapSettingsResource( release_track, 'projects/{0}'.format(args.project)) else: if args.resource_type == WEB_RESOURCE_TYPE: return iap_api.IapSettingsResource( release_track, 'projects/{0}/iap_web'.format(args.project)) elif args.resource_type == APP_ENGINE_RESOURCE_TYPE: if not args.service: raise calliope_exc.RequiredArgumentException( '--service', '`--service` must be specified for ' '`--resource-type=app-engine`.') else: if args.version: return iap_api.IapSettingsResource( release_track, 'projects/{0}/iap_web/appengine-{1}/services/{2}/versions/{3}' .format(args.project, args.project, args.service, args.version)) else: return iap_api.IapSettingsResource( release_track, 'projects/{0}/iap_web/appengine-{1}/services/{2}'. format(args.project, args.project, args.service)) elif args.resource_type == COMPUTE_RESOURCE_TYPE: if args.service: return iap_api.IapSettingsResource( release_track, 'projects/{0}/iap_web/compute/services/{1}'.format( args.project, args.service)) else: return iap_api.IapSettingsResource( release_track, 'projects/{0}/iap_web/compute'.format(args.project)) else: raise iap_exc.InvalidIapIamResourceError( 'Unsupported IAP settings resource type.') raise iap_exc.InvalidIapIamResourceError( 'Could not parse IAP settings resource.')