norad_cli 0.2.3 → 0.2.4
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/norad_cli/cli/sectest.rb +8 -0
- data/lib/norad_cli/support/ui_seed_generator.rb +90 -0
- data/lib/norad_cli/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ad7646308ba9f6cd0a67827779ec7fd05c6d992
|
4
|
+
data.tar.gz: 9a774b2c7fe5e97f1b1090099330af3e9a35f917
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b748b7146ec63d642e7299c2224119be7d6cd9878e4498eeaebe10a1ec9fa5181e4dd6943cd9c740dc896225fcfb93194e6d2a2702d8386a024bb80f97ff8d14
|
7
|
+
data.tar.gz: 5528ce3dcb526c735ce929bd05db1dc0a57c6a2927bbe66e8cc24509bf26ed0fd061eb1b8b85c16040f9086ece12673aa8138add39a952694b2e55a58759b436
|
data/Gemfile.lock
CHANGED
@@ -5,6 +5,7 @@ require 'git'
|
|
5
5
|
require 'docker'
|
6
6
|
require 'norad_cli/support/api_security_container_seed_script'
|
7
7
|
require 'norad_cli/support/sectest_container'
|
8
|
+
require 'norad_cli/support/ui_seed_generator'
|
8
9
|
require 'rspec'
|
9
10
|
require 'json'
|
10
11
|
require 'rainbow'
|
@@ -280,6 +281,13 @@ class Sectest < Thor
|
|
280
281
|
SeedGenerator.process_manifests(options[:seedfile], options[:docsite])
|
281
282
|
end
|
282
283
|
|
284
|
+
desc 'seed:private_repo', 'Generate seed to import into UI. '\
|
285
|
+
'Example: `norad sectest seed:private_repo <manifest_path1> <manifest_path2>` '\
|
286
|
+
'(for all tests run without args)'
|
287
|
+
define_method 'seed:private_repo' do |*manifest_paths|
|
288
|
+
NoradCli::UiSeedGenerator.new(manifest_paths).process!
|
289
|
+
end
|
290
|
+
|
283
291
|
desc 'validate:image SECTESTNAME', 'Validate SECTESTNAME manifest.yml and readme.md'
|
284
292
|
define_method 'validate:image' do |name|
|
285
293
|
run_validations(name)
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module NoradCli
|
6
|
+
class UiSeedGenerator
|
7
|
+
REQUIRED_ATTRIBUTES = %w[name prog_args test_types].freeze
|
8
|
+
OPTIONAL_ATTRIBUTES = %w[category multi_host configurable help_url default_config service].freeze
|
9
|
+
ALLOWED_ATTRIBUTES = REQUIRED_ATTRIBUTES | OPTIONAL_ATTRIBUTES
|
10
|
+
|
11
|
+
def initialize(manifest_paths)
|
12
|
+
@manifest_paths = if manifest_paths.empty?
|
13
|
+
Dir.glob('./**/manifest.yml')
|
14
|
+
else
|
15
|
+
manifest_paths
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def process!
|
20
|
+
configurations = []
|
21
|
+
@manifest_paths.each { |manifest_path| configurations << configuration_from_manifest(manifest_path) }
|
22
|
+
save_seed_file!(configurations)
|
23
|
+
rescue ManifestError => e
|
24
|
+
puts e.message
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def seed_path
|
30
|
+
"#{Dir.pwd}/seed.yml"
|
31
|
+
end
|
32
|
+
|
33
|
+
def save_seed_file!(configurations)
|
34
|
+
File.open(seed_path, 'w') { |f| f.write YAML.dump(configurations) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def configuration_from_manifest(manifest_path)
|
38
|
+
raise ManifestNotFoundError, manifest_path unless File.exist?(manifest_path)
|
39
|
+
|
40
|
+
seed = YAML.safe_load(File.read(manifest_path))
|
41
|
+
validate_seed(manifest_path, seed)
|
42
|
+
seed['name'] = seed['version'] ? "#{seed['name']}:#{seed['version']}" : seed['name']
|
43
|
+
|
44
|
+
sanitize_seed(seed)
|
45
|
+
end
|
46
|
+
|
47
|
+
def sanitize_seed(seed)
|
48
|
+
seed.each_key { |key| seed.delete(key) unless ALLOWED_ATTRIBUTES.include?(key) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def validate_seed(manifest_path, seed)
|
52
|
+
raise InvalidManifestError, manifest_path unless seed.is_a?(Hash)
|
53
|
+
return if REQUIRED_ATTRIBUTES & seed.keys == REQUIRED_ATTRIBUTES
|
54
|
+
raise ManifestMissingAttributesError.new(manifest_path, REQUIRED_ATTRIBUTES - seed.keys)
|
55
|
+
end
|
56
|
+
|
57
|
+
class ManifestError < StandardError
|
58
|
+
attr_reader :manifest_path
|
59
|
+
|
60
|
+
def initialize(manifest_path)
|
61
|
+
@manifest_path = manifest_path
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class ManifestNotFoundError < ManifestError
|
66
|
+
def message
|
67
|
+
"Could not find manifest provided: #{manifest_path}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class ManifestMissingAttributesError < ManifestError
|
72
|
+
attr_reader :attributes
|
73
|
+
|
74
|
+
def initialize(manifest_path, attributes)
|
75
|
+
@manifest_path = manifest_path
|
76
|
+
@attributes = attributes
|
77
|
+
end
|
78
|
+
|
79
|
+
def message
|
80
|
+
"Invalid manifest: #{manifest_path}. Missing attributes: #{attributes.join(', ')}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class InvalidManifestError < ManifestError
|
85
|
+
def message
|
86
|
+
"Invalid manifest: #{manifest_path}. See Norad security test repositories page for guidelines."
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/norad_cli/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Hitchcock
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-01-
|
13
|
+
date: 2018-01-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: docker-api
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- lib/norad_cli/support/readme_spec.rb
|
201
201
|
- lib/norad_cli/support/results_server.rb
|
202
202
|
- lib/norad_cli/support/sectest_container.rb
|
203
|
+
- lib/norad_cli/support/ui_seed_generator.rb
|
203
204
|
- lib/norad_cli/templates/.gitignore
|
204
205
|
- lib/norad_cli/templates/.rspec
|
205
206
|
- lib/norad_cli/templates/CONTRIBUTING.md
|