Class: LiveTribe::Debut::AWS

Inherits:
Provider show all
Defined in:
lib/debut/aws.rb

Instance Method Summary collapse

Methods inherited from Provider

inherited

Constructor Details

#initialize(attributes) ⇒ AWS

Returns a new instance of AWS.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/debut/aws.rb', line 29

def initialize(attributes)
  attributes = attributes.dup

  attributes[:use_iam_profile] = !ENV.include?('AWS_ACCESS_KEY')
  attributes[:use_iam_profile] = !ENV.include?('AWS_SECRET_ACCESS_KEY')

  if attributes[:use_iam_profile]
    puts 'Using IAM profile'
  end

  @dns = Fog::DNS.new(attributes)

  @hostname = LiveTribe::Debut::Debutante::USE_ENVIRONMENT
  @name = LiveTribe::Debut::Debutante::USE_ENVIRONMENT
  @subdomain = LiveTribe::Debut::Debutante::USE_ENVIRONMENT
  @use_local_hostname = LiveTribe::Debut::Debutante::USE_LOCAL_HOSTNAME
end

Instance Method Details

#goodbyeObject

Raises:

  • (ArgumentError)


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/debut/aws.rb', line 111

def goodbye
  name, subdomain = collect_name_and_subdomain
  fqdn = "#{name}.#{subdomain}"
  @dns.zones.each { |zone|
    if zone.domain == subdomain
      record = zone.records.find { |r| r.name == fqdn && r.type == 'CNAME' }
      if record
        record.destroy
      end

      puts "Unregistered #{fqdn}"

      return
    end
  }
  raise ArgumentError.new("Unable to find route53 zone: #{subdomain}")
end

#helloObject

Raises:

  • (ArgumentError)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/debut/aws.rb', line 83

def hello
  name, subdomain = collect_name_and_subdomain
  hostname = collect_hostname
  fqdn = "#{name}.#{subdomain}"
  for zone in @dns.zones
    if zone.domain == subdomain
      record = zone.records.find { |r| r.name == fqdn && r.type == 'CNAME' }
      if record
        puts "Destroying old record for #{fqdn}"

        record.destroy
      end

      zone.records.create(
          :value => hostname,
          :name => fqdn,
          :type => 'CNAME',
          :ttl => 60
      )

      puts "Registered hostname #{hostname} at #{fqdn}"

      return
    end
  end
  raise ArgumentError.new("Unable to find route53 zone: #{subdomain}")
end

#hostnameObject



47
48
49
# File 'lib/debut/aws.rb', line 47

def hostname
  @hostname
end

#hostname=(hostname) ⇒ Object



51
52
53
# File 'lib/debut/aws.rb', line 51

def hostname=(hostname)
  @hostname = hostname
end

#nameObject



55
56
57
# File 'lib/debut/aws.rb', line 55

def name
  @name
end

#name=(name) ⇒ Object



59
60
61
# File 'lib/debut/aws.rb', line 59

def name=(name)
  @name = name
end

#subdomainObject



63
64
65
# File 'lib/debut/aws.rb', line 63

def subdomain
  @subdomain
end

#subdomain=(subdomain) ⇒ Object



67
68
69
# File 'lib/debut/aws.rb', line 67

def subdomain=(subdomain)
  @subdomain = subdomain
end

#to_sObject



79
80
81
# File 'lib/debut/aws.rb', line 79

def to_s
  'aws'
end

#use_local_hostnameObject



71
72
73
# File 'lib/debut/aws.rb', line 71

def use_local_hostname
  @use_local_hostname
end

#use_local_hostname=(use_local_hostname) ⇒ Object



75
76
77
# File 'lib/debut/aws.rb', line 75

def use_local_hostname=(use_local_hostname)
  @use_local_hostname = use_local_hostname
end