smart_proxy_reports 0.0.5 → 0.0.6

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: a87c1e46cdc27bbfa0c00b76c30da881d87ca699457395ba471318139a8e6e07
4
- data.tar.gz: efca59c56a9b292aec6e8e72cc5b05d4db959d18651f8ac4848e0b1a79fece02
3
+ metadata.gz: d912cb5621772d9d65e57b9a35bc6a9b6bba176b5a4e6b13ba92e925af516138
4
+ data.tar.gz: 21cd931923c1035e34d74a997a2b21db7a3e18763fcbb577ef627d335a17c968
5
5
  SHA512:
6
- metadata.gz: a7acce03922c7e3c893e438206a1ac3482aabd7c44010655ae4bbbab4cc88146d4c8bf02329c789d551a9badccb267bfbeae42fec58460d7165aec4b1d47c29b
7
- data.tar.gz: c6540c75cc3076883f2fd6f76e65795ab2bbd1e2c2699576fc01b2eacae24b1b88d354135116704fa673fd27a43ea5bed6c7e004b148345601be294a0ec8f847
6
+ metadata.gz: 75c240ad37535a5b5b27ba7d6591e3ab4e32b2c94530adbfc5bd034a44382dbeda7eef49a8d298e2f59b931392d69ec54f0457fdffdce89eccd45ebccf726da9
7
+ data.tar.gz: b6c8b3ffc7af5f2971699fe60f7d31406f52733b8f5c238a7889bfdd17ccdf00d2cad8e6d93b1d35b438e3ef5aff0e178bb74dd5de0fe0397d7c4ac451e212e8
@@ -1,3 +1,5 @@
1
+ require_relative "friendly_message"
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  module Proxy::Reports
@@ -20,9 +22,12 @@ module Proxy::Reports
20
22
 
21
23
  def process_results
22
24
  @data["results"]&.each do |result|
25
+ raise("Report do not contain required 'results/result' element") unless result["result"]
26
+ raise("Report do not contain required 'results/task' element") unless result["task"]
23
27
  process_facts(result)
24
28
  process_level(result)
25
- process_message(result)
29
+ friendly_message = FriendlyMessage.new(result)
30
+ result["friendly_message"] = friendly_message.generate_message
26
31
  process_keywords(result)
27
32
  end
28
33
  @data["results"]
@@ -99,41 +104,6 @@ module Proxy::Reports
99
104
  end
100
105
  end
101
106
 
102
- def process_message(result)
103
- msg = "N/A"
104
- return result["friendly_message"] = msg if result["task"].nil? || result["task"]["action"].nil?
105
- return result["friendly_message"] = result["result"]["msg"] if result["failed"]
106
- result_tree = result["result"]
107
- task_tree = result["task"]
108
- raise("Report do not contain required 'results/result' element") unless result_tree
109
- raise("Report do not contain required 'results/task' element") unless task_tree
110
- module_args_tree = result_tree.dig("invocation", "module_args")
111
-
112
- case task_tree["action"]
113
- when "ansible.builtin.package", "package"
114
- detail = result_tree["results"] || result_tree["msg"] || "No details"
115
- msg = "Package(s) #{module_args_tree["name"].join(",")} are #{module_args_tree["state"]}: #{detail}"
116
- when "ansible.builtin.template", "template"
117
- msg = "Render template #{module_args_tree["_original_basename"]} to #{result_tree["dest"]}"
118
- when "ansible.builtin.service", "service"
119
- msg = "Service #{result_tree["name"]} is #{result_tree["state"]} and enabled: #{result_tree["enabled"]}"
120
- when "ansible.builtin.group", "group"
121
- msg = "User group #{result_tree["name"]} is #{result_tree["state"]} with gid: #{result_tree["gid"]}"
122
- when "ansible.builtin.user", "user"
123
- msg = "User #{result_tree["name"]} is #{result_tree["state"]} with uid: #{result_tree["uid"]}"
124
- when "ansible.builtin.cron", "cron"
125
- msg = "Cron job: #{module_args_tree["minute"]} #{module_args_tree["hour"]} #{module_args_tree["day"]} #{module_args_tree["month"]} #{module_args_tree["weekday"]} #{module_args_tree["job"]} and disabled: #{module_args_tree["disabled"]}"
126
- when "ansible.builtin.copy", "copy"
127
- msg = "Copy #{module_args_tree["_original_basename"]} to #{result_tree["dest"]}"
128
- when "ansible.builtin.command", "ansible.builtin.shell", "command", "shell"
129
- msg = result_tree["stdout_lines"]
130
- end
131
- rescue StandardError => e
132
- logger.debug "Unable to parse result (#{e.message}): #{result.inspect}"
133
- ensure
134
- result["friendly_message"] = msg
135
- end
136
-
137
107
  def process_statuses
