a2 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ab4e4782cc17d7bdd25d29feda56c81d4dbff2e911f19e9d723f5ecf66801f7
4
- data.tar.gz: 4993432169fd2305698ee7f1106b0b2a83576eef287ac7065d2543ed38b1cae4
3
+ metadata.gz: dc54ef0fc44adbd3b8e6fa6f6586dd100c2c536aa13ebf545de3fcab41424a3b
4
+ data.tar.gz: 5aaa16dae692a671ff1a76b6ec56335fcbac34c46f3753e7743e602c1f8292ab
5
5
  SHA512:
6
- metadata.gz: 5cdab720df6fc757d7392598e2ddefed1dfe0883013aca3eb63c95b9b8644ea02de60967b751758c73b312da36d2280ee758a1ae6cbbd92ba9a109ae9d1086ed
7
- data.tar.gz: e61c4e157f94ff5aca7f69808967cafa12c487bb0978af6726b6772e71d69774791e04c4b04c512ab31857faa15fcca510e645cfc8f3b1d81f6a33b2f2894e3b
6
+ metadata.gz: f8bf300517f1f6690d5000042b7cbc175666c9d84527a8f81d1750afb4de4248fb0e9add7fffc4da17e15dcf8991332a8be8176de5113796a96d095ca2ee71fa
7
+ data.tar.gz: 76bd17a096f75021a71733624200d2b4e2ce24ff515dceff8fc681b5f91a1e007a794243e18606dea463322cfe657d621a87b85427c5cdcb64095f1f43093551
data/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased](https://github.com/gscho/a2-cli/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/gscho/a2-cli/compare/v0.2.0...HEAD)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Add some basic unit tests for approved and filtered mixins [\#2](https://github.com/gscho/a2-cli/pull/2) ([gscho](https://github.com/gscho))
10
+ - Release v0.2.0 [\#1](https://github.com/gscho/a2-cli/pull/1) ([gscho](https://github.com/gscho))
11
+
12
+ ## [v0.2.0](https://github.com/gscho/a2-cli/tree/v0.2.0) (2021-04-07)
13
+
14
+ [Full Changelog](https://github.com/gscho/a2-cli/compare/v0.1.1...v0.2.0)
15
+
16
+ ## [v0.1.1](https://github.com/gscho/a2-cli/tree/v0.1.1) (2021-03-24)
17
+
18
+ [Full Changelog](https://github.com/gscho/a2-cli/compare/v0.1.0...v0.1.1)
19
+
20
+ ## [v0.1.0](https://github.com/gscho/a2-cli/tree/v0.1.0) (2021-03-23)
21
+
22
+ [Full Changelog](https://github.com/gscho/a2-cli/compare/783f8a6384a480f7b165ef5645aa1e8e4c4dfb45...v0.1.0)
23
+
24
+
25
+
26
+ \* *This Changelog was automatically generated by [github_changelog_generator] (https://github.com/github-changelog-generator/github-changelog-generator)*
data/Gemfile CHANGED
@@ -2,5 +2,4 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
- # Specify your gem's dependencies in a2.gemspec
6
5
  gemspec
data/Gemfile.lock CHANGED
@@ -8,16 +8,86 @@ PATH
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ activesupport (6.0.3.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
17
+ addressable (2.7.0)
18
+ public_suffix (>= 2.0.2, < 5.0)
19
+ async (1.28.9)
20
+ console (~> 1.10)
21
+ nio4r (~> 2.3)
22
+ timers (~> 4.1)
23
+ async-http (0.54.1)
24
+ async (~> 1.25)
25
+ async-io (~> 1.28)
26
+ async-pool (~> 0.2)
27
+ protocol-http (~> 0.21.0)
28
+ protocol-http1 (~> 0.13.0)
29
+ protocol-http2 (~> 0.14.0)
30
+ async-http-faraday (0.9.0)
31
+ async-http (~> 0.42)
32
+ faraday
33
+ async-io (1.30.2)
34
+ async (~> 1.14)
35
+ async-pool (0.3.5)
36
+ async (~> 1.25)
11
37
  cmdparse (3.0.7)
38
+ concurrent-ruby (1.1.7)
39
+ console (1.10.2)
40
+ fiber-local
41
+ faraday (0.17.3)
42
+ multipart-post (>= 1.2, < 3)
43
+ faraday-http-cache (1.2.2)
44
+ faraday (~> 0.8)
45
+ fiber-local (1.0.0)
46
+ github_changelog_generator (1.16.1)
47
+ activesupport
48
+ async (>= 1.25.0)
49
+ async-http-faraday
50
+ faraday-http-cache
51
+ multi_json
52
+ octokit (~> 4.6)
53
+ rainbow (>= 2.2.1)
54
+ rake (>= 10.0)
55
+ retriable (~> 3.0)
12
56
  httparty (0.18.1)
13
57
  mime-types (~> 3.0)
14
58
  multi_xml (>= 0.5.2)
59
+ i18n (1.8.5)
60
+ concurrent-ruby (~> 1.0)
15
61
  mime-types (3.3.1)
16
62
  mime-types-data (~> 3.2015)
17
63
  mime-types-data (3.2021.0225)
18
64
  minitest (5.14.4)
65
+ multi_json (1.15.0)
19
66
  multi_xml (0.6.0)
67
+ multipart-post (2.1.1)
68
+ nio4r (2.5.4)
69
+ octokit (4.18.0)
70
+ faraday (>= 0.9)
71
+ sawyer (~> 0.8.0, >= 0.5.3)
72
+ protocol-hpack (1.4.2)
73
+ protocol-http (0.21.0)
74
+ protocol-http1 (0.13.2)
75
+ protocol-http (~> 0.19)
76
+ protocol-http2 (0.14.2)
77
+ protocol-hpack (~> 1.4)
78
+ protocol-http (~> 0.18)
79
+ public_suffix (4.0.6)
80
+ rainbow (3.0.0)
20
81
  rake (13.0.3)
82
+ retriable (3.1.2)
83
+ sawyer (0.8.2)
84
+ addressable (>= 2.3.5)
85
+ faraday (> 0.8, < 2.0)
86
+ thread_safe (0.3.6)
87
+ timers (4.3.3)
88
+ tzinfo (1.2.8)
89
+ thread_safe (~> 0.1)
90
+ zeitwerk (2.4.2)
21
91
 
22
92
  PLATFORMS
23
93
  ruby
@@ -27,6 +97,7 @@ PLATFORMS
27
97
  DEPENDENCIES
28
98
  a2!
29
99
  bundler (~> 2.2.15)
100
+ github_changelog_generator
30
101
  minitest (~> 5.0)
31
102
  rake (>= 12.3.3)
32
103
 
data/README.md CHANGED
@@ -21,7 +21,7 @@ Environment variables:
21
21
  ```
22
22
  AUTOMATE_URL="https://automate.example.com"
23
23
  AUTOMATE_TOKEN="my-token"
24
- SSL_NO_VERIFY=true
24
+ AUTOMATE_SSL_NO_VERIFY=true
25
25
  ```
26
26
 
27
27
  List the available commands:
@@ -32,6 +32,7 @@ List the available commands:
32
32
  Available commands:
33
33
  compliance Compliance management commands
34
34
  export-node-reports
35
+ list-reports
35
36
  help Provide help for individual commands
36
37
  iam Identity access management commands
37
38
  add-membership
data/a2.gemspec CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = A2::VERSION
9
9
  spec.authors = ['gscho']
10
10
  spec.email = ['greg.c.schofield@gmail.com']
11
- spec.summary = %q{Write a short summary, because RubyGems requires one.}
12
- spec.description = %q{Write a longer description or delete this line.}
13
- spec.homepage = 'https://github.com/gscho/a2'
11
+ spec.summary = %q{A gem for interacting with the Chef Automate 2+ API}
12
+ spec.description = %q{A gem for interacting with the Chef Automate 2+ API}
13
+ spec.homepage = 'https://github.com/gscho/a2-cli'
14
14
  spec.license = 'MIT'
15
15
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
16
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -18,9 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.bindir = 'bin'
19
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
+ spec.metadata = {
22
+ "source_code_uri" => spec.homepage,
23
+ "changelog_uri" => "#{spec.homepage}/CHANGELOG.md"
24
+ }
21
25
  spec.add_development_dependency 'bundler', '~> 2.2.15'
22
26
  spec.add_development_dependency 'rake', '>= 12.3.3'
23
27
  spec.add_development_dependency 'minitest', '~> 5.0'
28
+ spec.add_development_dependency 'github_changelog_generator'
24
29
  spec.add_dependency 'cmdparse'
25
30
  spec.add_dependency 'httparty'
26
31
  end
data/lib/a2/client.rb CHANGED
@@ -47,7 +47,7 @@ module A2
47
47
  JSON.parse(response.body)
48
48
  end
49
49
 
50
- def download_report(path, json, output_file)
50
+ def download_file(path, json, output_file)
51
51
  File.open(output_file, "w") do |file|
52
52
  HTTParty.post(File.join(@automate_url, path).to_s, {
53
53
  verify: !@ssl_no_verify,
@@ -2,7 +2,11 @@ module A2
2
2
  class Client
3
3
  module Reporting
4
4
  def export_node_reports(json, output_file)
5
- download_report '/api/v0/compliance/reporting/node/export', json, output_file
5
+ download_file '/api/v0/compliance/reporting/node/export', json, output_file
6
+ end
7
+
8
+ def list_reports(json)
9
+ post '/api/v0/compliance/reporting/reports', json
6
10
  end
7
11
  end
8
12
  end
@@ -8,6 +8,7 @@ module A2
8
8
  short_desc('Compliance management commands')
9
9
  long_desc('Compliance management commands')
10
10
  add_command(A2::Subcommand::Reporting::ExportNodeReports.new)
11
+ add_command(A2::Subcommand::Reporting::ListReports.new)
11
12
  end
12
13
  end
13
14
  end
@@ -1,14 +1,13 @@
1
1
  module A2
2
2
  module Approved
3
- def initialize(name, opts = {})
4
- super(name, takes_commands: false)
5
- @opt = {}
3
+ def add_approval_option!(options, opt = {})
6
4
  options.on('-y', '--yes', 'Auto approve the deletion prompt.') do
7
- @opt[:yes] = true
5
+ opt[:auto_approved] = true
8
6
  end
7
+ opt
9
8
  end
10
9
 
11
- def ask_for_approval(message)
10
+ def ask_for_approval(message = '')
12
11
  puts "Are you sure you want to #{message}?"
13
12
  puts "Only 'yes' will be accepted to proceed:"
14
13
  answer = $stdin.gets.chomp
@@ -16,9 +15,10 @@ module A2
16
15
  answer
17
16
  end
18
17
 
19
- def with_approval(message, &block)
18
+ def with_approval(opts, &block)
19
+ opts[:auto_approved] = opts[:auto_approved] || false
20
20
  answer = 'yes'
21
- answer = ask_for_approval(message) unless @opt[:yes]
21
+ answer = ask_for_approval(opts[:message]) unless opts[:auto_approved]
22
22
  block.call if answer.eql?('yes')
23
23
  end
24
24
  end
@@ -1,5 +1,6 @@
1
1
  module A2
2
2
  class Filtered < CmdParse::Command
3
+ attr_reader :query_filter, :filter_key
3
4
  def initialize(name, opts = {})
4
5
  set_custom_opts!(opts)
5
6
  super(name, opts)
@@ -26,10 +26,11 @@ module A2
26
26
  include A2::Approved
27
27
  def initialize
28
28
  super('delete', takes_commands: false)
29
+ @opt = add_approval_option!(options)
29
30
  end
30
31
 
31
32
  def execute(id)
32
- with_approval("delete node #{id}") do
33
+ with_approval(message: "delete node #{id}", auto_approved: @opt[:auto_approved]) do
33
34
  puts JSON.pretty_generate(A2::Client.new(command_parser.data).delete_managed_node(id))
34
35
  end
35
36
  end
@@ -38,10 +39,11 @@ module A2
38
39
  include A2::Approved
39
40
  def initialize
40
41
  super('bulk-delete-by-ids', takes_commands: false)
42
+ @opt = add_approval_option!(options)
41
43
  end
42
44
 
43
45
  def execute(ids)
44
- with_approval("delete nodes") do
46
+ with_approval(message: "delete nodes", auto_approved: @opt[:auto_approved]) do
45
47
  puts JSON.pretty_generate(A2::Client.new(command_parser.data).bulk_delete_managed_nodes_by_id(id))
46
48
  end
47
49
  end
@@ -50,11 +52,12 @@ module A2
50
52
  include A2::Approved
51
53
  def initialize
52
54
  super('bulk-delete-by-filter', takes_commands: false)
55
+ @opt = add_approval_option!(options)
53
56
  end
54
57
 
55
58
  def execute
56
59
  with_paginated_filter_json do |json|
57
- with_approval("delete nodes using filter") do
60
+ with_approval(message: "delete nodes using filter", auto_approved: @opt[:auto_approved]) do
58
61
  puts JSON.pretty_generate(A2::Client.new(command_parser.data).bulk_delete_managed_nodes_by_filter(json))
59
62
  end
60
63
  end
@@ -25,6 +25,37 @@ module A2
25
25
  end
26
26
  end
27
27
  end
28
+ class ListReports < Paginated
29
+ def initialize
30
+ super('list-reports', takes_commands: false, filter_key: 'type')
31
+ options.on('-i', '--skip-impact IMPACT', 'Only show reports with an impact score greater than the provided value.') do |impact|
32
+ @opt[:impact] = impact
33
+ end
34
+ end
35
+
36
+ def execute
37
+ impact = @opt.delete(:impact)
38
+ with_paginated_filter_json do |json|
39
+ reports_json = A2::Client.new(command_parser.data).list_reports(json)
40
+ reports_json = filter_by_min_impact(reports_json, impact) unless impact.nil?
41
+
42
+ puts JSON.pretty_generate(reports_json)
43
+ end
44
+ end
45
+
46
+ def filter_by_min_impact(report_json, impact)
47
+ report_json['reports'].delete_if do |report|
48
+ if impact == 'minor'
49
+ if report['controls']['failed']['major'].eql?(0) && report['controls']['failed']['critical'].eql?(0)
50
+ true
51
+ end
52
+ elsif impact == 'major'
53
+ true if report['controls']['failed']['critical'].eql?(0)
54
+ end
55
+ end
56
+ report_json
57
+ end
58
+ end
28
59
  end
29
60
  end
30
61
  end
@@ -50,10 +50,11 @@ module A2
50
50
  include A2::Approved
51
51
  def initialize
52
52
  super('delete-team', takes_commands: false)
53
+ @opt = add_approval_option!(options)
53
54
  end
54
55
 
55
56
  def execute(id)
56
- with_approval("delete team #{id}") do
57
+ with_approval(message: "delete team #{id}", auto_approved: @opt[:auto_approved]) do
57
58
  puts JSON.pretty_generate(A2::Client.new(command_parser.data).delete_team(id))
58
59
  end
59
60
  end
@@ -50,10 +50,11 @@ module A2
50
50
  include A2::Approved
51
51
  def initialize
52
52
  super('delete-user', takes_commands: false)
53
+ @opt = add_approval_option!(options)
53
54
  end
54
55
 
55
56
  def execute(id)
56
- with_approval("delete user #{id}") do
57
+ with_approval(message: "delete user #{id}", auto_approved: @opt[:auto_approved]) do
57
58
  puts JSON.pretty_generate(A2::Client.new(command_parser.data).delete_user(id))
58
59
  end
59
60
  end
data/lib/a2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module A2
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gscho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-07 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: github_changelog_generator
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: cmdparse
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +94,7 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
- description: Write a longer description or delete this line.
97
+ description: A gem for interacting with the Chef Automate 2+ API
84
98
  email:
85
99
  - greg.c.schofield@gmail.com
86
100
  executables:
@@ -93,6 +107,7 @@ files:
93
107
  - ".github/workflows/gem-push.yml"
94
108
  - ".github/workflows/run-rake.yml"
95
109
  - ".gitignore"
110
+ - CHANGELOG.md
96
111
  - Gemfile
97
112
  - Gemfile.lock
98
113
  - LICENSE.txt
@@ -124,10 +139,12 @@ files:
124
139
  - lib/a2/subcommands/team.rb
125
140
  - lib/a2/subcommands/user.rb
126
141
  - lib/a2/version.rb
127
- homepage: https://github.com/gscho/a2
142
+ homepage: https://github.com/gscho/a2-cli
128
143
  licenses:
129
144
  - MIT
130
- metadata: {}
145
+ metadata:
146
+ source_code_uri: https://github.com/gscho/a2-cli
147
+ changelog_uri: https://github.com/gscho/a2-cli/CHANGELOG.md
131
148
  post_install_message:
132
149
  rdoc_options: []
133
150
  require_paths:
@@ -143,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
160
  - !ruby/object:Gem::Version
144
161
  version: '0'
145
162
  requirements: []
146
- rubygems_version: 3.0.3
163
+ rubygems_version: 3.0.3.1
147
164
  signing_key:
148
165
  specification_version: 4
149
- summary: Write a short summary, because RubyGems requires one.
166
+ summary: A gem for interacting with the Chef Automate 2+ API
150
167
  test_files: []