Class: GlobeSSL::CertificateSigningRequest
- Defined in:
- lib/globessl/certificate_signing_request.rb
Instance Method Summary collapse
- #country_name=(value) ⇒ Object
- #decode ⇒ Object
- #fetch ⇒ Object
- #set_errors(response) ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
Methods inherited from Base
Instance Method Details
#country_name=(value) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/globessl/certificate_signing_request.rb', line 19 def country_name=(value) if value @country_name = value.upcase else @country_name = value # nil end end |
#decode ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/globessl/certificate_signing_request.rb', line 63 def decode @errors.clear response = Client.post('/tools/decodecsr', { "csr" => @csr_code }) case response.code when '200' @csr_code_decoded = response.body return true when '400', '401', '403' set_errors(response) return false else return false end end |
#fetch ⇒ Object
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 |
# File 'lib/globessl/certificate_signing_request.rb', line 27 def fetch @errors.clear return false unless valid? params = { "countryName" => @country_name, "stateOrProvinceName" => @state_or_province_name, "localityName" => @locality_name, "organizationName" => @organization_name, "organizationalUnitName" => @organizational_unit_name, "commonName" => @common_name, "emailAddress" => @email_address } response = Client.post('/tools/autocsr', params) case response.code when '200' json = response.body hash = JSON.parse(json) @private_key = hash["key"] #.delete!("\n") # delete newlines @csr_code = hash["csr"] #.delete!("\n") # delete newlines @fingerprint_sha1 = hash["sha1"] @fingerprint_md5 = hash["md5"] return true when '400', '401', '403' set_errors(response) return false else return false end end |
#set_errors(response) ⇒ Object
79 80 81 82 83 |
# File 'lib/globessl/certificate_signing_request.rb', line 79 def set_errors(response) json = response.body hash = JSON.parse(json) @errors << hash["message"] end |
#valid? ⇒ Boolean
85 86 87 |
# File 'lib/globessl/certificate_signing_request.rb', line 85 def valid? validate end |
#validate ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/globessl/certificate_signing_request.rb', line 89 def validate unless @country_name @errors << "country_name is required" end unless COUNTRY_CODES.has_key?(@country_name) @errors << "country_name must be one in COUNTRY_CODES" end unless @state_or_province_name @errors << "state_or_province_name is required" end unless @locality_name @errors << "locality_name is required" end unless @organization_name @errors << "organization_name is required" end unless @organizational_unit_name @errors << "organizational_unit_name is required" end unless @common_name @errors << "common_name is required" end unless @email_address @errors << "email_address is required" end if @errors.any? return false else return true end end |