Class: SwFac::Config
- Inherits:
-
Object
- Object
- SwFac::Config
- Defined in:
- lib/sw_fac/config.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cadena ⇒ Object
readonly
Returns the value of attribute cadena.
-
#dev_token ⇒ Object
Returns the value of attribute dev_token.
-
#doc_cer_path ⇒ Object
Returns the value of attribute doc_cer_path.
-
#doc_key_path ⇒ Object
Returns the value of attribute doc_key_path.
-
#key_pass ⇒ Object
readonly
Returns the value of attribute key_pass.
-
#pem ⇒ Object
readonly
Returns the value of attribute pem.
-
#pem_cadena ⇒ Object
readonly
Returns the value of attribute pem_cadena.
-
#production_token ⇒ Object
Returns the value of attribute production_token.
-
#serial ⇒ Object
readonly
Returns the value of attribute serial.
Instance Method Summary collapse
- #cer_cadena ⇒ Object
-
#initialize(production_token, development_token, rfc, razon, regimen, doc_key_path, key_pass, doc_cer_path, production = false) ⇒ Config
constructor
A new instance of Config.
- #key_to_pem ⇒ Object
- #serial_number ⇒ Object
Constructor Details
#initialize(production_token, development_token, rfc, razon, regimen, doc_key_path, key_pass, doc_cer_path, production = false) ⇒ Config
Returns a new instance of Config.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sw_fac/config.rb', line 6 def initialize(production_token, development_token, rfc, razon, regimen, doc_key_path, key_pass, doc_cer_path, production=false) puts "---- SwFacturacion:config:initialize" @production_token = production_token.to_s @dev_token = development_token.to_s @rfc = rfc.to_s @razon = razon.to_s @regimen_fiscal = regimen @doc_key_path = doc_key_path.to_s @key_pass = key_pass.to_s @doc_cer_path = doc_cer_path @production = production key_to_pem serial_number cer_cadena end |
Instance Attribute Details
#cadena ⇒ Object (readonly)
Returns the value of attribute cadena.
4 5 6 |
# File 'lib/sw_fac/config.rb', line 4 def cadena @cadena end |
#dev_token ⇒ Object
Returns the value of attribute dev_token.
3 4 5 |
# File 'lib/sw_fac/config.rb', line 3 def dev_token @dev_token end |
#doc_cer_path ⇒ Object
Returns the value of attribute doc_cer_path.
3 4 5 |
# File 'lib/sw_fac/config.rb', line 3 def doc_cer_path @doc_cer_path end |
#doc_key_path ⇒ Object
Returns the value of attribute doc_key_path.
3 4 5 |
# File 'lib/sw_fac/config.rb', line 3 def doc_key_path @doc_key_path end |
#key_pass ⇒ Object (readonly)
Returns the value of attribute key_pass.
4 5 6 |
# File 'lib/sw_fac/config.rb', line 4 def key_pass @key_pass end |
#pem ⇒ Object (readonly)
Returns the value of attribute pem.
4 5 6 |
# File 'lib/sw_fac/config.rb', line 4 def pem @pem end |
#pem_cadena ⇒ Object (readonly)
Returns the value of attribute pem_cadena.
4 5 6 |
# File 'lib/sw_fac/config.rb', line 4 def pem_cadena @pem_cadena end |
#production_token ⇒ Object
Returns the value of attribute production_token.
3 4 5 |
# File 'lib/sw_fac/config.rb', line 3 def production_token @production_token end |
#serial ⇒ Object (readonly)
Returns the value of attribute serial.
4 5 6 |
# File 'lib/sw_fac/config.rb', line 4 def serial @serial end |
Instance Method Details
#cer_cadena ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sw_fac/config.rb', line 57 def cer_cadena puts "---- SwFacturacion:config:cer_cadena" file = File.read(@doc_cer_path) text_certificate = OpenSSL::X509::Certificate.new(file) cert_string = text_certificate.to_s cert_string.slice!("-----BEGIN CERTIFICATE-----") cert_string.slice!("-----END CERTIFICATE-----") cert_string.delete!("\n") @cadena = cert_string end |
#key_to_pem ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sw_fac/config.rb', line 25 def key_to_pem puts "---- SwFacturacion:config:key_to_pem" puts "-- 1" @pem = %x[openssl pkcs8 -inform DER -in #{@doc_key_path} -passin pass:#{@key_pass}] # @pem = %x[openssl rsa -inform DER -in #{@doc_key_path} -passin pass:#{@key_pass}] puts "-- 2" @pem_cadena = @pem.clone @pem_cadena.slice!("-----BEGIN PRIVATE KEY-----") @pem_cadena.slice!("-----END PRIVATE KEY-----") @pem_cadena.delete!("\n") end |
#serial_number ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sw_fac/config.rb', line 38 def serial_number puts "---- SwFacturacion:config:serial_number" response = %x[openssl x509 -inform DER -in #{@doc_cer_path} -noout -serial] d_begin = response.index(/\d/) number = (response[d_begin..-1]).chomp final_serial = "" number.each_char.with_index do |s, index| if (index + 1).even? final_serial << s end end @serial = final_serial end |