Class: Capricorn::Client::AuthToken

Inherits:
Object
  • Object
show all
Defined in:
lib/capricorn/client/auth_token.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options={})
  @target_uri          = options[:target_uri]
  @verify_mode         = options[:verify_mode]
  @ca_certificate_data = options[:ca_certificate_data]
  @private_key_data    = options[:private_key_data]
  @certificate_data    = options[:certificate_data]
end

Instance Attribute Details

#ca_certificate_dataObject (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_dataObject (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_dataObject (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_uriObject (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_modeObject (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_certificateObject

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

#certificateObject

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

#connectObject

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.options_for_drb
  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_drbObject

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
  @options_for_drb ||= {
    :SSLVerifyMode => self.verify_mode,
    :SSLCACertificate => self.ca_certificate,
    :SSLPrivateKey => self.private_key,
    :SSLCertificate => self.certificate
  }
end

#private_keyObject

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