Class: Capricorn::Client::AuthToken
- Inherits:
-
Object
- Object
- Capricorn::Client::AuthToken
- Defined in:
- lib/capricorn/client/auth_token.rb
Instance Attribute Summary collapse
-
#ca_certificate_data ⇒ Object
readonly
the optional CA certificate used by the capricorn server.
-
#certificate_data ⇒ Object
readonly
the certificate used by the client.
-
#private_key_data ⇒ Object
readonly
the private key used by the client.
-
#target_uri ⇒ Object
readonly
the uri at which the capricorn server can be accessed.
-
#verify_mode ⇒ Object
readonly
the SSL verification mode used by the capricorn server.
Class Method Summary collapse
-
.load(io) ⇒ Object
load a token from the passed IO.
-
.load_file(path) ⇒ Object
load a token from a file referenced by the given
path
.
Instance Method Summary collapse
-
#ca_certificate ⇒ Object
get the parsed and initialized OpenSSL::X509::Certificate.
-
#certificate ⇒ Object
get the parsed and initialized OpenSSL::X509::Certificate.
-
#connect ⇒ Object
connect to the server and return the server handle.
-
#dump(io = nil) ⇒ Object
dump this token to the given IO or return the content as a String.
-
#dump_file(path) ⇒ Object
dump this token to a file at the given
path
. -
#initialize(options = {}) ⇒ AuthToken
constructor
create a new token from the given options.
-
#options_for_drb ⇒ Object
return options for use with DRb.
-
#private_key ⇒ Object
get the parsed and initialized OpenSSL::PKey::RSA.
Constructor Details
#initialize(options = {}) ⇒ AuthToken
create a new token from the given options
:target_uri
, :verify_mode
, :ca_certificate_data
, :private_key_data
, :certificate_data
31 32 33 34 35 36 37 |
# File 'lib/capricorn/client/auth_token.rb', line 31 def initialize(={}) @target_uri = [:target_uri] @verify_mode = [:verify_mode] @ca_certificate_data = [:ca_certificate_data] @private_key_data = [:private_key_data] @certificate_data = [:certificate_data] end |
Instance Attribute Details
#ca_certificate_data ⇒ Object (readonly)
the optional CA certificate used by the capricorn server
22 23 24 |
# File 'lib/capricorn/client/auth_token.rb', line 22 def ca_certificate_data @ca_certificate_data end |
#certificate_data ⇒ Object (readonly)
the certificate used by the client
26 27 28 |
# File 'lib/capricorn/client/auth_token.rb', line 26 def certificate_data @certificate_data end |
#private_key_data ⇒ Object (readonly)
the private key used by the client
24 25 26 |
# File 'lib/capricorn/client/auth_token.rb', line 24 def private_key_data @private_key_data end |
#target_uri ⇒ Object (readonly)
the uri at which the capricorn server can be accessed.
18 19 20 |
# File 'lib/capricorn/client/auth_token.rb', line 18 def target_uri @target_uri end |
#verify_mode ⇒ Object (readonly)
the SSL verification mode used by the capricorn server
20 21 22 |
# File 'lib/capricorn/client/auth_token.rb', line 20 def verify_mode @verify_mode end |
Class Method Details
.load(io) ⇒ Object
load a token from the passed IO.
8 9 10 |
# File 'lib/capricorn/client/auth_token.rb', line 8 def self.load(io) self.new YAML.load(io) end |
.load_file(path) ⇒ Object
load a token from a file referenced by the given path
.
13 14 15 |
# File 'lib/capricorn/client/auth_token.rb', line 13 def self.load_file(path) self.new YAML.load_file(path) end |
Instance Method Details
#ca_certificate ⇒ Object
get the parsed and initialized OpenSSL::X509::Certificate
40 41 42 |
# File 'lib/capricorn/client/auth_token.rb', line 40 def ca_certificate @ca_certificate ||= OpenSSL::X509::Certificate.new(@ca_certificate_data) end |
#certificate ⇒ Object
get the parsed and initialized OpenSSL::X509::Certificate
45 46 47 |
# File 'lib/capricorn/client/auth_token.rb', line 45 def certificate @certificate ||= OpenSSL::X509::Certificate.new(@certificate_data) end |
#connect ⇒ Object
connect to the server and return the server handle.
55 56 57 58 59 60 61 62 63 |
# File 'lib/capricorn/client/auth_token.rb', line 55 def connect use_ssl, uri = Capricorn::Client.parse_uri(self.target_uri) if use_ssl DRb.start_service nil, nil, self. else DRb.start_service end DRbObject.new nil, uri end |
#dump(io = nil) ⇒ Object
dump this token to the given IO or return the content as a String
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/capricorn/client/auth_token.rb', line 76 def dump(io=nil) data = { :target_uri => self.target_uri, :verify_mode => self.verify_mode, :ca_certificate_data => self.ca_certificate_data, :private_key_data => self.private_key_data, :certificate_data => self.certificate_data } if io io.write YAML.dump(data) else YAML.dump(data) end end |
#dump_file(path) ⇒ Object
dump this token to a file at the given path
.
92 93 94 |
# File 'lib/capricorn/client/auth_token.rb', line 92 def dump_file(path) File.open(path, 'w+') { |f| dump(f) } end |
#options_for_drb ⇒ Object
return options for use with DRb
66 67 68 69 70 71 72 73 |
# File 'lib/capricorn/client/auth_token.rb', line 66 def @options_for_drb ||= { :SSLVerifyMode => self.verify_mode, :SSLCACertificate => self.ca_certificate, :SSLPrivateKey => self.private_key, :SSLCertificate => self.certificate } end |
#private_key ⇒ Object
get the parsed and initialized OpenSSL::PKey::RSA
50 51 52 |
# File 'lib/capricorn/client/auth_token.rb', line 50 def private_key @private_key ||= OpenSSL::PKey::RSA.new(@private_key_data) end |