File: get_change.rb

package info (click to toggle)
ruby-fog-aws 3.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,092 kB
  • sloc: ruby: 72,795; javascript: 14; makefile: 9; sh: 4
file content (54 lines) | stat: -rw-r--r-- 1,796 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Fog
  module AWS
    class DNS
      class Real
        require 'fog/aws/parsers/dns/get_change'

        # returns the current state of a change request
        #
        # ==== Parameters
        # * change_id<~String>
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'Id'<~String>
        #     * 'Status'<~String>
        #     * 'SubmittedAt'<~String>
        #   * status<~Integer> - 200 when successful
        def get_change(change_id)
          # AWS methods return change_ids that looks like '/change/id'.  Let the caller either use
          # that form or just the actual id (which is what this request needs)
          change_id = change_id.sub('/change/', '')

          request({
            :expects => 200,
            :parser  => Fog::Parsers::AWS::DNS::GetChange.new,
            :method  => 'GET',
            :path    => "change/#{change_id}"
          })
        end
      end

      class Mock
        def get_change(change_id)
          response = Excon::Response.new
          # find the record with matching change_id
          # records = data[:zones].values.map{|z| z[:records].values.map{|r| r.values}}.flatten
          change = self.data[:changes][change_id] ||
            raise(Fog::AWS::DNS::NotFound.new("NoSuchChange => Could not find resource with ID: #{change_id}"))

          response.status = 200
          submitted_at = Time.parse(change[:submitted_at])
          response.body = {
            'Id' => change[:id],
            # set as insync after some time
            'Status' => (submitted_at + Fog::Mock.delay) < Time.now ? 'INSYNC' : change[:status],
            'SubmittedAt' => change[:submitted_at]
          }
          response
        end
      end
    end
  end
end