Class: Shards::Dns

Inherits:
Base
  • Object
show all
Defined in:
lib/shards/dns.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#subdomain_param

Attributes included from Meta

#config

Instance Method Summary collapse

Methods inherited from Base

#default_region, method_list, #set_config

Methods included from Meta

#add, #custom_yaml, #default_yaml, #get_config, #method_list, #output, #print_output, #proxy, #proxy_user, #reset_output, #run, #ssh_conn, #test_env?, #write_extra_config_dirs, #yaml_file

Constructor Details

#initialize(stage:, domain: nil) ⇒ Dns

Returns a new instance of Dns.



16
17
18
19
20
21
22
23
24
# File 'lib/shards/dns.rb', line 16

def initialize stage:, domain: nil
  set_config
  @stage=stage
  @domain=domain.downcase if domain
  reset_output
  @r53 = Aws::Route53::Client.new( region: default_region )
  @ttl=300
  @type='CNAME'
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



12
13
14
# File 'lib/shards/dns.rb', line 12

def action
  @action
end

#aws_route53_respObject

Returns the value of attribute aws_route53_resp.



13
14
15
# File 'lib/shards/dns.rb', line 13

def aws_route53_resp
  @aws_route53_resp
end

#begin_commentObject (readonly)

Returns the value of attribute begin_comment.



12
13
14
# File 'lib/shards/dns.rb', line 12

def begin_comment
  @begin_comment
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/shards/dns.rb', line 12

def domain
  @domain
end

#r53Object

Returns the value of attribute r53.



13
14
15
# File 'lib/shards/dns.rb', line 13

def r53
  @r53
end

#resource_recordsObject



26
27
28
# File 'lib/shards/dns.rb', line 26

def resource_records
  @resource_records||= [ { value: target } ]
end

#stageObject (readonly)

Returns the value of attribute stage.



12
13
14
# File 'lib/shards/dns.rb', line 12

def stage
  @stage
end

#ttlObject

Returns the value of attribute ttl.



13
14
15
# File 'lib/shards/dns.rb', line 13

def ttl
  @ttl
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/shards/dns.rb', line 13

def type
  @type
end

Instance Method Details

#deleteObject



45
46
47
# File 'lib/shards/dns.rb', line 45

def delete
  @aws_route53_resp = r53.change_resource_record_sets r53delete
end

#exist?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/shards/dns.rb', line 49

def exist?
  !record_list.empty?
end

#host_paramObject



74
75
76
# File 'lib/shards/dns.rb', line 74

def host_param
  subdomain_param || host
end

#include_target?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/shards/dns.rb', line 58

def include_target?
  exist? and record_data[:resource_records].include?( { value: target} )
end

#record_dataObject



53
54
55
56
# File 'lib/shards/dns.rb', line 53

def record_data
  data=record_list.first || {}
  data.to_h
end

#record_listObject



62
63
64
# File 'lib/shards/dns.rb', line 62

def record_list
  record_sets.select { |x| x.name.include? host_param }
end

#record_setsObject



66
67
68
69
70
71
72
# File 'lib/shards/dns.rb', line 66

def record_sets
  r53.list_resource_record_sets({
    hosted_zone_id: zone,
    start_record_name: host_param,
    max_items: 20
  }).resource_record_sets
end

#set(dryrun: true) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/shards/dns.rb', line 30

def set dryrun: true
  if dryrun
    dryrun_message
  else
    creating_route53_message
    print_output
    set_aws_route53_record
  end
  print_output
end

#set_aws_route53_recordObject



41
42
43
# File 'lib/shards/dns.rb', line 41

def set_aws_route53_record
  @aws_route53_resp = r53.change_resource_record_sets r53upsert
end