soar_sc_mvc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca5bb8883f081b830af06796d35b361ec50583e0
4
+ data.tar.gz: e04d6643b5f8f5bfa801880f0f682373ceb01729
5
+ SHA512:
6
+ metadata.gz: 2b71e8343a04783d009047a7f42d78a3f07583561f9fbf17784f7bce799fe07b0c8c5e582e455d735f1af4ad13f6be0554e1c52dce7fbb4f5bf4381f9af77481
7
+ data.tar.gz: bd0caee06c4bc214e0ab0570411119fce5b6d9027e793a266f6d4628bb8716ebf2e9863620716a48b39a415fda06731e37204ae324157c49954e620d75d9c23a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soar_sc_mvc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ernst Van Graan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # SoarScMvc
2
+
3
+ This library includes a configured controller, configured model and model factory supporting the SOAR reference implementation service component MVC. ConfiguredController provides access to soar_sc dependencies as and requesty body, as well as a configured and ready-to-use SMAAK client.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'soar_sc_mvc'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install soar_sc_mvc
20
+
21
+ ## Usage
22
+
23
+ ### SoarSc::Web::Models::ModelFactory
24
+
25
+ Given a configuration with a provider adhering to SoarSc::Web::Models::ConfiguredModel, configured as follows:
26
+
27
+ ```ruby
28
+ { 'providers' =>
29
+ { 'my_provider' =>
30
+ { 'adaptor' => 'MyAdaptorClass',
31
+ 'some' => 'value' }
32
+ }
33
+ }
34
+ ```
35
+
36
+ an instance of the model (MyAdaptorClass), readily configured with the configuration hierarchy
37
+
38
+ ```ruby
39
+ { 'some' => 'value' }
40
+ ```
41
+
42
+ can be obtained so:
43
+
44
+ ```ruby
45
+ model_factory = SoarSc::Web::Models::ModelFactory.new(configuration)
46
+ model = model_factory.create('my_provider')
47
+ ```
48
+
49
+ ### ConfiguredModel
50
+
51
+ ```ruby
52
+ class MyModel < SoarSc::Web::Models::ConfiguredModel
53
+ end
54
+
55
+ model = MyModel.new(configuration)
56
+ puts model.configuration
57
+ ```
58
+
59
+ ### ConfiguredController
60
+
61
+ class MyController < SoarSc::Web::Controllers::ConfiguredController
62
+ def serve(request)
63
+ puts "Dependencies are: #{dependencies}"
64
+ puts "body is #{body(requests)}"
65
+ puts "I can use smaak client #{smaak_client}"
66
+ [200, "100"]
67
+ end
68
+ end
69
+
70
+ controller = MyController.new(configuration)
71
+
72
+ ## Contributing
73
+
74
+ Please send feedback and comments to the author at:
75
+
76
+ Ernst van Graan <ernst.van.graan@hetzner.co.za>
77
+
78
+ This gem is sponsored by Hetzner (Pty) Ltd - http://hetzner.co.za
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
83
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "soar_sc_mvc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,65 @@
1
+ require 'smaak'
2
+ require 'smaak/client'
3
+ require 'net/http'
4
+ require 'uri'
5
+
6
+ module SoarSc
7
+ module Web
8
+ module Controllers
9
+ class ConfiguredController
10
+ attr_accessor :configuration
11
+ attr_accessor :policies
12
+ attr_accessor :dependencies
13
+ attr_accessor :smaak_client
14
+
15
+ def initialize(configuration, policies = nil)
16
+ @configuration = configuration
17
+ @policies = policies
18
+ @dependencies = SoarSc::dependencies
19
+ configure_smaak_client if smaak_enabled?
20
+ end
21
+
22
+ def body(request)
23
+ return nil if request.body.nil?
24
+ return request.body.gets if request.body.is_a? Rack::Lint::InputWrapper
25
+ return request.body.string if request.body.is_a? StringIO
26
+ request.body
27
+ end
28
+
29
+ def serve(request)
30
+ [ 501, "Not implemented" ]
31
+ end
32
+
33
+ def smaak_client
34
+ SoarSc::auditing.warn("SMAAK not enabled, and so I don't have a SMAAK client",SoarSc::startup_flow_id) if not smaak_enabled?
35
+ @smaak_client
36
+ end
37
+
38
+ protected
39
+
40
+ def smaak_enabled?
41
+ (@configuration['private_key'] and @configuration['associations']) or
42
+ (@configuration['smaak'] == 'dynamic')
43
+ end
44
+
45
+ def configure_smaak_client
46
+ @smaak_client = ::Smaak::Client.new
47
+ secure_service = SoarSmaak::SecureService.get_instance(@configuration)
48
+ if secure_service.dynamic
49
+ secure_service.trust_store.associations.each do |identifier, association|
50
+ @smaak_client.add_association(identifier, association['public_key'], association['psk'], association['encrypt'])
51
+ end
52
+ @smaak_client.set_identifier(secure_service.dynamic)
53
+ @smaak_client.set_private_key(secure_service.trust_store.associations[secure_service.dynamic]['private_key'])
54
+ else
55
+ @smaak_client.set_identifier(SoarSc::environment['IDENTIFIER'])
56
+ @smaak_client.set_private_key(@configuration['private_key'])
57
+ @configuration['associations'].each do |identifier, association|
58
+ @smaak_client.add_association(identifier, association['public_key'], association['psk'], association['encrypt'])
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,15 @@
1
+ module SoarSc
2
+ module Web
3
+ module Models
4
+ class ConfiguredModel
5
+ attr_accessor :configuration
6
+ attr_accessor :dependencies
7
+
8
+ def initialize(configuration)
9
+ @configuration = configuration
10
+ @dependencies = SoarSc::dependencies
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'soar_configured_factory'
2
+
3
+ module SoarSc
4
+ module Web
5
+ module Models
6
+ class ModelFactory < SoarConfiguredFactory::ConfiguredFactory
7
+ def initialize(configuration)
8
+ super(configuration)
9
+ @path = ['providers']
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ module SoarSc
2
+ module Web
3
+ class Parser
4
+ def self.parseIntoParams(request)
5
+ rx = extract_request_parameters(request)
6
+ return {} if not rx
7
+ enumerate_parameters(rx)
8
+ end
9
+
10
+ def self.ensure_quoted(value)
11
+ is_quoted?(value) ? value : "\"#{value}\""
12
+ end
13
+
14
+ def self.ensure_not_quoted(value)
15
+ is_quoted?(value) ? value[1..-2] : value
16
+ end
17
+
18
+ private
19
+
20
+ def self.is_quoted?(param)
21
+ double = (param[0] == '"') and (param[param.size-1] == '"')
22
+ single = (param[0] == "'") and (param[param.size-1] == "'")
23
+ single or double
24
+ end
25
+
26
+ def self.extract_request_parameters(request)
27
+ rx = request.env['rack.request.form_vars'] || ""
28
+ rx = ((request.body.is_a? Rack::Lint::InputWrapper) ? request.body.gets : request.body) if rx == ""
29
+ rx = request.url.split('?')[1] if (request.url) and (not request.url.split('?').nil?) and (rx == "")
30
+ rx
31
+ end
32
+
33
+ def self.enumerate_parameters(rx)
34
+ params = {}
35
+ rx.split('&').each do |keyvalue|
36
+ params = append_parameter(params, keyvalue)
37
+ end
38
+ params
39
+ end
40
+
41
+ def self.append_parameter(params, keyvalue)
42
+ key = keyvalue.split('=')[0]
43
+ value = keyvalue.split('=')[1]
44
+ params[key] = value.nil? ? nil : CGI::unescape(value)
45
+ params
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module SoarScMvc
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "soar_sc_mvc/version"
2
+ require 'rack'
3
+ require 'smaak'
4
+ require 'soar_smaak'
5
+ require "soar_sc_mvc/parser"
6
+ require "soar_sc_mvc/configured_controller"
7
+ require "soar_sc_mvc/configured_model"
8
+ require "soar_sc_mvc/model_factory"
9
+
10
+ module SoarScMvc
11
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soar_sc_mvc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soar_sc_mvc"
8
+ spec.version = SoarScMvc::VERSION
9
+ spec.authors = ["Ernst Van Graan"]
10
+ spec.email = ["ernst.van.graan@hetzner.co.za"]
11
+
12
+ spec.summary = %q{MVC library for SOAR reference implementation service component}
13
+ spec.description = %q{MVC library for SOAR reference implementation service component}
14
+ spec.homepage = "https://github.com/hetznerZA/soar_sc_mvc"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "soar_configured_factory", '~> 0.1.0'
31
+ spec.add_dependency 'smaak', "~> 0.2.2"
32
+ spec.add_dependency 'soar_smaak', "~> 0.1.16"
33
+ spec.add_dependency "rack", "~> 1.6.4"
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.12"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "byebug"
39
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soar_sc_mvc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ernst Van Graan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: soar_configured_factory
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: smaak
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: soar_smaak
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.16
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.16
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: MVC library for SOAR reference implementation service component
126
+ email:
127
+ - ernst.van.graan@hetzner.co.za
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - lib/soar_sc_mvc.rb
142
+ - lib/soar_sc_mvc/configured_controller.rb
143
+ - lib/soar_sc_mvc/configured_model.rb
144
+ - lib/soar_sc_mvc/model_factory.rb
145
+ - lib/soar_sc_mvc/parser.rb
146
+ - lib/soar_sc_mvc/version.rb
147
+ - soar_sc_mvc.gemspec
148
+ homepage: https://github.com/hetznerZA/soar_sc_mvc
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.5.1
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: MVC library for SOAR reference implementation service component
172
+ test_files: []