Class: Fog::DNS::Google::Mock
- Inherits:
-
Object
- Object
- Fog::DNS::Google::Mock
- Includes:
- Google::Shared
- Defined in:
- lib/fog/google/dns.rb,
lib/fog/google/requests/dns/get_change.rb,
lib/fog/google/requests/dns/get_project.rb,
lib/fog/google/requests/dns/list_changes.rb,
lib/fog/google/requests/dns/create_change.rb,
lib/fog/google/requests/dns/get_managed_zone.rb,
lib/fog/google/requests/dns/list_managed_zones.rb,
lib/fog/google/requests/dns/create_managed_zone.rb,
lib/fog/google/requests/dns/delete_managed_zone.rb,
lib/fog/google/requests/dns/list_resource_record_sets.rb
Instance Attribute Summary
Attributes included from Google::Shared
#api_url, #api_version, #project
Class Method Summary collapse
Instance Method Summary collapse
- #create_change(zone_name_or_id, additions = [], deletions = []) ⇒ Object
- #create_managed_zone(name, dns_name, description) ⇒ Object
- #data(project = @project) ⇒ Object
- #delete_managed_zone(name_or_id) ⇒ Object
- #get_change(zone_name_or_id, identity) ⇒ Object
- #get_managed_zone(name_or_id) ⇒ Object
- #get_project(identity) ⇒ Object
-
#initialize(options) ⇒ Mock
constructor
A new instance of Mock.
- #list_changes(zone_name_or_id) ⇒ Object
- #list_managed_zones ⇒ Object
- #list_resource_record_sets(zone_name_or_id, options = {}) ⇒ Object
- #reset_data ⇒ Object
Methods included from Google::Shared
#build_excon_response, #initialize_google_client, #new_pk12_google_client, #request, #shared_initialize
Constructor Details
#initialize(options) ⇒ Mock
Returns a new instance of Mock.
57 58 59 |
# File 'lib/fog/google/dns.rb', line 57 def initialize() shared_initialize([:google_project], GOOGLE_DNS_API_VERSION, GOOGLE_DNS_BASE_URL) end |
Class Method Details
.data(api_version) ⇒ Object
61 62 63 |
# File 'lib/fog/google/dns.rb', line 61 def self.data(api_version) @data ||= {} end |
.reset ⇒ Object
65 66 67 |
# File 'lib/fog/google/dns.rb', line 65 def self.reset @data = nil end |
Instance Method Details
#create_change(zone_name_or_id, additions = [], deletions = []) ⇒ Object
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 55 56 57 58 59 60 |
# File 'lib/fog/google/requests/dns/create_change.rb', line 26 def create_change(zone_name_or_id, additions = [], deletions = []) if self.data[:managed_zones].has_key?(zone_name_or_id) zone = self.data[:managed_zones][zone_name_or_id] else zone = self.data[:managed_zones].values.find { |zone| zone['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 = self.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| self.data[:resource_record_sets][zone['id']] << add end id = self.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 |
#create_managed_zone(name, dns_name, description) ⇒ Object
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fog/google/requests/dns/create_managed_zone.rb', line 27 def create_managed_zone(name, dns_name, description) id = Fog::Mock.random_numbers(19).to_s data = { 'kind' => 'dns#managedZone', 'id' => id, 'creationTime' => DateTime.now.strftime('%FT%T.%LZ'), 'name' => name, 'dnsName' => dns_name, 'description' => description, 'nameServers' => [ 'ns-cloud-e1.googledomains.com.', 'ns-cloud-e2.googledomains.com.', 'ns-cloud-e3.googledomains.com.', 'ns-cloud-e4.googledomains.com.', ], } self.data[:managed_zones][id] = data self.data[:resource_record_sets][id] = [ { 'kind' => 'dns#resourceRecordSet', 'name' => dns_name, 'type' => 'NS', 'ttl' => 21600, 'rrdatas' => [ 'ns-cloud-c1.googledomains.com.', 'ns-cloud-c2.googledomains.com.', 'ns-cloud-c3.googledomains.com.', 'ns-cloud-c4.googledomains.com.', ] }, { 'kind' => 'dns#resourceRecordSet', 'name' => dns_name, 'type' => 'SOA', 'ttl' => 21600, 'rrdatas' => [ 'ns-cloud-c1.googledomains.com. dns-admin.google.com. 0 21600 3600 1209600 300', ] }, ] self.data[:changes][id] = [ { 'kind' => 'dns#change', 'id' => '0', 'startTime' => DateTime.now.strftime('%FT%T.%LZ'), 'status' => 'done', 'additions' => self.data[:resource_record_sets][id], }, ] build_excon_response(data) end |
#data(project = @project) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/fog/google/dns.rb', line 69 def data(project=@project) self.class.data(api_version)[project] ||= { :managed_zones => {}, :resource_record_sets => {}, :changes => {}, } end |
#delete_managed_zone(name_or_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/google/requests/dns/delete_managed_zone.rb', line 21 def delete_managed_zone(name_or_id) if self.data[:managed_zones].has_key?(name_or_id) self.data[:managed_zones].delete(name_or_id) elsif zone = self.data[:managed_zones].values.find { |zone| zone['name'] = name_or_id } self.data[:managed_zones].delete(zone['id']) else raise Fog::Errors::NotFound, "The 'parameters.managedZone' resource named '#{name_or_id}' does not exist." end build_excon_response(nil) end |
#get_change(zone_name_or_id, identity) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/google/requests/dns/get_change.rb', line 22 def get_change(zone_name_or_id, identity) if self.data[:managed_zones].has_key?(zone_name_or_id) zone = self.data[:managed_zones][zone_name_or_id] else zone = self.data[:managed_zones].values.find { |zone| zone['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 unless data = self.data[:changes][zone['id']].find { |c| c['id'] == identity } raise Fog::Errors::NotFound, "The 'parameters.changeId' resource named '#{identity}' does not exist." end build_excon_response(data) end |
#get_managed_zone(name_or_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fog/google/requests/dns/get_managed_zone.rb', line 21 def get_managed_zone(name_or_id) if self.data[:managed_zones].has_key?(name_or_id) data = self.data[:managed_zones][name_or_id] else data = self.data[:managed_zones].values.find { |zone| zone['name'] = name_or_id } end unless data raise Fog::Errors::NotFound, "The 'parameters.managedZone' resource named '#{name_or_id}' does not exist." end build_excon_response(data) end |
#get_project(identity) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fog/google/requests/dns/get_project.rb', line 21 def get_project(identity) body = { 'kind' => 'dns#project', 'number' => Fog::Mock.random_numbers(12).to_s, 'id' => identity, 'quota' => { 'kind' => 'dns#quota', 'managedZones' => 100, 'rrsetsPerManagedZone' => 10000, 'rrsetAdditionsPerChange' => 100, 'rrsetDeletionsPerChange'=>100, 'totalRrdataSizePerChange' => 10000, 'resourceRecordsPerRrset' => 20, } } build_excon_response(body) end |
#list_changes(zone_name_or_id) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/google/requests/dns/list_changes.rb', line 21 def list_changes(zone_name_or_id) if self.data[:managed_zones].has_key?(zone_name_or_id) zone = self.data[:managed_zones][zone_name_or_id] else zone = self.data[:managed_zones].values.find { |zone| zone['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 body = { 'kind' => 'dns#changesListResponse', 'changes' => self.data[:changes][zone['id']], } build_excon_response(body) end |
#list_managed_zones ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/fog/google/requests/dns/list_managed_zones.rb', line 20 def list_managed_zones() body = { 'kind' => 'dns#managedZonesListResponse', 'managedZones' => self.data[:managed_zones].values, } build_excon_response(body) end |
#list_resource_record_sets(zone_name_or_id, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/google/requests/dns/list_resource_record_sets.rb', line 25 def list_resource_record_sets(zone_name_or_id, = {}) if self.data[:managed_zones].has_key?(zone_name_or_id) zone = self.data[:managed_zones][zone_name_or_id] else zone = self.data[:managed_zones].values.find { |zone| zone['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 rrsets = self.data[:resource_record_sets][zone['id']] if .has_key?(:name) && .has_key?(:type) rrsets.delete_if { |rrset| rrset['name'] != [:name] || rrset['type'] != [:type] } end body = { 'kind' => 'dns#resourceRecordSetsListResponse', 'rrsets' => rrsets, } build_excon_response(body) end |
#reset_data ⇒ Object
77 78 79 |
# File 'lib/fog/google/dns.rb', line 77 def reset_data self.class.data(api_version).delete(@project) end |