abide_dev_utils 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/abide_dev_utils.gemspec +1 -1
- data/lib/abide_dev_utils.rb +4 -3
- data/lib/abide_dev_utils/cli/abstract.rb +16 -0
- data/lib/abide_dev_utils/cli/jira.rb +3 -1
- data/lib/abide_dev_utils/cli/puppet.rb +57 -10
- data/lib/abide_dev_utils/errors.rb +2 -0
- data/lib/abide_dev_utils/errors/ppt.rb +29 -0
- data/lib/abide_dev_utils/jira.rb +1 -1
- data/lib/abide_dev_utils/ppt.rb +5 -74
- data/lib/abide_dev_utils/ppt/coverage.rb +81 -0
- data/lib/abide_dev_utils/ppt/new_obj.rb +114 -0
- data/lib/abide_dev_utils/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75678bc1c177a3187619cfec9d2c25e566b08d91439c3b46c578c4202f4d9a7c
|
4
|
+
data.tar.gz: f9749e6c8ad3d5b0439a8fe0fd03ba3ea91e5c0052057eea43b3862c08b45fbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ba4b3b0898a40ed6df3facaf3aa03beb2d1375d61e1915c6566e107e6edffa083ab7af93827c2679c14a2503504cafd40d9275b12708f582c3723953b5c9c7
|
7
|
+
data.tar.gz: 2680eb354112e27223d590a645318ea14c4988dd0e331bf5a5f3b347402ead6398c8c07c1b7ded55704d76011522ff790459cf40452ceba8ca15dc2a19a76a7a
|
data/abide_dev_utils.gemspec
CHANGED
@@ -49,7 +49,7 @@ Gem::Specification.new do |spec|
|
|
49
49
|
spec.add_development_dependency 'rubocop-ast', '~> 1.4'
|
50
50
|
spec.add_development_dependency 'rubocop-performance', '~> 1.9'
|
51
51
|
spec.add_development_dependency 'rubocop-i18n', '~> 3.0'
|
52
|
-
spec.add_development_dependency 'fast_gettext', '~> 1.
|
52
|
+
spec.add_development_dependency 'fast_gettext', '~> 1.8'
|
53
53
|
|
54
54
|
# For more information and examples about making a new gem, checkout our
|
55
55
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/lib/abide_dev_utils.rb
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'abide_dev_utils/version'
|
4
4
|
require 'abide_dev_utils/xccdf'
|
5
|
-
require 'abide_dev_utils/
|
6
|
-
require 'abide_dev_utils/
|
5
|
+
require 'abide_dev_utils/ppt'
|
6
|
+
require 'abide_dev_utils/jira'
|
7
|
+
require 'abide_dev_utils/config'
|
7
8
|
|
8
|
-
#
|
9
|
+
# Root namespace all modules / classes
|
9
10
|
module AbideDevUtils; end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Abide
|
4
|
+
module CLI
|
5
|
+
# @abstract
|
6
|
+
class Command < CmdParse::Command
|
7
|
+
include AbideDevUtils::Config
|
8
|
+
def initialize(cmd_name, cmd_short, cmd_long, **opts)
|
9
|
+
super(cmd_name, **opts)
|
10
|
+
short_desc(cmd_short)
|
11
|
+
long_desc(cmd_long)
|
12
|
+
add_command(CmdParse::HelpCommand.new, default: true) if opts[:takes_commands]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -36,7 +36,9 @@ module Abide
|
|
36
36
|
def execute
|
37
37
|
client = JIRA.client
|
38
38
|
myself = JIRA.get_myself(client)
|
39
|
-
|
39
|
+
return if myself.attrs['name'].empty?
|
40
|
+
|
41
|
+
Abide::CLI::OUTPUT.simple("Successfully authenticated user #{myself.attrs['name']}!")
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
@@ -1,30 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'abide_dev_utils/cli/abstract'
|
4
|
+
|
3
5
|
module Abide
|
4
6
|
module CLI
|
5
|
-
class PuppetCommand <
|
7
|
+
class PuppetCommand < Command
|
6
8
|
CMD_NAME = 'puppet'
|
7
9
|
CMD_SHORT = 'Commands related to Puppet code'
|
8
10
|
CMD_LONG = 'Namespace for commands related to Puppet code'
|
9
11
|
def initialize
|
10
|
-
super(CMD_NAME, takes_commands: true)
|
11
|
-
short_desc(CMD_SHORT)
|
12
|
-
long_desc(CMD_LONG)
|
13
|
-
add_command(CmdParse::HelpCommand.new, default: true)
|
12
|
+
super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: true)
|
14
13
|
add_command(PuppetCoverageCommand.new)
|
14
|
+
add_command(PuppetNewCommand.new)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
class PuppetCoverageCommand <
|
18
|
+
class PuppetCoverageCommand < Command
|
19
19
|
CMD_NAME = 'coverage'
|
20
20
|
CMD_SHORT = 'Generates control coverage report'
|
21
21
|
CMD_LONG = 'Generates report of valid Puppet classes that match with Hiera controls'
|
22
22
|
CMD_CLASS_DIR = 'Directory that holds Puppet manifests'
|
23
23
|
CMD_HIERA_FILE = 'Hiera file generated from an XCCDF'
|
24
24
|
def initialize
|
25
|
-
super(CMD_NAME, takes_commands: false)
|
26
|
-
short_desc(CMD_SHORT)
|
27
|
-
long_desc(CMD_LONG)
|
25
|
+
super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
|
28
26
|
argument_desc(CLASS_DIR: CMD_CLASS_DIR, HIERA_FILE: CMD_HIERA_FILE)
|
29
27
|
options.on('-o [FILE]', '--out-file [FILE]', 'Path to save the coverage report') { |f| @data[:file] = f }
|
30
28
|
options.on('-p [PROFILE]', '--profile [PROFILE]', 'Generate only for profile') { |p| @data[:profile] = p }
|
@@ -43,7 +41,7 @@ module Abide
|
|
43
41
|
require 'abide_dev_utils/ppt'
|
44
42
|
Abide::CLI::VALIDATE.directory(class_dir)
|
45
43
|
Abide::CLI::VALIDATE.file(hiera_file)
|
46
|
-
coverage = AbideDevUtils::Ppt.
|
44
|
+
coverage = AbideDevUtils::Ppt::CoverageReport.generate(class_dir, hiera_file, @data[:profile])
|
47
45
|
coverage.each do |k, v|
|
48
46
|
next if ['classes', 'benchmark'].include?(k)
|
49
47
|
|
@@ -54,5 +52,54 @@ module Abide
|
|
54
52
|
Abide::CLI::OUTPUT.json(coverage, file: @data[:file])
|
55
53
|
end
|
56
54
|
end
|
55
|
+
|
56
|
+
class PuppetNewCommand < Command
|
57
|
+
CMD_NAME = 'new'
|
58
|
+
CMD_SHORT = 'Generates a new Puppet object from templates'
|
59
|
+
CMD_LONG = 'Generates a new Puppet object (class, test, etc.) from templates stored in the module repo'
|
60
|
+
CMD_TYPE_ARG = 'The type of object to generate. This value must be the name of a template (without .erb) file in <template dir>'
|
61
|
+
CMD_NAME_ARG = 'The fully namespaced name of the new object'
|
62
|
+
def initialize
|
63
|
+
super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
|
64
|
+
argument_desc(TYPE: CMD_TYPE_ARG, NAME: CMD_NAME_ARG)
|
65
|
+
options.on(
|
66
|
+
'-t [DIR]',
|
67
|
+
'--template-dir [DIR]',
|
68
|
+
'Path to the directory holding your ERB templates for custom objects. Defaults to "object_templates" in the root dir.'
|
69
|
+
) { |t| @data[:tmpl_dir] = t }
|
70
|
+
options.on(
|
71
|
+
'-r [DIR]',
|
72
|
+
'--root-dir [DIR]',
|
73
|
+
'Path to the root directory of the module. Defaults to the current working directory.'
|
74
|
+
) { |r| @data[:root_dir] = r }
|
75
|
+
options.on(
|
76
|
+
'-A',
|
77
|
+
'--absolute-template-dir',
|
78
|
+
'Use this flage if the template dir is an absolute path'
|
79
|
+
) { |a| @data[:absolute_template_dir] = a }
|
80
|
+
options.on(
|
81
|
+
'-n [NAME]',
|
82
|
+
'--template-name [NAME]',
|
83
|
+
'Allows you to specify a name for the template if it is different from the basename (last segment) of the object name.'
|
84
|
+
)
|
85
|
+
options.on(
|
86
|
+
'-V [VARNAME=VALUE]',
|
87
|
+
'--vars [VARNAME=VALUE]',
|
88
|
+
'Allows you to specify comma-separated variable names and values that will be converted into a hash that is available for you to use in your templates'
|
89
|
+
) { |v| @data[:vars] = v }
|
90
|
+
end
|
91
|
+
|
92
|
+
def execute(type, name)
|
93
|
+
require 'abide_dev_utils/ppt/new_obj'
|
94
|
+
builder = AbideDevUtils::Ppt::NewObjectBuilder.new(
|
95
|
+
type,
|
96
|
+
name,
|
97
|
+
opts: @data,
|
98
|
+
vars: @data.fetch(:vars, '').split(',').map { |i| i.split('=') }.to_h # makes the str a hash
|
99
|
+
)
|
100
|
+
result = builder.build
|
101
|
+
Abide::CLI::OUTPUT.simple(result)
|
102
|
+
end
|
103
|
+
end
|
57
104
|
end
|
58
105
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'abide_dev_utils/errors/base'
|
4
|
+
|
5
|
+
module AbideDevUtils
|
6
|
+
module Errors
|
7
|
+
module Ppt
|
8
|
+
class ObjClassPathError < GenericError
|
9
|
+
@default = 'Invalid path for class:'
|
10
|
+
end
|
11
|
+
|
12
|
+
class CustomObjPathKeyError < GenericError
|
13
|
+
@default = 'Custom Object value hash does not have :path key: '
|
14
|
+
end
|
15
|
+
|
16
|
+
class CustomObjNotFoundError < GenericError
|
17
|
+
@default = 'Could not find custom object in map:'
|
18
|
+
end
|
19
|
+
|
20
|
+
class TemplateNotFoundError < GenericError
|
21
|
+
@default = 'Template does not exist at:'
|
22
|
+
end
|
23
|
+
|
24
|
+
class FailedToCreateFileError < GenericError
|
25
|
+
@default = 'Failed to create file:'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/abide_dev_utils/jira.rb
CHANGED
@@ -148,7 +148,7 @@ module AbideDevUtils
|
|
148
148
|
false
|
149
149
|
end
|
150
150
|
|
151
|
-
def self.summaries_from_coverage_report(report)
|
151
|
+
def self.summaries_from_coverage_report(report) # rubocop:disable Metrics/CyclomaticComplexity
|
152
152
|
summaries = {}
|
153
153
|
benchmark = nil
|
154
154
|
report.each do |k, v|
|
data/lib/abide_dev_utils/ppt.rb
CHANGED
@@ -1,57 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require 'yaml'
|
6
|
-
require 'puppet_pal'
|
3
|
+
require 'abide_dev_utils/ppt/coverage'
|
4
|
+
require 'abide_dev_utils/ppt/new_obj'
|
7
5
|
|
8
6
|
module AbideDevUtils
|
9
7
|
module Ppt
|
10
|
-
def self.coverage_report(puppet_class_dir, hiera_path, profile = nil)
|
11
|
-
coverage = {}
|
12
|
-
coverage['classes'] = {}
|
13
|
-
all_cap = find_all_classes_and_paths(puppet_class_dir)
|
14
|
-
invalid_classes = find_invalid_classes(all_cap)
|
15
|
-
valid_classes = all_cap.dup.transpose[0] - invalid_classes
|
16
|
-
coverage['classes']['invalid'] = invalid_classes
|
17
|
-
coverage['classes']['valid'] = valid_classes
|
18
|
-
hiera = YAML.safe_load(File.open(hiera_path))
|
19
|
-
matcher = profile.nil? ? /^profile_/ : /^profile_#{profile}/
|
20
|
-
hiera.each do |k, v|
|
21
|
-
key_base = k.split('::')[-1]
|
22
|
-
coverage['benchmark'] = v if key_base == 'title'
|
23
|
-
next unless key_base.match?(matcher)
|
24
|
-
|
25
|
-
coverage[key_base] = generate_uncovered_data(v, valid_classes)
|
26
|
-
end
|
27
|
-
coverage
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.generate_uncovered_data(ctrl_list, valid_classes)
|
31
|
-
out_hash = {}
|
32
|
-
out_hash[:num_total] = ctrl_list.length
|
33
|
-
out_hash[:uncovered] = []
|
34
|
-
out_hash[:covered] = []
|
35
|
-
ctrl_list.each do |c|
|
36
|
-
if valid_classes.include?(c)
|
37
|
-
out_hash[:covered] << c
|
38
|
-
else
|
39
|
-
out_hash[:uncovered] << c
|
40
|
-
end
|
41
|
-
end
|
42
|
-
out_hash[:num_covered] = out_hash[:covered].length
|
43
|
-
out_hash[:num_uncovered] = out_hash[:uncovered].length
|
44
|
-
out_hash[:coverage] = Float(
|
45
|
-
(Float(out_hash[:num_covered]) / Float(out_hash[:num_total])) * 100.0
|
46
|
-
).floor(3)
|
47
|
-
out_hash
|
48
|
-
end
|
49
|
-
|
50
8
|
# Given a directory holding Puppet manifests, returns
|
51
9
|
# the full namespace for all classes in that directory.
|
52
10
|
# @param puppet_class_dir [String] path to a dir containing Puppet manifests
|
53
11
|
# @return [String] The namespace for all classes in manifests in the dir
|
54
|
-
def
|
12
|
+
def find_class_namespace(puppet_class_dir)
|
55
13
|
path = Pathname.new(puppet_class_dir)
|
56
14
|
mod_root = nil
|
57
15
|
ns_parts = []
|
@@ -76,7 +34,7 @@ module AbideDevUtils
|
|
76
34
|
# metadata.json, if it exists, or by using the parent directory name.
|
77
35
|
# @param pathname [Pathname] A Pathname object of the module's manifests dir
|
78
36
|
# @return [String] The module's namespace root
|
79
|
-
def
|
37
|
+
def find_mod_root(pathname)
|
80
38
|
metadata_file = nil
|
81
39
|
pathname.entries.each do |e|
|
82
40
|
metadata_file = "#{pathname}/metadata.json" if File.basename(e) == 'metadata.json'
|
@@ -94,7 +52,7 @@ module AbideDevUtils
|
|
94
52
|
|
95
53
|
# @return [Array] An array of frozen arrays where each sub-array's
|
96
54
|
# index 0 is class_name and index 1 is the full path to the file.
|
97
|
-
def
|
55
|
+
def find_all_classes_and_paths(puppet_class_dir)
|
98
56
|
all_cap = []
|
99
57
|
Dir.each_child(puppet_class_dir) do |c|
|
100
58
|
path = "#{puppet_class_dir}/#{c}"
|
@@ -104,32 +62,5 @@ module AbideDevUtils
|
|
104
62
|
end
|
105
63
|
all_cap
|
106
64
|
end
|
107
|
-
|
108
|
-
def self.find_valid_classes(all_cap)
|
109
|
-
all_classes = all_cap.dup.transpose[0]
|
110
|
-
all_classes - find_invalid_classes(all_cap)
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.find_invalid_classes(all_cap)
|
114
|
-
invalid_classes = []
|
115
|
-
all_cap.each do |cap|
|
116
|
-
invalid_classes << cap[0] unless class_valid?(cap[1])
|
117
|
-
end
|
118
|
-
invalid_classes
|
119
|
-
end
|
120
|
-
|
121
|
-
def self.class_valid?(manifest_path)
|
122
|
-
compiler = Puppet::Pal::Compiler.new(nil)
|
123
|
-
ast = compiler.parse_file(manifest_path)
|
124
|
-
ast.body.body.statements.each do |s|
|
125
|
-
next unless s.respond_to?(:arguments)
|
126
|
-
next unless s.arguments.respond_to?(:each)
|
127
|
-
|
128
|
-
s.arguments.each do |i|
|
129
|
-
return false if i.value == 'Not implemented'
|
130
|
-
end
|
131
|
-
end
|
132
|
-
true
|
133
|
-
end
|
134
65
|
end
|
135
66
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'pathname'
|
5
|
+
require 'yaml'
|
6
|
+
require 'puppet_pal'
|
7
|
+
require 'abide_dev_utils/ppt'
|
8
|
+
|
9
|
+
module AbideDevUtils
|
10
|
+
module Ppt
|
11
|
+
class CoverageReport
|
12
|
+
include AbideDevUtils::Ppt
|
13
|
+
def self.generate(puppet_class_dir, hiera_path, profile = nil)
|
14
|
+
coverage = {}
|
15
|
+
coverage['classes'] = {}
|
16
|
+
all_cap = find_all_classes_and_paths(puppet_class_dir)
|
17
|
+
invalid_classes = find_invalid_classes(all_cap)
|
18
|
+
valid_classes = all_cap.dup.transpose[0] - invalid_classes
|
19
|
+
coverage['classes']['invalid'] = invalid_classes
|
20
|
+
coverage['classes']['valid'] = valid_classes
|
21
|
+
hiera = YAML.safe_load(File.open(hiera_path))
|
22
|
+
matcher = profile.nil? ? /^profile_/ : /^profile_#{profile}/
|
23
|
+
hiera.each do |k, v|
|
24
|
+
key_base = k.split('::')[-1]
|
25
|
+
coverage['benchmark'] = v if key_base == 'title'
|
26
|
+
next unless key_base.match?(matcher)
|
27
|
+
|
28
|
+
coverage[key_base] = generate_uncovered_data(v, valid_classes)
|
29
|
+
end
|
30
|
+
coverage
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.generate_uncovered_data(ctrl_list, valid_classes)
|
34
|
+
out_hash = {}
|
35
|
+
out_hash[:num_total] = ctrl_list.length
|
36
|
+
out_hash[:uncovered] = []
|
37
|
+
out_hash[:covered] = []
|
38
|
+
ctrl_list.each do |c|
|
39
|
+
if valid_classes.include?(c)
|
40
|
+
out_hash[:covered] << c
|
41
|
+
else
|
42
|
+
out_hash[:uncovered] << c
|
43
|
+
end
|
44
|
+
end
|
45
|
+
out_hash[:num_covered] = out_hash[:covered].length
|
46
|
+
out_hash[:num_uncovered] = out_hash[:uncovered].length
|
47
|
+
out_hash[:coverage] = Float(
|
48
|
+
(Float(out_hash[:num_covered]) / Float(out_hash[:num_total])) * 100.0
|
49
|
+
).floor(3)
|
50
|
+
out_hash
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.find_valid_classes(all_cap)
|
54
|
+
all_classes = all_cap.dup.transpose[0]
|
55
|
+
all_classes - find_invalid_classes(all_cap)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.find_invalid_classes(all_cap)
|
59
|
+
invalid_classes = []
|
60
|
+
all_cap.each do |cap|
|
61
|
+
invalid_classes << cap[0] unless class_valid?(cap[1])
|
62
|
+
end
|
63
|
+
invalid_classes
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.class_valid?(manifest_path)
|
67
|
+
compiler = Puppet::Pal::Compiler.new(nil)
|
68
|
+
ast = compiler.parse_file(manifest_path)
|
69
|
+
ast.body.body.statements.each do |s|
|
70
|
+
next unless s.respond_to?(:arguments)
|
71
|
+
next unless s.arguments.respond_to?(:each)
|
72
|
+
|
73
|
+
s.arguments.each do |i|
|
74
|
+
return false if i.value == 'Not implemented'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'pathname'
|
5
|
+
require 'abide_dev_utils/prompt'
|
6
|
+
require 'abide_dev_utils/errors/ppt'
|
7
|
+
|
8
|
+
module AbideDevUtils
|
9
|
+
module Ppt
|
10
|
+
class NewObjectBuilder
|
11
|
+
DEFAULT_EXT = '.pp'
|
12
|
+
|
13
|
+
def initialize(obj_type, obj_name, opts: {}, vars: {})
|
14
|
+
@obj_type = obj_type
|
15
|
+
@obj_name = obj_name.split(':').reject(&:empty?).join('::') # removes
|
16
|
+
@obj_basename = obj_name.split('::')[-1]
|
17
|
+
@root_dir = Pathname.new(opts.fetch(:root_dir, Dir.pwd))
|
18
|
+
@tmpl_dir = if opts.fetch(:absolute_template_dir, false)
|
19
|
+
opts.fetch(:tmpl_dir)
|
20
|
+
else
|
21
|
+
"#{@root_dir}/#{opts.fetch(:tmpl_dir, 'object_templates')}"
|
22
|
+
end
|
23
|
+
@tmpl_name = opts.fetch(:tmpl_name, "#{@obj_type}.erb")
|
24
|
+
@tmpl_path = Pathname.new("#{@tmpl_dir}/#{@tmpl_name}")
|
25
|
+
@type_path_map = opts.fetch(:type_path_map, {})
|
26
|
+
@vars = vars
|
27
|
+
end
|
28
|
+
|
29
|
+
def obj_path
|
30
|
+
case @obj_type
|
31
|
+
when 'class'
|
32
|
+
obj_path_from_name
|
33
|
+
else
|
34
|
+
custom_obj_path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def template?
|
39
|
+
@tmpl_path.file?
|
40
|
+
end
|
41
|
+
|
42
|
+
def render
|
43
|
+
raise AbideDevUtils::Errors::Ppt::TemplateNotFoundError, @tmpl_path.to_s unless template?
|
44
|
+
|
45
|
+
ERB.new(File.read(@tmpl_path.to_s), 0, '<>-').result(binding)
|
46
|
+
end
|
47
|
+
|
48
|
+
def build
|
49
|
+
continue = File.exist?(obj_path) ? AbideDevUtils::Prompt.yes_no('File exists, would you like to overwrite?') : true
|
50
|
+
return "Not overwriting file #{obj_path}" unless continue
|
51
|
+
|
52
|
+
dir, = Pathname.new(obj_path).split
|
53
|
+
Pathname.new(dir).mkpath unless Dir.exist?(dir)
|
54
|
+
content = render
|
55
|
+
File.open(obj_path, 'w') { |f| f.write(render) } unless content.empty?
|
56
|
+
raise AbideDevUtils::Errors::Ppt::FailedToCreateFileError, obj_path unless File.file?(obj_path)
|
57
|
+
|
58
|
+
"Created file #{obj_path}"
|
59
|
+
end
|
60
|
+
|
61
|
+
# If a method gets called on the Hiera object which is not defined,
|
62
|
+
# this sends that method call to hash, then doc, then super.
|
63
|
+
def method_missing(method, *args, &block)
|
64
|
+
return true if ['exist?', 'exists?'].include?(method.to_s)
|
65
|
+
|
66
|
+
return @hash.send(method, *args, &block) if @hash.respond_to?(method)
|
67
|
+
|
68
|
+
return @doc.send(method, *args, &block) if @doc.respond_to?(method)
|
69
|
+
|
70
|
+
super(method, *args, &block)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Checks the respond_to? of hash, doc, or super
|
74
|
+
def respond_to_missing?(method_name, include_private = false)
|
75
|
+
return true if ['exist?', 'exists?'].include?(method_name.to_s)
|
76
|
+
|
77
|
+
@hash || @doc || super
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def obj_path_from_name
|
83
|
+
parts = @obj_name.split('::')[1..-2]
|
84
|
+
parts.insert(0, 'manifests')
|
85
|
+
parts.insert(-1, "#{@obj_basename}#{DEFAULT_EXT}")
|
86
|
+
path = @root_dir + Pathname.new(parts.join('/'))
|
87
|
+
path.to_s
|
88
|
+
end
|
89
|
+
|
90
|
+
def custom_obj_path
|
91
|
+
map_val = @type_path_map.fetch(@obj_type.to_sym, nil)
|
92
|
+
return obj_path_from_name if map_val.nil?
|
93
|
+
|
94
|
+
if map_val.respond_to?(:key?)
|
95
|
+
custom_obj_path_from_hash(map_val)
|
96
|
+
else
|
97
|
+
abs_path = Pathname.new(map_val).absolute? ? map_val : "#{Dir.pwd}/#{map_val}"
|
98
|
+
"#{abs_path}/#{@obj_basename}#{DEFAULT_EXT}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def custom_obj_path_from_hash(map_val)
|
103
|
+
raise AbideDevUtils::Errors::Ppt::CustomObjPathKeyError, map_val unless map_val.key?(:path)
|
104
|
+
|
105
|
+
abs_path = Pathname.new(map_val[:path]).absolute? ? map_val[:path] : "#{Dir.pwd}/#{map_val[:path]}"
|
106
|
+
if map_val.key?(:extension)
|
107
|
+
"#{abs_path}/#{@obj_basename}#{map_val[:extension]}"
|
108
|
+
else
|
109
|
+
"#{abs_path}/#{@obj_basename}#{DEFAULT_EXT}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abide_dev_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Heston Snodgrass
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -226,14 +226,14 @@ dependencies:
|
|
226
226
|
requirements:
|
227
227
|
- - "~>"
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version: '1.
|
229
|
+
version: '1.8'
|
230
230
|
type: :development
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
234
|
- - "~>"
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: '1.
|
236
|
+
version: '1.8'
|
237
237
|
description: Provides a CLI with helpful utilities for developing Abide
|
238
238
|
email:
|
239
239
|
- hsnodgrass3@gmail.com
|
@@ -258,6 +258,7 @@ files:
|
|
258
258
|
- exe/abide
|
259
259
|
- lib/abide_dev_utils.rb
|
260
260
|
- lib/abide_dev_utils/cli.rb
|
261
|
+
- lib/abide_dev_utils/cli/abstract.rb
|
261
262
|
- lib/abide_dev_utils/cli/jira.rb
|
262
263
|
- lib/abide_dev_utils/cli/puppet.rb
|
263
264
|
- lib/abide_dev_utils/cli/test.rb
|
@@ -268,11 +269,14 @@ files:
|
|
268
269
|
- lib/abide_dev_utils/errors/base.rb
|
269
270
|
- lib/abide_dev_utils/errors/general.rb
|
270
271
|
- lib/abide_dev_utils/errors/jira.rb
|
272
|
+
- lib/abide_dev_utils/errors/ppt.rb
|
271
273
|
- lib/abide_dev_utils/errors/xccdf.rb
|
272
274
|
- lib/abide_dev_utils/files.rb
|
273
275
|
- lib/abide_dev_utils/jira.rb
|
274
276
|
- lib/abide_dev_utils/output.rb
|
275
277
|
- lib/abide_dev_utils/ppt.rb
|
278
|
+
- lib/abide_dev_utils/ppt/coverage.rb
|
279
|
+
- lib/abide_dev_utils/ppt/new_obj.rb
|
276
280
|
- lib/abide_dev_utils/prompt.rb
|
277
281
|
- lib/abide_dev_utils/utils/general.rb
|
278
282
|
- lib/abide_dev_utils/validate.rb
|