Class: Options

Inherits:
Object show all
Defined in:
lib/cfn-nag/cli_options.rb

Overview

rubocop:disable Metrics/ClassLength

Class Method Summary collapse

Class Method Details

.file_optionsObject

rubocop:disable Metrics/BlockLength rubocop:disable Metrics/MethodLength



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cfn-nag/cli_options.rb', line 26

def self.file_options
  options_message = '[options] <cloudformation template path ...>|' \
                      '<cloudformation template in STDIN>'
  custom_rule_exceptions_message = @custom_rule_exceptions_message
  version = @version

  Optimist.options do
    usage options_message
    version version

    opt :debug,
        'Enable debug output',
        type: :boolean,
        required: false,
        default: false
    opt :allow_suppression,
        'Allow using Metadata to suppress violations',
        type: :boolean,
        required: false,
        default: true
    opt :print_suppression,
        'Emit suppressions to stderr',
        type: :boolean,
        required: false,
        default: false
    opt :rule_directory,
        'Extra rule directory',
        type: :string,
        required: false,
        default: nil
    opt :profile_path,
        'Path to a profile file',
        type: :string,
        required: false,
        default: nil
    opt :blacklist_path,
        'Path to a blacklist file',
        type: :string,
        required: false,
        default: nil
    opt :parameter_values_path,
        'Path to a JSON file to pull Parameter values from',
        type: :string,
        required: false,
        default: nil
    opt :condition_values_path,
        'Path to a JSON file to pull Condition values from',
        type: :string,
        required: false,
        default: nil
    opt :isolate_custom_rule_exceptions,
        custom_rule_exceptions_message,
        type: :boolean,
        required: false,
        default: false
    opt :fail_on_warnings,
        'Treat warnings as failing violations',
        type: :boolean,
        required: false,
        default: false
    opt :output_format,
        'Format of results: [txt, json, colortxt]',
        type: :string,
        default: 'colortxt'
    opt :rule_repository,
        'Path(s) to a rule repository to include in rule discovery',
        type: :strings,
        required: false
    opt :rule_arguments,
        'Rule arguments to inject into interested rules',
        type: :strings,
        required: false
    opt :rule_arguments_path,
        'Path to a rule arguments to inject into interested rules',
        type: :string,
        required: false,
        default: nil
    opt :ignore_fatal,
        'Ignore files with fatal violations.  Useful for ignoring non-Cloudformation yaml/yml/json in a path',
        type: :boolean,
        required: false,
        default: false
  end
end

.for(type) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/cfn-nag/cli_options.rb', line 13

def self.for(type)
  case type
  when 'file'
    file_options
  when 'scan'
    scan_options
  else
    raise "Unsupported Options type #{type}; use 'file' or 'scan'"
  end
end

.scan_optionsObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/cfn-nag/cli_options.rb', line 111

def self.scan_options
  input_path_message = 'CloudFormation template to nag on or directory of ' \
                       'templates.  Default is all *.json, *.yaml, *.yml ' \
                       'and *.template recursively, but can be constrained ' \
                       'by --template-pattern'

  template_pattern_message = 'Within the --input-path, match files to scan ' \
                             'against this regular expression'

  custom_rule_exceptions_message = @custom_rule_exceptions_message
  version = @version

  Optimist.options do
    version version
    opt :input_path,
        input_path_message,
        type: :string,
        required: true
    opt :output_format,
        'Format of results: [txt, json, colortxt]',
        type: :string,
        default: 'colortxt'
    opt :debug,
        'Enable debug output',
        type: :boolean,
        required: false,
        default: false
    opt :rule_directory,
        'Extra rule directory',
        type: :string,
        required: false,
        default: nil
    opt :profile_path,
        'Path to a profile file',
        type: :string,
        required: false,
        default: nil
    opt :blacklist_path,
        'Path to a blacklist file',
        type: :string,
        required: false,
        default: nil
    opt :parameter_values_path,
        'Path to a JSON file to pull Parameter values from',
        type: :string,
        required: false,
        default: nil
    opt :condition_values_path,
        'Path to a JSON file to pull Condition values from',
        type: :string,
        required: false,
        default: nil
    opt :allow_suppression,
        'Allow using Metadata to suppress violations',
        type: :boolean,
        required: false,
        default: true
    opt :print_suppression,
        'Emit suppressions to stderr',
        type: :boolean,
        required: false,
        default: false
    opt :isolate_custom_rule_exceptions,
        custom_rule_exceptions_message,
        type: :boolean,
        required: false,
        default: false
    opt :template_pattern,
        template_pattern_message,
        type: :string,
        required: false,
        default: '..*\.json|..*\.yaml|..*\.yml|..*\.template'
    opt :fail_on_warnings,
        'Treat warnings as failing violations',
        type: :boolean,
        required: false,
        default: false
    opt :rule_repository,
        'Path(s)s to rule repository to include in rule discovery',
        type: :strings,
        required: false
    opt :rule_arguments,
        'Rule arguments to inject into interested rules',
        type: :strings,
        required: false
    opt :rule_arguments_path,
        'Path to a rule arguments to inject into interested rules',
        type: :string,
        required: false,
        default: nil
    opt :ignore_fatal,
        'Ignore files with fatal violations.  Useful for ignoring non-Cloudformation yaml/yml/json in a path',
        short: 'g',
        type: :boolean,
        required: false,
        default: false
  end
end