Module: SoarSc

Defined in:
lib/soar_sc_core.rb,
lib/web/renderer.rb,
lib/providers/auditing.rb,
lib/providers/sessions.rb,
lib/web/soar_sc_router.rb,
lib/providers/service_registry.rb

Defined Under Namespace

Modules: Providers, Web Classes: SoarScRouter

Class Method Summary collapse

Class Method Details

.adapt_configuration_service_errors(errors) ⇒ Object



123
124
125
126
127
# File 'lib/soar_sc_core.rb', line 123

def self.adapt_configuration_service_errors(errors)
  errors << 'missing configuration service URI' if errors.include?('missing key address')
  errors << 'incorrect configuration service token' if errors.include?('permission denied')
  errors << 'failure retrieving configuration from configuration service' if not errors.empty?
end

.auditingObject



220
221
222
# File 'lib/soar_sc_core.rb', line 220

def self.auditing
  @auditing
end

.auditing=(auditing) ⇒ Object



224
225
226
# File 'lib/soar_sc_core.rb', line 224

def self.auditing=(auditing)
  @auditing = auditing
end

.bootstrap_aspects(config, authenticated_meta, lexicon) ⇒ Object



172
173
174
175
176
177
# File 'lib/soar_sc_core.rb', line 172

def self.bootstrap_aspects(config, authenticated_meta, lexicon)
  SoarAspects::Aspects::configuration = config
  SoarAspects::Aspects::signed_routes = authenticated_meta.signed_routes
  SoarAspects::Aspects::auditing = SoarSc::auditing
  SoarAspects::Aspects::lexicon = lexicon
end

.bootstrap_authentication(stack) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/soar_sc_core.rb', line 152

def self.bootstrap_authentication(stack)
  if 'development' == ENV['RACK_ENV']
    SoarSc::auditing.warn("Authentication ignored in development mode.")
  elsif SoarSc::configuration['auth_token']
    SoarSc::auditing.info("Using auth tokens for authentication with <#{SoarSc::configuration['auth_token']['provider']}> provider.",SoarSc::startup_flow_id)
    stack.use SoarAuthenticationToken::RackMiddleware, SoarSc::configuration['auth_token'], SoarSc::environment['IDENTIFIER'], SoarSc::auditing
  elsif SoarSc::environment['CAS_SERVER']
    SoarSc::auditing.info("Using CAS_SERVER=#{SoarSc::environment['CAS_SERVER']} for authentication",SoarSc::startup_flow_id)
    options = SoarAuthenticationCas::configure(SoarSc::environment)
    stack.use KhSignon::RackMiddleware, options if options
  elsif SoarSc::environment['BASIC_AUTH_USER']
    SoarSc::auditing.warn("BASIC_AUTH_USER specified, using basic auth for authentication. Basic auth is not recommended for production",SoarSc::startup_flow_id)
    stack.use Rack::Auth::Basic, "Restricted Area" do |username, password|
      [username, password] == [SoarSc::environment['BASIC_AUTH_USER'], SoarSc::environment['BASIC_AUTH_PASSWORD']]
    end
  else
    SoarSc::auditing.warn("Neither Authentication Tokens, CAS_SERVER or BASIC_AUTH_USER specified. Having no authentication is not recommended for production",SoarSc::startup_flow_id)
  end
end

.bootstrap_sessions(stack) ⇒ Object



145
146
147
148
149
150
# File 'lib/soar_sc_core.rb', line 145

def self.bootstrap_sessions(stack)
  if (SoarSc::environment['SESSION_KEY'] or SoarSc::environment['SESSION_SECRET'])
    session_provider = SoarSc::Providers::Sessions.new
    session_provider.bootstrap_sessions(stack)
  end
end

.configurationObject



208
209
210
# File 'lib/soar_sc_core.rb', line 208

def self.configuration
  @configuration
end

.configuration=(configuration) ⇒ Object



240
241
242
# File 'lib/soar_sc_core.rb', line 240

def self.configuration=(configuration)
  @configuration = configuration
end

.dependenciesObject



200
201
202
# File 'lib/soar_sc_core.rb', line 200

def self.dependencies
  @dependencies
end

.environmentObject



212
213
214
# File 'lib/soar_sc_core.rb', line 212

def self.environment
  @environment
end

.environment=(environment) ⇒ Object



