Class: OvhDnsup::DomainManager
- Inherits:
-
Object
- Object
- OvhDnsup::DomainManager
- Defined in:
- lib/ovh_dnsup/domain_manager.rb
Overview
Allows managing a DNS zone.
Instance Method Summary collapse
- #application_key ⇒ Object
- #application_secret ⇒ Object
- #delete_all_sessions ⇒ Object
- #delete_session(id) ⇒ Object
- #endpoint ⇒ Object
-
#initialize(args) ⇒ DomainManager
constructor
A new instance of DomainManager.
- #list_sessions(all: false) ⇒ Object
- #list_zone(domain) ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #register ⇒ Object
- #state ⇒ Object
- #state=(h) ⇒ Object
- #subdomain_type_map(domain, sub) ⇒ Object
- #unregister(all: false) ⇒ Object
Constructor Details
#initialize(args) ⇒ DomainManager
Returns a new instance of DomainManager.
21 22 23 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 21 def initialize(args) @api = OvhApi.new(args) end |
Instance Method Details
#application_key ⇒ Object
26 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 26 def application_key; @api.application_key; end |
#application_secret ⇒ Object
27 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 27 def application_secret; @api.application_secret; end |
#delete_all_sessions ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 140 def delete_all_sessions() cred_id = @api.get('auth/currentCredential')['credentialId'] other_ids = @api.get('me/api/credential').select {|id| id != cred_id} other_ids.each &method(:delete_session) delete_session(cred_id) end |
#delete_session(id) ⇒ Object
136 137 138 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 136 def delete_session(id) @api.delete("me/api/credential/#{id}") end |
#endpoint ⇒ Object
25 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 25 def endpoint; @api.endpoint; end |
#list_sessions(all: false) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 99 def list_sessions(all: false) params = nil if !all app_id = @api.get('auth/currentCredential')['applicationId'] params = {'applicationId' => app_id} end cred_ids = @api.get('me/api/credential', params) cred_ids.each do |id| info = @api.get("me/api/credential/#{id}") next if info['status'] == 'expired' && !all app_info = @api.get("me/api/credential/#{id}/application") if all puts "id: #{id}" puts " app: #{app_info['name']} (#{app_info['description']})" if all puts " status: #{info['status']}" if all puts " creation: #{info['creation']} expiration: #{info['expiration']}" info['rules'].each do |rule| if /^\/domain\/zone\/(?<zone>[^\/]+)\/record\/(?<eid>[^\/]+)$/ =~ rule['path'] then begin entry = @api.get("domain/zone/#{zone}/record/#{eid}") puts " zone: #{zone} subdomain: #{entry['subDomain']}" rescue OvhException end end if rule['path'] == '/domain/zone/*' puts " domain management" end end # info['rules'].each end # cred_ids.each end |
#list_zone(domain) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 69 def list_zone(domain) ids = @api.get("domain/zone/#{domain}/record") ids.each do |id| record = @api.get("domain/zone/#{domain}/record/#{id}") if !record['subDomain'].empty? full_domain = "#{record['subDomain']}.#{domain}" else full_domain = domain end puts "#{record['fieldType']} #{full_domain} => #{record['target']}" end end |
#login ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 56 def login @api.login [{:method => 'GET', :path => '/domain/zone/*'}, {:method => 'GET', :path => '/me/api/application'}, {:method => 'DELETE', :path => '/me/api/application/*'}, {:method => 'GET', :path => '/me/api/credential'}, {:method => 'GET', :path => '/me/api/credential/*'}, {:method => 'DELETE', :path => '/me/api/credential/*'}] end |
#logout ⇒ Object
65 66 67 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 65 def logout @api.post('auth/logout') end |
#register ⇒ Object
37 38 39 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 37 def register @api.register end |
#state ⇒ Object
29 30 31 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 29 def state @api.state end |
#state=(h) ⇒ Object
33 34 35 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 33 def state= h @api.state = h end |
#subdomain_type_map(domain, sub) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 82 def subdomain_type_map(domain, sub) # get IDs of all entries of this subdomain ids = @api.get("domain/zone/#{domain}/record", subDomain: sub) type_map = {} ids.each do |id| record = @api.get("domain/zone/#{domain}/record/#{id}") field_type = record['fieldType'] if ['A', 'AAAA'].include? field_type type_map[field_type] = id end end type_map end |
#unregister(all: false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ovh_dnsup/domain_manager.rb', line 41 def unregister(all: false) response = @api.get('auth/currentCredential') app_id = response['applicationId'] # unregister all applications other if all other_apps = @api.get('me/api/application').select {|id| id != app_id } other_apps.each do |id| @api.delete("me/api/application/#{id}") end end @api.delete("me/api/application/#{app_id}") end |