Class: Aviator::Session
- Inherits:
-
Object
show all
- Defined in:
- lib/puppet/feature/aviator/core/session.rb
Defined Under Namespace
Classes: AuthenticationError, EnvironmentNotDefinedError, InitializationError, InvalidConfigFilePathError, NotAuthenticatedError, ValidatorNotDefinedError
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Session
Returns a new instance of Session.
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/puppet/feature/aviator/core/session.rb', line 46
def initialize(opts={})
if opts.has_key? :session_dump
initialize_with_dump(opts[:session_dump])
elsif opts.has_key? :config_file
initialize_with_config(opts[:config_file], opts[:environment])
elsif opts.has_key? :config
initialize_with_hash(opts[:config])
else
raise InitializationError.new
end
@log_file = opts[:log_file]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'lib/puppet/feature/aviator/core/session.rb', line 103
def method_missing(name, *args, &block)
service_name_parts = name.to_s.match(/^(\w+)_service$/)
if service_name_parts
get_service_obj(service_name_parts[1])
else
super name, *args, &block
end
end
|
Class Method Details
.load(session_dump, opts = {}) ⇒ Object
114
115
116
117
118
|
# File 'lib/puppet/feature/aviator/core/session.rb', line 114
def self.load(session_dump, opts={})
opts[:session_dump] = session_dump
new(opts)
end
|
Instance Method Details
#authenticate(&block) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/puppet/feature/aviator/core/session.rb', line 61
def authenticate(&block)
block ||= lambda do |params|
environment[:auth_credentials].each do |key, value|
params[key] = value
end
end
response = auth_service.request environment[:auth_service][:request].to_sym, &block
if [200, 201].include? response.status
@auth_response = Hashish.new({
:headers => response.,
:body => response.body
})
update_services_session_data
else
raise AuthenticationError.new(response.body)
end
self
end
|
#authenticated? ⇒ Boolean
83
84
85
|
# File 'lib/puppet/feature/aviator/core/session.rb', line 83
def authenticated?
!auth_response.nil?
end
|
88
89
90
91
92
93
|
# File 'lib/puppet/feature/aviator/core/session.rb', line 88
def dump
JSON.generate({
:environment => environment,
:auth_response => auth_response
})
end
|
#load(session_dump) ⇒ Object
96
97
98
99
100
|
# File 'lib/puppet/feature/aviator/core/session.rb', line 96
def load(session_dump)
initialize_with_dump(session_dump)
update_services_session_data
self
end
|
121
122
123
124
125
126
127
128
129
|
# File 'lib/puppet/feature/aviator/core/session.rb', line 121
def validate
raise NotAuthenticatedError.new unless authenticated?
raise ValidatorNotDefinedError.new unless environment[:auth_service][:validator]
auth_with_bootstrap = auth_response.merge({ :auth_service => environment[:auth_service] })
response = auth_service.request environment[:auth_service][:validator].to_sym, :session_data => auth_with_bootstrap
response.status == 200 || response.status == 203
end
|