Class: Maestrano::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/maestrano.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/maestrano.rb', line 137

def initialize
  @environment = 'production'

  # App config
  @app = OpenStruct.new({
    host: 'http://localhost:3000'
  })

  # API Config
  @api = OpenStruct.new({
    id: nil,
    key: nil,
    token: nil,
    version: nil,
    verify_ssl_certs: false,
    lang: nil, # set in post_initialize
    lang_version: nil # set in post_initialize
  })

  # SSO Config
  @sso = OpenStruct.new({
    enabled: true,
    slo_enabled: true,
    creation_mode: 'real',
    init_path: '/maestrano/auth/saml/init',
    consume_path: '/maestrano/auth/saml/consume',
    name_id_format: nil, # set in post_initialize
    idm: nil
  })

  # WebHooks Config
  @webhook = OpenStruct.new({
    account: OpenStruct.new({
      groups_path: '/maestrano/account/groups/:id',
      group_users_path: '/maestrano/account/groups/:group_id/users/:id',
    }),
    connec: OpenStruct.new({
      notifications_path: '/maestrano/connec/notifications',
      subscriptions: {}
    })
  })

  # Connec! Config
  @connec = OpenStruct.new({
    enabled: true
  })
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object

Handle legacy parameter assignment



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/maestrano.rb', line 224

def method_missing(meth, *args, &block)
  if meth.to_s =~ /^((?:sso|app|api|user)_.*)=$/
    new_meth = self.legacy_param_to_new($1) + '='
    props = new_meth.split('.')
    last_prop = props.pop
    obj = props.inject(self,:send)
    obj.send(last_prop, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



135
136
137
# File 'lib/maestrano.rb', line 135

def api
  @api
end

#appObject

Returns the value of attribute app.



135
136
137
# File 'lib/maestrano.rb', line 135

def app
  @app
end

#connecObject

Returns the value of attribute connec.



135
136
137
# File 'lib/maestrano.rb', line 135

def connec
  @connec
end

#environmentObject

Returns the value of attribute environment.



135
136
137
# File 'lib/maestrano.rb', line 135

def environment
  @environment
end

#ssoObject

Returns the value of attribute sso.



135
136
137
# File 'lib/maestrano.rb', line 135

def sso
  @sso
end

#webhookObject

Returns the value of attribute webhook.



135
136
137
# File 'lib/maestrano.rb', line 135

def webhook
  @webhook
end

Instance Method Details

#legacy_param_to_new(parameter) ⇒ Object

Transform legacy parameters into new parameter style Dummy mapping



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/maestrano.rb', line 202

def legacy_param_to_new(parameter)
  case parameter.to_s
  when 'user_creation_mode'
    return 'sso.creation_mode'
  when 'verify_ssl_certs'
    return 'api.verify_ssl_certs'
  when 'app_id'
    return 'api.id'
  when /^app_(.*)/i
    return "app.#{$1}"
  when /^api_(.*)/i
    return "api.#{$1}"
  when /^sso_app_(.*)/i
    return "sso.#{$1}"
  when /^sso_(.*)/i
    return "sso.#{$1}"
  else
    return parameter.to_s
  end
end

#param(parameter) ⇒ Object

Get configuration parameter value



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/maestrano.rb', line 237

def param(parameter)
  real_param = self.legacy_param_to_new(parameter)
  props = real_param.split('.')

  # Either respond to param directly or via properties chaining (e.g: webhook.account.groups_path)
  if self.respond_to?(real_param) || props.inject(self) { |result,elem| result && result.respond_to?(elem) ? result.send(elem) || elem : false }
    last_prop = props.pop
    obj = props.inject(self,:send)
    obj.send(last_prop)
  elsif EVT_CONFIG.has_key?(@environment.to_s) && EVT_CONFIG[@environment.to_s].has_key?(real_param.to_s)
    EVT_CONFIG[@environment.to_s][real_param.to_s]
  else
    raise ArgumentError, "No such configuration parameter: '#{parameter}'"
  end
end

#post_initializeObject

Force or default certain parameters Used after configure block



187
188
189
190
191
192
193
194
195
196
197
# File 'lib/maestrano.rb', line 187

def post_initialize
  self.api.token = "#{self.api.id}:#{self.api.key}"
  self.api.version = Maestrano::VERSION
  self.api.lang = 'ruby'
  self.api.lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})"
  self.sso.idm ||= self.app.host
  self.sso.name_id_format ||= Maestrano::Saml::Settings::NAMEID_PERSISTENT
  self.sso.slo_enabled &&= self.sso.enabled
  self.connec.base_path ||= '/api/v2'
  self.connec.timeout ||= 60
end