Class: GlobeSSL::SSLCertificate

Inherits:
Base
  • Object
show all
Defined in:
lib/globessl/ssl_certificate.rb

Instance Method Summary collapse

Methods inherited from Base

#inspect

Instance Method Details

#fetchObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/globessl/ssl_certificate.rb', line 22

def fetch
  @errors.clear
  
  unless @id
    @errors << "cerificate id is required"
    return false
  end
  
  response = Client.get('/certificates/get', { "id" => @id })
  
  case response.code
  when '200'  
    json = response.body
    hash = JSON.parse(json)
    
    @order_id           = hash["order_id"]
    @partner_order_id   = hash["partner_order_id"]
    @status             = hash["status"]
    @status_description = hash["status_description"]
    @dcv_method         = hash["dcv_method"]
    @dcv_email          = hash["dcv_email"]
    @domain             = hash["domain"]
    @domains            = hash["domains"]
    @total_domains      = hash["total_domains"]
    @period             = hash["period"]
    @valid_from         = hash["valid_from"]
    @valid_till         = hash["valid_till"]
    @csr_code           = hash["csr_code"]
    @crt_code           = hash["crt_code"]
    @ca_code            = hash["ca_code"]

    @product = Product.new(:id => hash["product_id"])
    @product.fetch
    
    return true
  when '400', '401', '403'
    set_errors(response)
    return false
  else
    return false
  end      
end

#reissueObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/globessl/ssl_certificate.rb', line 65

def reissue
  @errors.clear
  return false unless valid?
  
  params = { 
    "id"             => @id,
    "csr"            => @csr_code,
    "dcv_method"     => @dcv_method,
    "webserver_type" => @webserver_type
  }
  
  if @dcv_method == "email" && @product.validation == "dv"
    email_params = {
      "approver_email" => @approver_email
    }
    params.merge!(email_params)
  
    if @product.multi_domain
      multi_domain_params = {
        "dns_names"       => @domains,
        "approver_emails" => @approver_emails
      }
      params.merge!(multi_domain_params)
    end
  end
  
  request = Client.post('/certificates/reissue', params)
  
  case response.code
  when '200'  
    return true
  when '400', '401', '403'
    set_errors(response)
    return false
  else
    return false
  end      
end

#set_errors(response) ⇒ Object



104
105
106
107
108
# File 'lib/globessl/ssl_certificate.rb', line 104

def set_errors(response)
  json = response.body
  hash = JSON.parse(json)
  @errors << hash["message"]
end

#valid?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/globessl/ssl_certificate.rb', line 110

def valid?
  validate
end

#validateObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/globessl/ssl_certificate.rb', line 114

def validate
  unless @dcv_method
    @errors << "dcv_method is required"
  else
    unless DomainControlValidation::METHODS.include?(@dcv_method)
      @errors << "dcv_method must be one of 'email', 'http' or 'https'"
    end
  end
  
  if @product.multi_domain
    unless @dns_names.size > (@product.min_domains - 1)
      @errors << "dns_names are required"
    end
  end
  
  if @dcv_method == "email"
    unless @approver_email
      @errors << "approver_email is required"
    end
    
    if @product.multi_domain
      unless @approver_emails.size == @dns_names.size
        @errors << "approver_emails are required"
      end
    end
  end
  
  unless @product.validation == "dv"  # if not domain validation
    unless @admin_org
      @errors << "admin_org is required"
    end
    
    unless @admin_address
      @errors << "admin_address is required"
    end
    
    unless @admin_city
      @errors << "admin_city is required"
    end

    unless @admin_country
      @errors << "admin_country is required"
    else
      unless COUNTRY_CODES.has_key?(@admin_country)
        @errors << "admin_country must be one in COUNTRY_CODES"
      end
    end

    unless @org_name
      @errors << "org_name is required"
    end
    
    unless @org_division
      @errors << "org_division is required"
    end

    unless @org_address
      @errors << "org_address is required"
    end

    unless @org_city
      @errors << "org_city is required"
    end

    unless @org_state
      @errors << "org_state is required"
    end
    
    unless @org_country
      @errors << "org_country is required"
    else
      unless COUNTRY_CODES.has_key?(@org_country)
        @errors << "org_country must be one in COUNTRY_CODES"
      end
    end
    
    unless @org_postalcode
      @errors << "org_postalcode is required"
    end
    
    unless @org_phone
      @errors << "org_phone is required"
    end
  end
  
  unless @admin_firstname
    @errors << "admin_firstname is required"
  end

  unless @admin_lastname
    @errors << "admin_lastname is required"
  end

  unless @admin_email
    @errors << "admin_email is required"
  end
  
  unless @admin_jobtitle
    @errors << "admin_jobtitle is required"
  end

  unless @admin_phone
    @errors << "admin_phone is required"
  end

  unless @admin_phone
    @errors << "admin_phone is required"
  end
  
  unless @csr
    @errors << "certificate signing request (csr) is required"
  end
  
  unless @period
    @errors << "period is required"
  else
    unless EXPIRY_PERIODS.include?(@period)
      @errors << "period must be 1, 2 or 3 years or 0 if product is free"
    end
  end
  
  unless @webserver_type
    @errors << "webserver_type is required"
  end
  
  unless @product
    @errors << "product is required"
  end

  if @errors.any?
    return false
  else
    return true
  end
end