class Maestrano::Configuration
Constants
- EVT_CONFIG
Attributes
api[RW]
app[RW]
environment[RW]
sso[RW]
webhook[RW]
Public Class Methods
new()
click to toggle source
# File lib/maestrano.rb, line 149 def initialize @environment = 'test' # 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', 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', }) }) end
Public Instance Methods
legacy_param_to_new(parameter)
click to toggle source
Transform legacy parameters into new parameter style Dummy mapping
# File lib/maestrano.rb, line 201 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
method_missing(meth, *args, &block)
click to toggle source
Handle legacy parameter assignment
Calls superclass method
# File lib/maestrano.rb, line 223 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
param(parameter)
click to toggle source
Get configuration parameter value
# File lib/maestrano.rb, line 236 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[@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_initialize()
click to toggle source
Force or default certain parameters Used after configure block
# File lib/maestrano.rb, line 189 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.slo_enabled &&= self.sso.enabled end