138
108
  {
139
109
  "applied" => @body["status"]["applied"],
@@ -0,0 +1,66 @@
1
+ class FriendlyMessage
2
+ def initialize(result)
3
+ @result = result
4
+ @result_tree = @result["result"]
5
+ @task_tree = @result["task"]
6
+ @module_args_tree = @result_tree.dig("invocation", "module_args")
7
+ end
8
+
9
+ def generate_message
10
+ msg = "N/A"
11
+ return msg if @task_tree.nil? || @task_tree["action"].nil?
12
+ return @result_tree["msg"] if @result["failed"]
13
+
14
+ case @task_tree["action"]
15
+ when "ansible.builtin.package", "package" then msg = package_message
16
+ when "ansible.builtin.template", "template" then msg = template_message
17
+ when "ansible.builtin.service", "service" then msg = service_message
18
+ when "ansible.builtin.group", "group" then msg = group_message
19
+ when "ansible.builtin.user", "user" then msg = user_message
20
+ when "ansible.builtin.cron", "cron" then msg = cron_message
21
+ when "ansible.builtin.copy", "copy" then msg = copy_message
22
+ when "ansible.builtin.command", "ansible.builtin.shell", "command", "shell" then msg = @result_tree["stdout_lines"]
23
+ end
24
+ msg
25
+ rescue StandardError => e
26
+ logger.debug "Unable to parse result (#{e.message}): #{@result.inspect}"
27
+ msg
28
+ end
29
+
30
+ def human_readable_array(array, length = 10)
31
+ return array if array.nil?
32
+ return array.slice(0, length).join(", ") + " and more" if array.length > length
33
+ array.join(", ")
34
+ end
35
+
36
+ def package_message
37
+ packages = human_readable_array(@module_args_tree["name"])
38
+ state = "present"
39
+ state = @module_args_tree["state"] unless @module_args_tree["state"].nil?
40
+ "Package(s) #{packages} are #{state}"
41
+ end
42
+
43
+ def template_message
44
+ "Render template #{@module_args_tree["_original_basename"]} to #{@result_tree["dest"]}"
45
+ end
46
+
47
+ def service_message
48
+ "Service #{@result_tree["name"]} is #{@result_tree["state"]} and enabled: #{@result_tree["enabled"]}"
49
+ end
50
+
51
+ def group_message
52
+ "User group #{@result_tree["name"]} is #{@result_tree["state"]} with gid: #{@result_tree["gid"]}"
53
+ end
54
+
55
+ def user_message
56
+ "User #{@result_tree["name"]} is #{@result_tree["state"]} with uid: #{@result_tree["uid"]}"
57
+ end
58
+
59
+ def cron_message
60
+ "Cron job: #{@module_args_tree["minute"]} #{@module_args_tree["hour"]} #{@module_args_tree["day"]} #{@module_args_tree["month"]} #{@module_args_tree["weekday"]} #{@module_args_tree["job"]} and disabled: #{@module_args_tree["disabled"]}"
61
+ end
62
+
63
+ def copy_message
64
+ "Copy #{@module_args_tree["_original_basename"]} to #{@result_tree["dest"]}"
65
+ end
66
+ end
@@ -59,6 +59,8 @@ module Proxy::Reports
59
59
  add_keywords("PuppetHasSkips") if value["skipped"]
60
60
  # corrective changes
61
61
  add_keywords("PuppetHasCorrectiveChange") if value["corrective_change"]
62
+ # others
63
+ add_keywords("PuppetEnvironment:#{@data["environment"]}") if @data["environment"]
62
64
  end
63
65
  statuses
64
66
  rescue StandardError => e
@@ -1,5 +1,5 @@
1
1
  module Proxy
2
2
  module Reports
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_reports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Zapletal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-25 00:00:00.000000000 Z
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.0
19
+ version: 2.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.0
26
+ version: 2.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -51,6 +51,7 @@ files:
51
51
  - bundler.d/reports.rb
52
52
  - lib/smart_proxy_reports.rb
53
53
  - lib/smart_proxy_reports/ansible_processor.rb
54
+ - lib/smart_proxy_reports/friendly_message.rb
54
55
  - lib/smart_proxy_reports/processor.rb
55
56
  - lib/smart_proxy_reports/puppet_processor.rb
56
57
  - lib/smart_proxy_reports/reports.rb
@@ -62,7 +63,8 @@ files:
62
63
  homepage: http://github.com/theforeman/smart_proxy_reports
63
64
  licenses:
64
65
  - GPL-3.0-or-later
65
- metadata: {}
66
+ metadata:
67
+ rubygems_mfa_required: 'true'
66
68
  post_install_message:
67
69
  rdoc_options: []
68
70
  require_paths: