norad_cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.gitlab-ci.yml +43 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +34 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/.travis.yml +5 -0
  9. data/CONTRIBUTING.md +102 -0
  10. data/Gemfile +5 -0
  11. data/LICENSE +201 -0
  12. data/README.md +119 -0
  13. data/Rakefile +7 -0
  14. data/bin/console +15 -0
  15. data/bin/norad +6 -0
  16. data/bin/setup +8 -0
  17. data/lib/norad_cli/cli/main.rb +12 -0
  18. data/lib/norad_cli/cli/secrepo.rb +46 -0
  19. data/lib/norad_cli/cli/sectest.rb +183 -0
  20. data/lib/norad_cli/support/api_security_container_seed_script.rb +42 -0
  21. data/lib/norad_cli/support/manifest.rb +16 -0
  22. data/lib/norad_cli/support/readme.rb +3 -0
  23. data/lib/norad_cli/templates/.gitignore +2 -0
  24. data/lib/norad_cli/templates/.rspec +2 -0
  25. data/lib/norad_cli/templates/CONTRIBUTING.md +193 -0
  26. data/lib/norad_cli/templates/LICENSE.erb +201 -0
  27. data/lib/norad_cli/templates/README.md +2 -0
  28. data/lib/norad_cli/templates/ci/.gitlab.ci.yml +44 -0
  29. data/lib/norad_cli/templates/spec/spec_helper.rb +247 -0
  30. data/lib/norad_cli/templates/spec/support/Dockerfile.testserver +22 -0
  31. data/lib/norad_cli/templates/spec/support/Dockerfile.ubuntu_ssh +20 -0
  32. data/lib/norad_cli/templates/spec/support/ssh_key +27 -0
  33. data/lib/norad_cli/templates/spec/support/ssh_key.pub +1 -0
  34. data/lib/norad_cli/templates/spec/support/test_server/.gitignore +21 -0
  35. data/lib/norad_cli/templates/spec/support/test_server/Gemfile +5 -0
  36. data/lib/norad_cli/templates/spec/support/test_server/Gemfile.lock +116 -0
  37. data/lib/norad_cli/templates/spec/support/test_server/Rakefile +6 -0
  38. data/lib/norad_cli/templates/spec/support/test_server/app/controllers/application_controller.rb +2 -0
  39. data/lib/norad_cli/templates/spec/support/test_server/app/controllers/results_controller.rb +23 -0
  40. data/lib/norad_cli/templates/spec/support/test_server/app/models/application_record.rb +3 -0
  41. data/lib/norad_cli/templates/spec/support/test_server/app/models/result.rb +2 -0
  42. data/lib/norad_cli/templates/spec/support/test_server/bin/bundle +3 -0
  43. data/lib/norad_cli/templates/spec/support/test_server/bin/rails +9 -0
  44. data/lib/norad_cli/templates/spec/support/test_server/bin/rake +9 -0
  45. data/lib/norad_cli/templates/spec/support/test_server/config/application.rb +30 -0
  46. data/lib/norad_cli/templates/spec/support/test_server/config/boot.rb +3 -0
  47. data/lib/norad_cli/templates/spec/support/test_server/config/cable.yml +9 -0
  48. data/lib/norad_cli/templates/spec/support/test_server/config/database.yml +25 -0
  49. data/lib/norad_cli/templates/spec/support/test_server/config/environment.rb +5 -0
  50. data/lib/norad_cli/templates/spec/support/test_server/config/environments/development.rb +47 -0
  51. data/lib/norad_cli/templates/spec/support/test_server/config/environments/production.rb +78 -0
  52. data/lib/norad_cli/templates/spec/support/test_server/config/environments/test.rb +42 -0
  53. data/lib/norad_cli/templates/spec/support/test_server/config/initializers/application_controller_renderer.rb +6 -0
  54. data/lib/norad_cli/templates/spec/support/test_server/config/initializers/backtrace_silencers.rb +7 -0
  55. data/lib/norad_cli/templates/spec/support/test_server/config/initializers/cors.rb +16 -0
  56. data/lib/norad_cli/templates/spec/support/test_server/config/initializers/filter_parameter_logging.rb +4 -0
  57. data/lib/norad_cli/templates/spec/support/test_server/config/initializers/inflections.rb +16 -0
  58. data/lib/norad_cli/templates/spec/support/test_server/config/initializers/mime_types.rb +4 -0
  59. data/lib/norad_cli/templates/spec/support/test_server/config/initializers/new_framework_defaults.rb +18 -0
  60. data/lib/norad_cli/templates/spec/support/test_server/config/initializers/wrap_parameters.rb +14 -0
  61. data/lib/norad_cli/templates/spec/support/test_server/config/locales/en.yml +23 -0
  62. data/lib/norad_cli/templates/spec/support/test_server/config/puma.rb +47 -0
  63. data/lib/norad_cli/templates/spec/support/test_server/config/routes.rb +5 -0
  64. data/lib/norad_cli/templates/spec/support/test_server/config/secrets.yml +20 -0
  65. data/lib/norad_cli/templates/spec/support/test_server/config.ru +5 -0
  66. data/lib/norad_cli/templates/spec/support/test_server/db/migrate/20160725144604_create_results.rb +15 -0
  67. data/lib/norad_cli/templates/spec/support/test_server/db/schema.rb +2 -0
  68. data/lib/norad_cli/templates/spec/support/test_server/lib/tasks/.keep +0 -0
  69. data/lib/norad_cli/templates/spec/support/test_server/log/.keep +0 -0
  70. data/lib/norad_cli/templates/spec/support/test_server/public/robots.txt +5 -0
  71. data/lib/norad_cli/templates/spec/support/test_server/tmp/.keep +0 -0
  72. data/lib/norad_cli/templates/tool/Dockerfile.auth.target.erb +2 -0
  73. data/lib/norad_cli/templates/tool/Dockerfile.erb +11 -0
  74. data/lib/norad_cli/templates/tool/Dockerfile.unauth.target.erb +5 -0
  75. data/lib/norad_cli/templates/tool/README.md.erb +17 -0
  76. data/lib/norad_cli/templates/tool/manifest.yml.erb +19 -0
  77. data/lib/norad_cli/templates/tool/tool_spec.rb.erb +55 -0
  78. data/lib/norad_cli/templates/tool/wrapper.rb.erb +47 -0
  79. data/lib/norad_cli/version.rb +4 -0
  80. data/lib/norad_cli.rb +7 -0
  81. data/norad_cli.gemspec +38 -0
  82. metadata +285 -0
