norad_cli 0.1.5 → 0.1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e7fb80586e9097ae6596d925a944317aa24ca56
4
- data.tar.gz: 4fb2895a21437b787d29549588c1c03d10365196
3
+ metadata.gz: 6845add9cfabc34338bc67744b6d3b4509f3a0bd
4
+ data.tar.gz: 870a0347fd4929e075c877eaec20034d3471317e
5
5
  SHA512:
6
- metadata.gz: b43b85e81eb87e5d867c16c0e65c5569c4acf2891ae0656914ecd92589fb2a6d459ed30753c33e6d01130d01fcbe142c976a9e54237bb17374f5500249b83dff
7
- data.tar.gz: f16410a27950b486298e70bd5f93b00c44accb6fbcc22c589e1188b037ef15fc14e29494bac79658d2a319afd5be792a4f3f2db8e8f03c754de1f6d2ad2dd198
6
+ metadata.gz: 31bfb046789af2d16a86f912db431b5b10e4e9ec1b7fead6fd6be4db6841c04748d3c9cc5e7ee68d9ece1d606167cfaa9127864c5b44b6d59811450f9ffe4a30
7
+ data.tar.gz: 05d22bb8f7ff35bf7abd624003c2d023f9778370d791a6558b92296c48458a20a318a0a3d05609be97cb4a74d7dcde205c5a43b44c78d7c13ef499c1f066885c
data/.rubocop.yml CHANGED
@@ -44,3 +44,6 @@ Style/RegexpLiteral:
44
44
  Style/Next:
45
45
  Exclude:
46
46
  - 'lib/norad_cli/support/manifest_spec.rb'
47
+ Style/IfUnlessModifier:
48
+ Exclude:
49
+ - 'lib/norad_cli/cli/sectest.rb'
@@ -22,7 +22,9 @@ class Sectest < Thor
22
22
  # Grab the current directory
23
23
  repo_dir = Dir.pwd
24
24
 
25
- puts options[:configurable]
25
+ # Check for the root_dir
26
+ root_dir?
27
+
26
28
  # Set options for templates
27
29
  options[:name] = sectest_name
28
30
  options[:spec_class_name] = sectest_name.split('-').map { |t| t =~ /\d+/ ? t : t.capitalize! }.join
@@ -52,6 +54,9 @@ class Sectest < Thor
52
54
  option :registry, aliases: '-r', default: 'norad-registry.cisco.com:5000', desc: 'The Docker registry for Docker images'
53
55
  option :version, aliases: '-v', default: 'latest', desc: 'The version of the sectest container to build'
54
56
  def build
57
+ # Check for the root_dir
58
+ root_dir?
59
+
55
60
  # Error check to ensure this is a plugin directory
56
61
  Dir.glob('sectests/*').select do |f|
57
62
  if File.directory? f
@@ -66,6 +71,9 @@ class Sectest < Thor
66
71
  option :registry, aliases: '-r', default: 'norad-registry.cisco.com:5000', desc: 'The Docker registry for Docker images'
67
72
  option :version, aliases: '-v', default: 'latest', desc: 'The version of the sectest container to build'
68
73
  define_method 'build:image' do |name|
74
+ # Check for the root_dir
75
+ root_dir?
76
+
69
77
  imgs_to_build = {}
70
78
  imgs_to_build["sectests/#{name}"] = "#{options[:registry]}/#{name}:#{options[:version]}"
71
79
 
@@ -97,6 +105,9 @@ class Sectest < Thor
97
105
  option :registry, aliases: '-r', default: 'norad-registry.cisco.com:5000', desc: 'The Docker registry for Docker images'
98
106
  option :version, aliases: '-v', default: 'latest', desc: 'The version of the sectest container to build'
99
107
  define_method 'build:specs' do |name|
108
+ # Check for the root_dir
109
+ root_dir?
110
+
100
111
  imgs_to_build = {}
101
112
  imgs_to_build["#{File.expand_path(File.dirname(__FILE__))}/../templates/spec/support/Dockerfile.testserver"] = 'docker-images-test-results-server:latest'
102
113
  imgs_to_build["#{File.expand_path(File.dirname(__FILE__))}/../templates/spec/support/Dockerfile.ubuntu_ssh"] = 'docker-images-test-ubuntu-ssh-server:latest'
@@ -126,6 +137,9 @@ class Sectest < Thor
126
137
  option :registry, aliases: '-r', default: 'norad-registry.cisco.com:5000', desc: 'The Docker registry for Docker images'
127
138
  option :version, aliases: '-v', default: 'latest', desc: 'The version of the sectest container to build'
128
139
  define_method 'build:all' do |name|
140
+ # Check for the root_dir
141
+ root_dir?
142
+
129
143
  # Build the sectest image
130
144
  send('build:image', name)
131
145
 
@@ -133,34 +147,18 @@ class Sectest < Thor
133
147
  send('build:specs', name)
134
148
  end
135
149
 
