Sha256: 489bd7fe7ea7611028e6cc166cf76ec290af1e15eeecbb084a480b6609fb480f

Contents?: true

Size: 2 KB

Versions: 14

Compression:

Stored size: 2 KB

Contents

module Fog
  module DNS
    class Google
      ##
      # Atomically updates a ResourceRecordSet collection.
      #
      # @see https://cloud.google.com/dns/api/v1/changes/create
      class Real
        def create_change(zone_name_or_id, additions = [], deletions = [])
          api_method = @dns.changes.create
          parameters = {
            "project" => @project,
            "managedZone" => zone_name_or_id
          }

          body = {
            "additions" => additions,
            "deletions" => deletions
          }

          request(api_method, parameters, body)
        end
      end

      class Mock
        def create_change(zone_name_or_id, additions = [], deletions = [])
          if data[:managed_zones].key?(zone_name_or_id)
            zone = data[:managed_zones][zone_name_or_id]
          else
            zone = data[:managed_zones].values.detect { |z| z["name"] = zone_name_or_id }
          end

          unless zone
            raise Fog::Errors::NotFound, "The 'parameters.managedZone' resource named '#{zone_name_or_id}' does not exist."
          end

          deletions.each do |del|
            rrset = data[:resource_record_sets][zone["id"]].reject! { |r| r["name"] == del["name"] && r["type"] == del["type"] }
            unless rrset
              raise Fog::Errors::NotFound, "The 'entity.change.deletions[0]' resource named '#{del['name']} ('#{del['type']})' does not exist."
            end
          end

          additions.each do |add|
            data[:resource_record_sets][zone["id"]] << add
          end

          id = data[:changes][zone["id"]].max_by { |c| c["id"] }["id"]
          data = {
            "kind" => 'dns#change',
            "id" => (id.to_i + 1).to_s,
            "startTime" => DateTime.now.strftime("%FT%T.%LZ"),
            "status" => "done",
            "additions" => additions,
            "deletions" => deletions
          }
          self.data[:changes][zone["id"]] << data

          build_excon_response(data)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fog-google-0.6.0 lib/fog/dns/google/requests/create_change.rb
fog-google-0.5.5 lib/fog/dns/google/requests/create_change.rb
fog-google-0.5.4 lib/fog/dns/google/requests/create_change.rb
fog-google-0.5.3 lib/fog/dns/google/requests/create_change.rb
fog-google-0.5.2 lib/fog/dns/google/requests/create_change.rb
fog-google-0.5.1 lib/fog/dns/google/requests/create_change.rb
fog-google-0.5.0 lib/fog/dns/google/requests/create_change.rb
fog-google-0.4.2 lib/fog/dns/google/requests/create_change.rb
fog-google-0.4.1 lib/fog/dns/google/requests/create_change.rb
fog-google-0.4.0 lib/fog/dns/google/requests/create_change.rb
fog-google-0.3.2 lib/fog/dns/google/requests/create_change.rb
fog-google-0.3.1 lib/fog/dns/google/requests/create_change.rb
fog-google-0.3.0 lib/fog/dns/google/requests/create_change.rb
fog-google-0.2.0 lib/fog/dns/google/requests/create_change.rb