Class: Gcloud::Dns::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/dns/service.rb

Overview

Represents the service to DNS, exposing the API calls.

Constant Summary collapse

API =

Alias to the Google Client API module

Google::Apis::DnsV1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, credentials, retries: nil, timeout: nil) ⇒ Service

Creates a new Service instance.



35
36
37
38
39
40
41
42
43
44
# File 'lib/gcloud/dns/service.rb', line 35

def initialize project, credentials, retries: nil, timeout: nil
  @project = project
  @credentials = credentials
  @service = API::DnsService.new
  @service.client_options.application_name    = "gcloud-ruby"
  @service.client_options.application_version = Gcloud::VERSION
  @service.request_options.retries = retries || 3
  @service.request_options.timeout_sec = timeout if timeout
  @service.authorization = @credentials.client
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



31
32
33
# File 'lib/gcloud/dns/service.rb', line 31

def credentials
  @credentials
end

#mocked_serviceObject

Returns the value of attribute mocked_service.



50
51
52
# File 'lib/gcloud/dns/service.rb', line 50

def mocked_service
  @mocked_service
end

#projectObject

Returns the value of attribute project.



30
31
32
# File 'lib/gcloud/dns/service.rb', line 30

def project
  @project
end

Class Method Details

.fqdn(name, origin_dns) ⇒ Object

Fully Qualified Domain Name



143
144
145
146
147
148
149
150
151
# File 'lib/gcloud/dns/service.rb', line 143

def self.fqdn name, origin_dns
  name = name.to_s.strip
  return name if self.ip_addr? name
  name = origin_dns if name.empty?
  name = origin_dns if name == "@"
  name = "#{name}.#{origin_dns}" unless name.include? "."
  name = "#{name}." unless name.end_with? "."
  name
end

.ip_addr?(name) ⇒ Boolean

Returns:

  • (Boolean)


155
156
157
158
159
160
# File 'lib/gcloud/dns/service.rb', line 155

def self.ip_addr? name
  IPAddr.new name
  true
rescue IPAddr::Error
  false
end

Instance Method Details

#create_change(zone_id, additions, deletions) ⇒ Object

Returns Google::Apis::DnsV1::Change



119
120
121
122
123
124
125
126
127
128
# File 'lib/gcloud/dns/service.rb', line 119

def create_change zone_id, additions, deletions
  change = Google::Apis::DnsV1::Change.new(
    kind: "dns#change",
    additions: Array(additions),
    deletions: Array(deletions)
  )
  service.create_change @project, zone_id, change
rescue Google::Apis::Error => e
  raise Gcloud::Error.from_error(e)
end

#create_zone(zone_name, zone_dns, description: nil, name_server_set: nil) ⇒ Object

Returns Google::Apis::DnsV1::ManagedZone



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gcloud/dns/service.rb', line 78

def create_zone zone_name, zone_dns, description: nil,
                name_server_set: nil
  managed_zone = Google::Apis::DnsV1::ManagedZone.new(
    kind: "dns#managedZone",
    name: zone_name,
    dns_name: zone_dns,
    description: (description || ""),
    name_server_set: name_server_set
  )
  service.create_managed_zone @project, managed_zone
rescue Google::Apis::Error => e
  raise Gcloud::Error.from_error(e)
end

#delete_zone(zone_id) ⇒ Object



92
93
94
95
96
# File 'lib/gcloud/dns/service.rb', line 92

def delete_zone zone_id
  service.delete_managed_zone @project, zone_id
rescue Google::Apis::Error => e
  raise Gcloud::Error.from_error(e)
end

#get_change(zone_id, change_id) ⇒ Object

Returns Google::Apis::DnsV1::Change



100
101
102
103
104
# File 'lib/gcloud/dns/service.rb', line 100

def get_change zone_id, change_id
  service.get_change @project, zone_id, change_id
rescue Google::Apis::Error => e
  raise Gcloud::Error.from_error(e)
end

#get_project(project_id = @project) ⇒ Object

Returns Google::Apis::DnsV1::Project



54
55
56
57
58
# File 'lib/gcloud/dns/service.rb', line 54

def get_project project_id = @project
  service.get_project project_id
rescue Google::Apis::Error => e
  raise Gcloud::Error.from_error(e)
end

#get_zone(zone_id) ⇒ Object

Returns Google::Apis::DnsV1::ManagedZone



62
63
64
65
66
# File 'lib/gcloud/dns/service.rb', line 62

def get_zone zone_id
  service.get_managed_zone @project, zone_id
rescue Google::Apis::Error => e
  raise Gcloud::Error.from_error(e)
end

#inspectObject



162
163
164
# File 'lib/gcloud/dns/service.rb', line 162

def inspect
  "#{self.class}(#{@project})"
end

#list_changes(zone_id, token: nil, max: nil, order: nil, sort: nil) ⇒ Object

Returns Google::Apis::DnsV1::ListChangesResponse



108
109
110
111
112
113
114
115
# File 'lib/gcloud/dns/service.rb', line 108

def list_changes zone_id, token: nil, max: nil, order: nil, sort: nil
  service.list_changes @project, zone_id, max_results: max,
                                          page_token: token,
                                          sort_by: sort,
                                          sort_order: order
rescue Google::Apis::Error => e
  raise Gcloud::Error.from_error(e)
end

#list_records(zone_id, name = nil, type = nil, token: nil, max: nil) ⇒ Object

Returns Google::Apis::DnsV1::ListResourceRecordSetsResponse



132
133
134
135
136
137
138
139
# File 'lib/gcloud/dns/service.rb', line 132

def list_records zone_id, name = nil, type = nil, token: nil, max: nil
  service.list_resource_record_sets @project, zone_id, max_results: max,
                                                       name: name,
                                                       page_token: token,
                                                       type: type
rescue Google::Apis::Error => e
  raise Gcloud::Error.from_error(e)
end

#list_zones(token: nil, max: nil) ⇒ Object

Returns Google::Apis::DnsV1::ListManagedZonesResponse



70
71
72
73
74
# File 'lib/gcloud/dns/service.rb', line 70

def list_zones token: nil, max: nil
  service.list_managed_zones @project, max_results: max, page_token: token
rescue Google::Apis::Error => e
  raise Gcloud::Error.from_error(e)
end

#serviceObject



46
47
48
49
# File 'lib/gcloud/dns/service.rb', line 46

def service
  return mocked_service if mocked_service
  @service
end