- release_tracks: [ALPHA, BETA, GA]
  command_type: GENERIC

  help_text:
    brief: |
      Replace all existing service perimeters.
    description: |
      Replace all existing service perimeter in specified access policy with service perimeters
      specified in a file.

      ## EXAMPLES

      To replace all perimeters within a policy, using etag:

        $ {command} my-policy-number --source-file=path-to-file-containing-all-replacement-service-perimeters.yaml --etag=optional-latest-etag-of-policy

      To replace all perimeters within a policy, without using etag:

        $ {command} my-policy-number --source-file=path-to-file-containing-all-replacement-service-perimeters.yaml

  request:
    collection: accesscontextmanager.accessPolicies.servicePerimeters
    ALPHA:
      api_version: v1alpha
      method: replaceAll
    BETA:
      api_version: v1
      method: replaceAll
    GA:
      api_version: v1
      method: replaceAll
  response:
    ALPHA:
      modify_response_hooks:
      - googlecloudsdk.command_lib.accesscontextmanager.perimeters:ParseReplaceServicePerimetersResponseAlpha
    BETA:
      modify_response_hooks:
      - googlecloudsdk.command_lib.accesscontextmanager.perimeters:ParseReplaceServicePerimetersResponseGA
    GA:
      modify_response_hooks:
      - googlecloudsdk.command_lib.accesscontextmanager.perimeters:ParseReplaceServicePerimetersResponseGA

  arguments:
    resource:
      help_text: The access policy that contains the perimeters you want to replace.
      spec: !REF googlecloudsdk.command_lib.accesscontextmanager.resources:policy
      override_resource_collection: true

    params:
    - api_field: replaceServicePerimetersRequest.etag
      arg_name: etag
      required: false
      help_text: |
        An etag which specifies the version of the Access Policy. Only etags
        that represent the latest version of the Access Policy will be accepted.
      repeated: false
    - api_field: replaceServicePerimetersRequest.servicePerimeters
      arg_name: source-file
      required: true
      help_text: |
        Path to a file containing a list of service perimeters.

        An service perimeter file is a YAML-formatted list of service perimeters,
        which are YAML objects representing a Condition as described in
        the API reference. For example:

        ```
        - name: my_perimeter
          title: My Perimeter
          description: Perimeter for foo.
          perimeterType: PERIMETER_TYPE_REGULAR
          status:
            resources:
            - projects/0123456789
            accessLevels:
            - accessPolicies/my_policy/accessLevels/my_level
            restrictedServices:
            - storage.googleapis.com
        ```

        For more information about the alpha version, see:
        https://cloud.google.com/access-context-manager/docs/reference/rest/v1alpha/accessPolicies.servicePerimeters
        For other versions, see:
        https://cloud.google.com/access-context-manager/docs/reference/rest/v1/accessPolicies.servicePerimeters
      repeated: false
      ALPHA:
        processor: googlecloudsdk.command_lib.accesscontextmanager.perimeters:ParseServicePerimetersAlpha
      BETA:
        processor: googlecloudsdk.command_lib.accesscontextmanager.perimeters:ParseServicePerimetersGA
      GA:
        processor: googlecloudsdk.command_lib.accesscontextmanager.perimeters:ParseServicePerimetersGA
