Sha256: 4fd6faf01c2e9359b1ad7395a0c606758b82ef4d4a44eaad78ddf64e7be551e5

Contents?: true

Size: 1.9 KB

Versions: 70

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module Aws
  module Route53
    module Plugins

      # The Amazon Route 53 API returns hosted zones and request Ids as strings
      # formatted like:
      #
      #     '/hostedzone/ID'
      #     '/change/ID'
      #
      # However, their API does not accept Ids with the '/hostedzone/' or
      # '/change/' prefixes. This plugin removes those prefixes before
      # serializing their Ids onto the request. This allows a user to
      # use the prefixed Ids returned in {Aws::Route53::Client} responses.
      #
      # @api private
      class IdFix < Seahorse::Client::Plugin

        class Handler < Seahorse::Client::Handler

          def call(context)
            remove_id_prefixes(context.params)
            @handler.call(context)
          end

          private

          def remove_id_prefixes(params)
            # Many operations accept of :id or :hosted_zone_id as a root-level
            # param, pruning prefixes from those.
            [:id, :hosted_zone_id, :delegation_set_id].each do |key|
              params[key] = remove_prefix(params[key]) if params.to_hash.key?(key)
            end

            # The `#change_resource_record_sets operation` has a deeply nested
            # target with a :hosted_zone_id that needs to be pruned.
            if params[:change_batch]
              params[:change_batch][:changes].each do |batch|
                if target = batch[:resource_record_set][:alias_target]
                  target[:hosted_zone_id] = remove_prefix(target[:hosted_zone_id])
                end
              end
            end
          end

          def remove_prefix(str)
            str.sub(/^\/(hostedzone|change|delegationset)\//, '')
          end

        end

        # Run this handler after params have been validated, but before
        # they are serialized onto the request
        handler(Handler, priority: 99, step: :build)

      end
    end
  end
end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
aws-sdk-route53-1.87.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.86.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.85.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.84.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.83.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.82.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.81.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.80.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.79.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.78.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.77.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.76.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.75.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.74.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.73.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.72.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.71.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.70.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.69.0 lib/aws-sdk-route53/plugins/id_fix.rb
aws-sdk-route53-1.68.0 lib/aws-sdk-route53/plugins/id_fix.rb