216
217
218
# File 'lib/soar_sc_core.rb', line 216

def self.environment=(environment)
  @environment = environment
end

.inject_dependencies(configuration) ⇒ Object



134
135
136
137
138
139
140
141
142
143
# File 'lib/soar_sc_core.rb', line 134

def self.inject_dependencies(configuration)
  if configuration and configuration['dependency_injector']
    injector = Object::const_get(configuration['dependency_injector']).new
    @dependencies = injector.inject_dependencies(configuration)
  else
    @dependencies = {}
  end

  @dependencies
end

.load_configurationObject

Raises:

  • (ArgumentError)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/soar_sc_core.rb', line 103

def self.load_configuration
  configuration = SoarConfiguration::Configuration.new
  if SoarSc::environment['CFGSRV_IDENTIFIER']
    self.validate_configuration_service_token
    config, errors = configuration.load_from_configuration_service(SoarSc::environment)
    self.adapt_configuration_service_errors(errors)
  else
    config_file = SoarSc::environment['CONFIG_FILE'] ? SoarSc::environment['CONFIG_FILE'] : "config.yml"
    config, errors = configuration.load_from_yaml("config/#{config_file}")
    errors << 'Failure retrieving configuration from file' if not errors.empty?
    errors << 'Invalid configuration file' if not config.is_a?(::Hash)
  end
  errors << 'missing configuration' if config.nil?
  errors = configuration.validate(config) if (errors) and (errors.empty?)
  raise ArgumentError.new(errors) if (errors) and (not (errors.empty?))

  SoarSc::configuration = config
  config
end

.load_environment_and_configurationObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/soar_sc_core.rb', line 84

def self.load_environment_and_configuration
  environment_file = ENV['ENVIRONMENT_FILE'] ? "config/#{ENV['ENVIRONMENT_FILE']}" : 'config/environment.yml'
  if File.exists?(environment_file)
    environment_loader = SoarEnvironment::Environment.new(environment_file)
  else
    environment_loader = SoarEnvironment::Environment.new
  end
  SoarSc::environment = environment_loader.load_environment
  config = SoarSc::load_configuration
  SoarSc::environment = environment_loader.supplement_with_configuration(config)
  validator = SoarEnvironment::EnvironmentValidator.new
  errors = validator.validate(SoarSc::environment)
  raise ArgumentError.new(errors) if (errors) and (not (errors.empty?))
  config
rescue Exception
  $stderr.puts 'Failure retrieving environment from file'
  raise
end

.self_testObject



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

def self.self_test
  Thread.new do |thread|
    sleep 1
    url = URI.parse('http://localhost:9393/status')
    res = Net::HTTP.get(url)
    puts "SELF-TEST: #{res}"

    if RUBY_PLATFORM =~ /java/
      java.lang.System.exit(1)
    else
      exit 0
    end
  end
end

.service_registryObject



204
205
206
# File 'lib/soar_sc_core.rb', line 204

def self.service_registry
  @service_registry
end

.service_registry=(service_registry) ⇒ Object



236
237
238
# File 'lib/soar_sc_core.rb', line 236

def self.service_registry=(service_registry)
  @service_registry = service_registry
end

.startup_flow_idObject



228
229
230
# File 'lib/soar_sc_core.rb', line 228

def self.startup_flow_id
  @startup_flow_id
end

.startup_flow_id=(startup_flow_id) ⇒ Object



232
233
234
# File 'lib/soar_sc_core.rb', line 232

def self.startup_flow_id=(startup_flow_id)
  @startup_flow_id = startup_flow_id
end

.static_optionsObject



179
180
181
182
183
# File 'lib/soar_sc_core.rb', line 179

def self.static_options
  static_options = SoarSc::configuration['static_options'] || DEFAULT_STATIC_OPTIONS

  { :urls => static_options['urls'], :root => static_options['root'] }
end

.validate_configuration_service_tokenObject

Raises:

  • (ArgumentError)


129
130
131
132
# File 'lib/soar_sc_core.rb', line 129

def self.validate_configuration_service_token
  raise ArgumentError.new('missing configuration service token') if SoarSc::environment['CFGSRV_TOKEN'].nil?
  raise ArgumentError.new('invalid configuration service token') if SoarSc::environment['CFGSRV_TOKEN'].length < 12
end