136
- # Define arguments and options
137
- desc 'execute SECTESTNAME ARGUMENTS', 'Executes the specified security test SECTESTNAME w/ ARGUMENTS'
138
- option :registry, aliases: '-r', default: 'norad-registry.cisco.com:5000', desc: 'The Docker registry for Docker images'
139
- option :version, aliases: '-v', default: 'latest', desc: 'The version of the tools docker container to build'
140
- def execute(name, arguments)
141
- # Ensure container exists
142
- if !Docker::Image.exist?("#{options[:registry]}/#{name}:#{options[:version]}")
143
- say("Requested image #{options[:registry]}/#{name}:#{options[:version]} does not exist!", :red)
144
- exit(1)
145
- end
146
-
147
- # Setup and run the container
148
- env = ['NORAD_ROOT=', %(ASSESSMENT_PATHS=[{"id":"1", "assessment": "1"}]), 'NORAD_SECRET=1234']
149
- container = Docker::Container.create(Image: "#{options[:registry]}/#{name}:#{options[:version]}",
150
- Env: env,
151
- Cmd: arguments)
152
-
153
- # Start the container, watch stdout
154
- container.tap(&:start).attach { |stream, chunk| puts "#{stream}: #{chunk}" }
155
- end
156
-
157
150
  desc 'spec:image SECTESTNAME', 'Run the rspec tests for SECTESTNAME'
158
- option :verbose, aliases: '-v', type: :boolean, default: false, desc: 'Turn on verbose logging'
159
- option :scan_assessment, aliases: '-s', type: :boolean, default: true, desc: 'Fix me'
151
+ option :verbose, aliases: '-v', type: :boolean, desc: 'Turn on verbose logging'
160
152
  define_method 'spec:image' do |name|
153
+ # Check for the root_dir
154
+ root_dir?
155
+
161
156
  # Set environment variables
162
- ENV['ENABLE_LOGS'] = options[:verbose] ? 'true' : 'false'
163
- ENV['SCAN_ASSESSMENT'] = options[:scan_assessment] ? 'true' : 'false'
157
+ if options[:verbose]
158
+ ENV['ENABLE_LOGS'] = 'true'
159
+ end
160
+
161
+ ENV['SCAN_ASSESSMENT'] = 'true'
164
162
  ENV['TEST_RESULTS_SERVER_IMAGE'] = 'docker-images-test-results-server'
165
163
  ENV['UBUNTU_SSH_SERVER_IMAGE'] = 'docker-images-test-ubuntu-ssh-server'
166
164
 
@@ -172,6 +170,9 @@ class Sectest < Thor
172
170
  option :verbose, aliases: '-v', type: :boolean, default: false, desc: 'Turn on verbose logging'
173
171
  option :scan_assessment, aliases: '-s', type: :boolean, default: true, desc: 'Fix me'
174
172
  def spec
173
+ # Check for the root_dir
174
+ root_dir?
175
+
175
176
  # Error check to ensure this is a plugin directory
176
177
  Dir.glob('sectests/*').select do |f|
177
178
  if File.directory? f
@@ -185,7 +186,8 @@ class Sectest < Thor
185
186
  option :seedfile, aliases: '-s', type: :string, default: './containers.rb', desc: 'The name of the seed file to generate'
186
187
  option :docsite, aliases: '-d', type: :string, default: 'https://norad.gitlab.io/docs/', desc: 'Set the documentation site'
187
188
  def seed
188
- # Error check to ensure this is a plugin directory
189
+ # Check for the root_dir
190
+ root_dir?
189
191
 
190
192
  # Generate the seed file
191
193
  SeedGenerator.process_manifests(options[:seedfile], options[:docsite])
@@ -193,6 +195,9 @@ class Sectest < Thor
193
195
 
194
196
  desc 'validate:image SECTESTNAME', 'Validate SECTESTNAME manifest.yml and readme.md'
195
197
  define_method 'validate:image' do |name|
198
+ # Check for the root_dir
199
+ root_dir?
200
+
196
201
  # Validate the readme file
197
202
  ENV['sectest_name'] = name
198
203
  RSpec::Core::Runner.run(["#{File.dirname(File.expand_path(__FILE__))}/../support/readme_spec.rb"], $stderr, $stdout)
@@ -203,6 +208,9 @@ class Sectest < Thor
203
208
 
204
209
  desc 'validate', 'Validate all manifest.yml and readme.md'
205
210
  def validate
211
+ # Check for the root_dir
212
+ root_dir?
213
+
206
214
  # Error check to ensure this is a plugin directory
207
215
  Dir.glob('sectests/*').select do |f|
208
216
  if File.directory? f
@@ -226,5 +234,15 @@ class Sectest < Thor
226
234
  from_image = from_line[0][%r{\AFROM\s+(.*?\/)?(.*?)(:.*?)?\Z}i, 2] || raise('bad from')
227
235
  [from_image, from_line_arr[1]]
228
236
  end
237
+
238
+ # Ensure commands are run from the root dir
239
+ def root_dir?
240
+ %w(base spec sectests).each do |dirrepo_name|
241
+ if !File.exist?(dirrepo_name)
242
+ say("Commands must be run from the root directory\nExiting....", :red)
243
+ exit(1)
244
+ end
245
+ end
246
+ end
229
247
  end
230
248
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module NoradCli
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.6'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: norad_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Hitchcock