certman 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '087eb221a45056f14751bf7896d99645c3dc31be'
4
- data.tar.gz: dd1693769ace09e80d6ad0c95363fde58d27e4e8
3
+ metadata.gz: 9ef3fe64e1dce859da78da61b05d16eadea7831f
4
+ data.tar.gz: 49dcc2814216eaac91207f92c504da4a1b7032ec
5
5
  SHA512:
6
- metadata.gz: 6046fc4421e11441b9098c6039d3bbeb89edf4192d6fbeb3429333c9d66aa863c01921f7b71cbc03578064a0e0ccacc2b8327777fbb2da74debf902643754f64
7
- data.tar.gz: 9416242570398ad5f2273b620542b50c8aa0ab90f450d8d257906c6f178203944ec796af2b4c6dc145cf182df8bf5ce792e8e8bb63d2a99672821a02c4c9e8ec
6
+ metadata.gz: da29279cf87464bf77418c21a3db658c21c95eba43346a6ee34bc117b649ac637c55ac979ef18a79cbc3f600c2a71bc2062d1a1fe6125607c396e43d8b93c869
7
+ data.tar.gz: 0e01313f8299bb3029c3671f4cf20ca669c94994aea35ee030bd9a982331da72f457b2da5a43719f3f5c1a11970adad9639bbd3cb0a99bf3014f91619ec6b849
@@ -8,6 +8,7 @@ module Certman
8
8
 
9
9
  def initialize(domain)
10
10
  @do_rollback = false
11
+ @cname_exists = false
11
12
  @domain = domain
12
13
  @cert_arn = nil
13
14
  @savepoint = []
@@ -76,21 +77,28 @@ module Certman
76
77
 
77
78
  def check_resource
78
79
  s = spinner('[ACM] Check Certificate')
79
- check_certificate
80
+ raise 'Certificate already exist' if check_certificate
80
81
  s.success
81
82
 
82
83
  s = spinner('[Route53] Check Hosted Zone')
83
- check_hosted_zone
84
+ raise "Hosted Zone #{root_domain} does not exist" unless check_hosted_zone
84
85
  s.success
85
86
 
86
87
  s = spinner('[Route53] Check TXT Record')
87
- check_txt_rset
88
+ raise "_amazonses.#{email_domain} TXT already exist" if check_txt_rset
88
89
  s.success
89
90
 
90
91
  s = spinner('[Route53] Check MX Record')
91
- check_mx_rset
92
+ raise "#{email_domain} MX already exist" if check_mx_rset
92
93
  s.success
93
94
 
95
+ if check_cname_rset
96
+ pastel = Pastel.new
97
+ puts pastel.cyan("#{email_domain} CNAME already exist. Use #{root_domain}")
98
+ @cname_exists = true
99
+ check_resource
100
+ end
101
+
94
102
  true
95
103
  end
96
104
 
@@ -185,10 +193,20 @@ module Certman
185
193
  end
186
194
  end
187
195
 
196
+ def root_domain
197
+ PublicSuffix.domain(@domain)
198
+ end
199
+
188
200
  def email_domain
201
+ return root_domain if @cname_exists
189
202
  @domain.sub(/\A(www|\*)\./, '')
190
203
  end
191
204
 
205
+ def validation_domain
206
+ return root_domain if @cname_exists
207
+ @domain
208
+ end
209
+
192
210
  def rule_name
193
211
  @rule_name ||= if "RuleCertman_#{email_domain}".length < 64
194
212
  "RuleCertman_#{email_domain}"
@@ -8,7 +8,7 @@ module Certman
8
8
  domain_validation_options: [
9
9
  {
10
10
  domain_name: @domain,
11
- validation_domain: @domain
11
+ validation_domain: validation_domain
12
12
  }
13
13
  ]
14
14
  )
@@ -27,7 +27,7 @@ module Certman
27
27
  current_cert = acm.list_certificates.certificate_summary_list.find do |cert|
28
28
  cert.domain_name == @domain
29
29
  end
30
- raise 'Certificate already exist' if current_cert
30
+ current_cert
31
31
  end
32
32
 
33
33
  def acm
@@ -3,7 +3,6 @@ module Certman
3
3
  # rubocop:disable Metrics/ModuleLength
4
4
  module Route53
5
5
  def create_txt_rset
6
- root_domain = PublicSuffix.domain(@domain)
7
6
  @hosted_zone = route53.list_hosted_zones.hosted_zones.find do |zone|
8
7
  PublicSuffix.domain(zone.name) == root_domain
9
8
  end
@@ -103,7 +102,6 @@ module Certman
103
102
  end
104
103
 
105
104
  def check_hosted_zone
106
- root_domain = PublicSuffix.domain(@domain)
107
105
  @hosted_zone_id = nil
108
106
  hosted_zone = route53.list_hosted_zones.hosted_zones.find do |zone|
109
107
  if PublicSuffix.domain(zone.name) == root_domain
@@ -111,7 +109,7 @@ module Certman
111
109
  next true
112
110
  end
113
111
  end
114
- raise "Hosted Zone #{root_domain} does not exist" unless hosted_zone
112
+ hosted_zone
115
113
  end
116
114
 
117
115
  def check_txt_rset
@@ -120,7 +118,7 @@ module Certman
120
118
  record_name: "_amazonses.#{email_domain}.",
121
119
  record_type: 'TXT'
122
120
  )
123
- raise "_amazonses.#{email_domain} TXT already exist" unless res.record_data.empty?
121
+ !res.record_data.empty?
124
122
  end
125
123
 
126
124
  def check_mx_rset
@@ -129,7 +127,16 @@ module Certman
129
127
  record_name: "#{email_domain}.",
130
128
  record_type: 'MX'
131
129
  )
132
- raise "#{email_domain} MX already exist" unless res.record_data.empty?
130
+ !res.record_data.empty?
131
+ end
132
+
133
+ def check_cname_rset
134
+ res = route53.test_dns_answer(
135
+ hosted_zone_id: @hosted_zone_id,
136
+ record_name: "#{email_domain}.",
137
+ record_type: 'CNAME'
138
+ )
139
+ !res.record_data.empty?
133
140
  end
134
141
 
135
142
  def route53
@@ -1,3 +1,3 @@
1
1
  module Certman
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: certman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - k1LoW