@@ -0,0 +1,44 @@
1
+ stages:
2
+ - validate
3
+ - build
4
+ - test
5
+ - deploy
6
+ - integrate
7
+
8
+ before_script:
9
+ - rvm gemset use norad-docker-images
10
+ - gem install bundler --no-ri --no-rdoc
11
+ - bundle install
12
+
13
+ validate_manifests:
14
+ stage: validate
15
+ script:
16
+ - rspec spec/validate_manifests_spec.rb
17
+ - rspec spec/require_readmes_spec.rb
18
+
19
+ build_containers:
20
+ stage: build
21
+ script:
22
+ - ./ci/build_images.sh
23
+
24
+ test_containers:
25
+ stage: test
26
+ script:
27
+ - ./ci/run_image_integration_tests.sh
28
+
29
+ push_images:
30
+ stage: deploy
31
+ only:
32
+ - master
33
+ script:
34
+ - ./ci/push_images.sh
35
+
36
+ generate_api_seed:
37
+ stage: integrate
38
+ only:
39
+ - master
40
+ script:
41
+ - ./ci/api_security_container_seed_script.rb
42
+ artifacts:
43
+ paths:
44
+ - containers.rb
@@ -0,0 +1,247 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.before(:context, scan_assessment: true) do
11
+ @base_id = described_class.scan_base
12
+ @base_results = described_class.retrieve_results(@base_id)
13
+ described_class.get_scans.each do |type|
14
+ puts type
15
+ instance_variable_set("@#{type}_id", described_class.scan_machine(type))
16
+ puts instance_variable_get("@#{type}_id")
17
+ instance_variable_set("@#{type}_results", described_class.retrieve_results(instance_variable_get("@#{type}_id")))
18
+ end
19
+ end
20
+ end
21
+
22
+ if ENV['SCAN_ASSESSMENT']
23
+ require 'yaml'
24
+ require 'net/http'
25
+ require 'json'
26
+ require 'docker'
27
+ require 'securerandom'
28
+ require 'base64'
29
+ require 'pp'
30
+
31
+ Docker.url = ENV.fetch('DOCKER_HOST') { "unix:///var/run/docker.sock" }
32
+ #*************************************************************************
33
+ # @parent - for variants of base tests like serverspec
34
+ # @verify_machine_ready - when True will wait for file /tmp/status in the container
35
+ # under test content's to match /ready_to_test/
36
+ # @host_config - passed to Docker::Container.create param HostConfig
37
+ #
38
+ # Example:
39
+ #
40
+ # class DockerHostCisBenchmarks
41
+ # extend AssessmentHelpers
42
+ # @parent = 'serverspec'
43
+ # @host_config = {
44
+ # 'vulnerable': { 'Privileged': true },
45
+ # 'secure': { 'Privileged': true, 'cap-add': 'ALL', },
46
+ # }
47
+ # @verify_machine_ready = true
48
+ # end
49
+
50
+ RSpec::Matchers.define :fail_with_msg do |expected|
51
+ match do
52
+ false
53
+ end
54
+
55
+ failure_message do
56
+ expected.to_s
57
+ end
58
+ end
59
+
60
+ class ResultsServer
61
+ attr_accessor :container
62
+
63
+ def host_port
64
+ container.info["NetworkSettings"]["Ports"]["3000/tcp"].first["HostPort"]
65
+ end
66
+ end
67
+
68
+ class BaseMachine
69
+ attr_accessor :container
70
+ end
71
+
72
+ results_server = ResultsServer.new
73
+ base_machine = BaseMachine.new
74
+
75
+ RSpec.configure do |config|
76
+ config.before(:suite) do
77
+ results_server.container = Docker::Container.create(
78
+ Image: ENV['TEST_RESULTS_SERVER_IMAGE'],
79
+ HostConfig: { PublishAllPorts: true }
80
+ )
81
+ results_server.container.start
82
+ sleep 5 # sleep rather than wait since we are daemonizing a container
83
+ results_server.container.refresh! # get more details
84
+ base_machine.container = Docker::Container.create(Image: 'alpine:3.4', Cmd: '/bin/ash', Tty: true)
85
+ base_machine.container.start
86
+ end
87
+
88
+ config.after(:suite) do
89
+ results_server.container.stop
90
+ results_server.container.delete(force: true)
91
+ base_machine.container.stop
92
+ base_machine.container.delete(force: true)
93
+ end
94
+ end
95
+
96
+ AssessmentHelpers = Module.new do
97
+ MAX_SLEEP_TIME = 30
98
+ SLEEP_INTERVAL = 3
99
+
100
+ define_method :get_scans do
101
+ %w(vulnerable secure)
102
+ end
103
+
104
+ define_method :assessment_name do
105
+ name.split(/(?=[A-Z])|(?<=[a-z])(\d+)/).map { |e| e.downcase }.join('-')
106
+ end
107
+
108
+ define_method :manifest_file do
109
+ assessment_path = @parent.nil? ? assessment_name : "#{@parent}/variants/#{assessment_name}"
110
+ "./#{assessment_path}/manifest.yml"
111
+ end
112
+
113
+ define_method :options do
114
+ @options ||= YAML.load(File.read(manifest_file))
115
+ end
116
+
117
+ define_method :image_name do
118
+ "#{options['registry']}/#{options['name']}:#{options['version']}"
119
+ end
120
+
121
+ define_method :config_hash do
122
+ return default_test_config if respond_to?(:default_test_config)
123
+ options['default_config'].each_with_object({}) do |(k, v), h|
124
+ h[k.to_sym] = v
125
+ end
126
+ end
127
+
128
+ define_method :args do |target|
129
+ ssh_vals = options['prog_args']['ssh_key'] ? load_ssh_args : {}
130
+ format(options['prog_args'], config_hash.merge({target: target}).merge(ssh_vals)).split(' ')
131
+ end
132
+
133
+ define_method :load_ssh_args do
134
+ { ssh_user: 'testuser', ssh_key: Base64.strict_encode64(File.read('./spec/support/ssh_key')) }
135
+ end
136
+
137
+ define_method :machine_ready? do |machine, image_name|
138
+ if @verify_machine_ready
139
+ config_status = machine.exec(['cat', '/tmp/status']).to_s
140
+ unless config_status.match(/ready_to_test/)
141
+ puts "machine:#{image_name} not ready_to_test current status:#{config_status}"
142
+ return false
143
+ end
144
+ end
145
+ true
146
+ end
147
+
148
+ define_method :machine_running? do |machine, image_name|
149
+ if !machine.json['State']['Running']
150
+ puts "Target machine: #{image_name} failed to start."
151
+ return false
152
+ end
153
+ true
154
+ end
155
+
156
+ define_method :start_target_machine do |image_name|
157
+ elapsed_time = 0
158
+ target = image_name.split('-')[-1].to_sym
159
+ h_config = nil
160
+ h_config = @host_config[target] if @host_config
161
+ machine = Docker::Container.create(Image: image_name, HostConfig: h_config )
162
+ machine.start
163
+ sleep SLEEP_INTERVAL
164
+ until (machine_running?(machine, image_name) && machine_ready?(machine, image_name)) || elapsed_time > MAX_SLEEP_TIME
165
+ sleep SLEEP_INTERVAL # sleep rather than wait since we are daemonizing a container
166
+ elapsed_time += SLEEP_INTERVAL
167
+ end
168
+ machine
169
+ end
170
+
171
+ define_method :log_machine_not_running do |machine, image_name|
172
+ puts '*' * 80
173
+ puts "* target docker container for #{image_name} not running"
174
+ puts '*' * 80
175
+ pp machine.json
176
+ puts "******************** logs #{image_name} *****************************"
177
+ machine.streaming_logs(stdout: true, stderr: true) { |stream, chunk| puts "#{stream}: #{chunk}" }
178
+ end
179
+
180
+ define_method :stop_target_machine do |machine|
181
+ machine.stop
182
+ machine.delete(force: true)
183
+ machine.id
184
+ end
185
+
186
+ define_method :scan_machine do |type|
187
+ image_name = "#{assessment_name}-#{type}"
188
+ machine = start_target_machine(image_name)
189
+ target_name = type
190
+ target_name = @target_host if @target_host
191
+ scan(target_name, machine.id) if machine_running?(machine, image_name) && machine_ready?(machine, image_name)
192
+ log_machine_not_running(machine, image_name) unless machine_running?(machine, image_name)
193
+ stop_target_machine(machine)
194
+ end
195
+
196
+ define_method :scan_base do
197
+ assessment_id = scan('base', base_machine.container.id)
198
+ assessment_id
199
+ end
200
+
201
+ define_method :scan do |target, target_id|
202
+ assessment_id = target == 'base' ? SecureRandom.hex(32) : target_id
203
+ env = [
204
+ "NORAD_ROOT=http://results:3000",
205
+ %Q{ASSESSMENT_PATHS=[{"id":"#{target}", "assessment": "/results/#{assessment_id}"}]},
206
+ "NORAD_SECRET=1234"
207
+ ]
208
+ c = Docker::Container.create({
209
+ Image: image_name,
210
+ Cmd: args(target),
211
+ Env: env,
212
+ HostConfig: { Links: ["#{target_id}:#{target}", "#{results_server.container.id}:results"] },
213
+ })
214
+
215
+ c.start
216
+ c.wait(60 * 10)
217
+
218
+ # Output container logs for debugging
219
+ if ENV['ENABLE_LOGS']
220
+ c.stop
221
+ c_state = c.json['State']
222
+
223
+ # Print the entire state regardless of error or not to aid in debugging
224
+ puts "[DEBUG] Container #{image_name}'s Final State"
225
+ puts '-------------------------'
226
+ c_state.each do |key, value|
227
+ puts "#{key}: #{value}"
228
+ end
229
+
230
+ puts "\n[DEBUG] Logs for target \"#{image_name}\" run against #{target}:"
231
+
232
+ # Print logs regardless of ExitCode
233
+ puts c.logs(stdout: true, stderr: true)
234
+
235
+ end
236
+
237
+ c.delete(force: true)
238
+ assessment_id
239
+ end
240
+
241
+ define_method :retrieve_results do |id|
242
+ url = "http://localhost:#{results_server.host_port}/results?assessment_id=#{id}"
243
+ uri = URI(url)
244
+ JSON.parse(Net::HTTP.get(uri))
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,22 @@
1
+ FROM ruby:2.3.1
2
+
3
+ # Adapted from: https://github.com/marcelocg/phoenix-docker/blob/master/Dockerfile
4
+ MAINTAINER Blake Hitchcock <blhitchc@cisco.com>
5
+
6
+ # update and install some software requirements
7
+ RUN apt-get update && apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade -y && apt-get install -y libxml2-dev libxslt1-dev nodejs
8
+
9
+ ENV APP_HOME /myapp
10
+ ENV RAILS_ENV production
11
+ RUN mkdir $APP_HOME
12
+ WORKDIR $APP_HOME
13
+
14
+ ADD test_server/Gemfile* $APP_HOME/
15
+ RUN bundle install
16
+
17
+ ADD test_server/. $APP_HOME
18
+ RUN rake db:create
19
+ RUN rake db:migrate
20
+
21
+ EXPOSE 3000
22
+ CMD ["bin/rails", "server", "--port", "3000"]
@@ -0,0 +1,20 @@
1
+ FROM ubuntu:14.04
2
+ MAINTAINER Blake Hitchcock
3
+
4
+ RUN apt-get update; apt-get install -y openssh-server
5
+ RUN mkdir -p ~root/.ssh && chmod 700 ~root/.ssh/ && \
6
+ echo "Port 22\n" >> /etc/ssh/sshd_config && \
7
+ cp -a /etc/ssh /etc/ssh.cache
8
+ RUN mkdir /var/run/sshd
9
+
10
+ # Create Sudo user
11
+ # useradd doesn't like -m in a script.
12
+ RUN useradd -K MAIL_DIR=/dev/null -s /bin/bash testuser
13
+ RUN mkdir -p /home/testuser/.ssh
14
+ RUN sed -i '4i\testuser ALL= (ALL) NOPASSWD: ALL' /etc/sudoers
15
+ COPY ssh_key.pub /home/testuser/.ssh/authorized_keys
16
+ RUN chown -R testuser /home/testuser
17
+ RUN chmod 600 /home/testuser/.ssh/authorized_keys
18
+
19
+ EXPOSE 22
20
+ CMD ["/usr/sbin/sshd", "-D"]
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEpAIBAAKCAQEAzOOvUUrCexzr1Wx8GdtgVqfRBxQR7+7Eh0UyrDfMyonAsYvP
3
+ LaAHMmrobrsOoSWk8RA/fyo/t2m98UJVnpyr0L9xb/JIkDg0hlm+QdUnW7ax5PPE
4
+ 5kssQsh2eSPvlolLjvfOQEYGplsuQ3B56Nc1snhMs1lCpHpwSSotigz+MP16K2Qf
5
+ R+rztPYfr5cGgJzczIUrYsu8gS/CkSmLz76FOMjlS6ss+b5u3q0VdJrDHhtP21jJ
6
+ 850iwTNFvw9l6A0+puQEgKwnLDhxwlIlOzplHm0WlLIzUJwHzP/ggKMuCc7ZHkhY
7
+ v2pklOwfNAUpR8m07inWD+TCFYEyRpUKhEZBhwIDAQABAoIBAHVqQY0Pj7Yn08qh
8
+ +diDjIj8cOBikwjxxvRSJoDlFVo4aRIWMetOmvE8rOjQD8kvnn97NTg1yP/d/Djn
9
+ L9POqvPc0jA6I3VqkEcx5MMrWPvJDddMD1l+WOYIpUQ04Nde5MsQncTdnG/3LuL8
10
+ 8RALTL1zDVl2XKePdwumvSQw3/bINZhdJl/UhtRrpvmbxKzNbojH/007J+OpsYlu
11
+ YmpBIenZzxYVXUHlAml8Mu0tCe6stdWWTnHFxLYrf0bAdKHmf0FuiB/J6q3ajh78
12
+ NFTqVAWwZ9BsNtdSbRLkdA31EZoez8ZAiqtbbJLEt4f6EL7y1E26m2wP9XoM4SlD
13
+ tAyRJvkCgYEA581AirCFlkMlg4IdhJqLDMug4g578gKvBIBJ2kXS9pEcYqKPPMUj
14
+ VhVszbEGLNKT8qBlTYbYi9KecE6PJ3/Mk8hUan2KyfgzXpEAUkc793ubzKdtUJTZ
15
+ Di8DcgdcmNHlkZ0tY7jmMHcHHilkLb1iNCtI4YbN77JDKFn8sSJMoyMCgYEA4kc3
16
+ rTuDSLruG7x4Br6fdboUkNZwTBEJLt48arFJksrnBaE7tO+aQZ6Hdc/5AtAFDasX
17
+ jsYZ2fiC5aIgH9qoFxekYza5ANSHUjSqCduNizm4h01RROQzcQCnwn7bgHDmSaTq
18
+ gCPfpRGHHT4fOPLafErySb3YQhKhWdSteILNEE0CgYEAoh6/oUBMbgeQWSXLl06v
19
+ KcfRQcl3jo+p8K/49xwWrDRZcfLX01zdlftuGX5SH084Al2D/HDvSvuHrGyFWs7b
20
+ OhDGWaRsSU26P82SN/lyS2i8UqpWniE8ndrrwfi8HnXO5cTUVgafmA3ngITad9MY
21
+ t/v+AR3TMm2u4q3tOcYPa5kCgYEA4GySJBaqlzAPiSLcSJQ3w6PTUfPdXRRobzur
22
+ 4IYF2rmzeDn55fLeo8Z/w7GJ3+hBmtTegJSqfy2jZe3uvqk3ne+s81oLE2+25ymk
23
+ nDJNqJCPHGLq/9D11FY6DQWU30caoGAY1Q6/ehBwWeiLPwhe+ne65riMDLw9m8L8
24
+ alIQ4OECgYARpS8CfpC0lR9kWiuUU1h8LQ01rwS3IlhNHUzbVtydJJp6o3llY7Ws
25
+ FEJUHoE8Lp/sujbUCTly62NVeZBvDKHb5wkMusR3Qx1+fmgedR5Qp+I+WtVctAI9
26
+ vgO0JpuoFlC2qRe/XmwQJkSOi/KrRWRiIuW5bxhU+dF9Ota16jCzsA==
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDM469RSsJ7HOvVbHwZ22BWp9EHFBHv7sSHRTKsN8zKicCxi88toAcyauhuuw6hJaTxED9/Kj+3ab3xQlWenKvQv3Fv8kiQODSGWb5B1SdbtrHk88TmSyxCyHZ5I++WiUuO985ARgamWy5DcHno1zWyeEyzWUKkenBJKi2KDP4w/XorZB9H6vO09h+vlwaAnNzMhStiy7yBL8KRKYvPvoU4yOVLqyz5vm7erRV0msMeG0/bWMnznSLBM0W/D2XoDT6m5ASArCcsOHHCUiU7OmUebRaUsjNQnAfM/+CAoy4JztkeSFi/amSU7B80BSlHybTuKdYP5MIVgTJGlQqERkGH vagrant@norad-dev-box
@@ -0,0 +1,21 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*
16
+ /tmp/*
17
+ !/log/.keep
18
+ !/tmp/.keep
19
+
20
+ # Ignore Byebug command history file.
21
+ .byebug_history
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.0.0'
4
+ gem 'sqlite3'
5
+ gem 'puma', '~> 3.0'
@@ -0,0 +1,116 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actioncable (5.0.0)
5
+ actionpack (= 5.0.0)
6
+ nio4r (~> 1.2)
7
+ websocket-driver (~> 0.6.1)
8
+ actionmailer (5.0.0)
9
+ actionpack (= 5.0.0)
10
+ actionview (= 5.0.0)
11
+ activejob (= 5.0.0)
12
+ mail (~> 2.5, >= 2.5.4)
13
+ rails-dom-testing (~> 2.0)
14
+ actionpack (5.0.0)
15
+ actionview (= 5.0.0)
16
+ activesupport (= 5.0.0)
17
+ rack (~> 2.0)
18
+ rack-test (~> 0.6.3)
19
+ rails-dom-testing (~> 2.0)
20
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
21
+ actionview (5.0.0)
22
+ activesupport (= 5.0.0)
23
+ builder (~> 3.1)
24
+ erubis (~> 2.7.0)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ activejob (5.0.0)
28
+ activesupport (= 5.0.0)
29
+ globalid (>= 0.3.6)
30
+ activemodel (5.0.0)
31
+ activesupport (= 5.0.0)
32
+ activerecord (5.0.0)
33
+ activemodel (= 5.0.0)
34
+ activesupport (= 5.0.0)
35
+ arel (~> 7.0)
36
+ activesupport (5.0.0)
37
+ concurrent-ruby (~> 1.0, >= 1.0.2)
38
+ i18n (~> 0.7)
39
+ minitest (~> 5.1)
40
+ tzinfo (~> 1.1)
41
+ arel (7.1.0)
42
+ builder (3.2.2)
43
+ concurrent-ruby (1.0.2)
44
+ erubis (2.7.0)
45
+ globalid (0.3.6)
46
+ activesupport (>= 4.1.0)
47
+ i18n (0.7.0)
48
+ loofah (2.0.3)
49
+ nokogiri (>= 1.5.9)
50
+ mail (2.6.4)
51
+ mime-types (>= 1.16, < 4)
52
+ method_source (0.8.2)
53
+ mime-types (3.1)
54
+ mime-types-data (~> 3.2015)
55
+ mime-types-data (3.2016.0521)
56
+ mini_portile2 (2.1.0)
57
+ minitest (5.9.0)
58
+ nio4r (1.2.1)
59
+ nokogiri (1.6.8)
60
+ mini_portile2 (~> 2.1.0)
61
+ pkg-config (~> 1.1.7)
62
+ pkg-config (1.1.7)
63
+ puma (3.6.0)
64
+ rack (2.0.1)
65
+ rack-test (0.6.3)
66
+ rack (>= 1.0)
67
+ rails (5.0.0)
68
+ actioncable (= 5.0.0)
69
+ actionmailer (= 5.0.0)
70
+ actionpack (= 5.0.0)
71
+ actionview (= 5.0.0)
72
+ activejob (= 5.0.0)
73
+ activemodel (= 5.0.0)
74
+ activerecord (= 5.0.0)
75
+ activesupport (= 5.0.0)
76
+ bundler (>= 1.3.0, < 2.0)
77
+ railties (= 5.0.0)
78
+ sprockets-rails (>= 2.0.0)
79
+ rails-dom-testing (2.0.1)
80
+ activesupport (>= 4.2.0, < 6.0)
81
+ nokogiri (~> 1.6.0)
82
+ rails-html-sanitizer (1.0.3)
83
+ loofah (~> 2.0)
84
+ railties (5.0.0)
85
+ actionpack (= 5.0.0)
86
+ activesupport (= 5.0.0)
87
+ method_source
88
+ rake (>= 0.8.7)
89
+ thor (>= 0.18.1, < 2.0)
90
+ rake (11.2.2)
91
+ sprockets (3.7.0)
92
+ concurrent-ruby (~> 1.0)
93
+ rack (> 1, < 3)
94
+ sprockets-rails (3.1.1)
95
+ actionpack (>= 4.0)
96
+ activesupport (>= 4.0)
97
+ sprockets (>= 3.0.0)
98
+ sqlite3 (1.3.11)
99
+ thor (0.19.1)
100
+ thread_safe (0.3.5)
101
+ tzinfo (1.2.2)
102
+ thread_safe (~> 0.1)
103
+ websocket-driver (0.6.4)
104
+ websocket-extensions (>= 0.1.0)
105
+ websocket-extensions (0.1.2)
106
+
107
+ PLATFORMS
108
+ ruby
109
+
110
+ DEPENDENCIES
111
+ puma (~> 3.0)
112
+ rails (~> 5.0.0)
113
+ sqlite3
114
+
115
+ BUNDLED WITH
116
+ 1.12.5
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::API
2
+ end
@@ -0,0 +1,23 @@
1
+ class ResultsController < ApplicationController
2
+ # GET /results
3
+ def index
4
+ @results = Result.where(assessment_id: params[:assessment_id])
5
+ render json: @results
6
+ end
7
+
8
+ # POST /results
9
+ def create
10
+ params[:results].each do |result|
11
+ Result.create(
12
+ assessment_id: params[:id],
13
+ nid: result[:nid],
14
+ sir: result[:sir],
15
+ status: result[:status],
16
+ output: result[:output],
17
+ title: result[:title],
18
+ description: result[:description]
19
+ )
20
+ end
21
+ render json: Result.where(assessment_id: params[:id]), status: :created
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,2 @@
1
+ class Result < ApplicationRecord
2
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path('../spring', __FILE__)
4
+ rescue LoadError => e
5
+ raise unless e.message.include?('spring')
6
+ end
7
+ APP_PATH = File.expand_path('../config/application', __dir__)
8
+ require_relative '../config/boot'
9
+ require 'rails/commands'
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path('../spring', __FILE__)
4
+ rescue LoadError => e
5
+ raise unless e.message.include?('spring')
6
+ end
7
+ require_relative '../config/boot'
8
+ require 'rake'
9
+ Rake.application.run
@@ -0,0 +1,30 @@
1
+ require_relative 'boot'
2
+
3
+ require "rails"
4
+ # Pick the frameworks you want:
5
+ require "active_model/railtie"
6
+ require "active_job/railtie"
7
+ require "active_record/railtie"
8
+ require "action_controller/railtie"
9
+ require "action_mailer/railtie"
10
+ require "action_view/railtie"
11
+ require "action_cable/engine"
12
+ # require "sprockets/railtie"
13
+ require "rails/test_unit/railtie"
14
+
15
+ # Require the gems listed in Gemfile, including any gems
16
+ # you've limited to :test, :development, or :production.
17
+ Bundler.require(*Rails.groups)
18
+
19
+ module TestServer
20
+ class Application < Rails::Application
21
+ # Settings in config/environments/* take precedence over those specified here.
22
+ # Application configuration should go into files in config/initializers
23
+ # -- all .rb files in that directory are automatically loaded.
24
+
25
+ # Only loads a smaller set of middleware suitable for API only apps.
26
+ # Middleware like session, flash, cookies can be added back manually.
27
+ # Skip views, helpers and assets when generating a new resource.
28
+ config.api_only = true
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -0,0 +1,9 @@
1
+ development:
2
+ adapter: async
3
+
4
+ test:
5
+ adapter: async
6
+
7
+ production:
8
+ adapter: redis
9
+ url: redis://localhost:6379/1
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ production:
24
+ <<: *default
25
+ database: db/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative 'application'
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!