eco-rake 0.2.16 → 0.2.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6adc55db4ba9cc01ef0f3bd19630c8028431e12cd2846a8242d885adcea349a9
4
- data.tar.gz: ee6222a4f3018f6fc0d945a7c7092dccea23342501e345ba10a8417333ade30b
3
+ metadata.gz: 0bb9055bc4df37679dbb4c3b72642bcbb46aae262a130c6f55f036cea18102d0
4
+ data.tar.gz: 8924b3ff334aad4797fe2214e814546d5842522a2aba4d271df55c3821ec894d
5
5
  SHA512:
6
- metadata.gz: f09228e9b94773ba18a528116f3094f641b832da371357fff4ea72f70900bef36ca0407e6604009d216a91ad45c1add2731fb7eea499f1561f5e087156fda298
7
- data.tar.gz: bf02711a0c9939086153ad9206cd87298335b8e1a5b0fa11042855e81039de8fbce53da8e3db8b8fffeb3b88b7e5867c6caad1afb6e15961a9638fab86655bf4
6
+ metadata.gz: d2eab027780b84fa36cc3102eabc88a793c62a74e88e90c6c2f47cc391f2e12622d880ae8616a7248479ef6b86c8d4ace23e506ebbb4be8c843e8289c27f357c
7
+ data.tar.gz: cc2bd29bde312fbd7419faf87d7269859586301c7a52e7c84bdd9dd54c6260a28bdecd9d52e0a3330daa66937e05aba090fb5d0b3fbb9ecc8094a8d1e08c3825
data/.gitignore CHANGED
@@ -26,3 +26,4 @@ Gemfile.lock
26
26
  scratch.rb
27
27
 
28
28
  /.byebug_history
29
+ .solargraph.yml
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [0.2.17] - 2025-03-xx
5
+ ## [0.2.18] - 2025-03-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,6 +10,15 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Fixed
12
12
 
13
+ ## [0.2.17] - 2025-03-22
14
+
15
+ ### Added
16
+
17
+ - `space` to mailing.
18
+ - Export `payload` notify
19
+ - On error
20
+ - On success
21
+
13
22
  ## [0.2.16] - 2025-03-11
14
23
 
15
24
  ### Fixed
@@ -8,32 +8,51 @@ class EcoRake
8
8
  module Lib
9
9
  module Export
10
10
  class Payload < EcoRake::Lib::BaseTask
11
- INCLUDED_OPTIONS = %i[csv simulate].freeze
11
+ INCLUDED_OPTIONS = %i[csv simulate no_email].freeze
12
12
  FORWARD_RULES = {
13
- enviro: ->(enviro) { "-#{enviro}" },
14
- space: ->(space) { "-space #{space}" },
13
+ enviro: ->(enviro) { "-#{enviro}" },
14
+ space: ->(space) { "-space #{space}" },
15
15
  simulate: '-simulate',
16
+ no_email: '-no-email',
16
17
  csv: '-csv',
17
18
  full: ->(full) { full ? nil : '-delta' },
18
19
  asat: ->(asat) { "-asatdate #{asat}" }
19
20
  }.freeze
20
21
 
22
+ attr_const :mail_to
23
+
21
24
  options_with_defaults true
22
25
  option '-s', '--simulate', TrueClass, 'Do a dry-run (with no changes)'
23
- option '-e', '--enviro ENVIRO', String, desc: 'Target environment to run against (i.e. org, live)', required: true # , default_lookup: :default_enviro
24
- option '-w', '--space SPACE', String, desc: 'Target space of the envionment (i.e. uat)'
25
- option '-f', '--[no-]full', TrueClass, default: false, desc: 'If the PAYLOAD file is a full file (false: means delta)'
26
- option '-c', '--csv', TrueClass, default: true, desc: 'Generate files in csv format?'
27
- option '-a', '--asat [DATE]', Time, default: Time.now.iso8601, desc: 'Specifies the date when the export was done (default: now).' do |value|
26
+
27
+ str_desc = 'Target environment to run against (i.e. org, live)'
28
+ option '-e', '--enviro ENVIRO', String, desc: str_desc, required: true # , default_lookup: :default_enviro
29
+
30
+ str_desc = 'Target space of the envionment (i.e. uat)'
31
+ option '-w', '--space SPACE', String, desc: str_desc
32
+
33
+ str_desc = 'If the PAYLOAD file is a full file (false: means delta)'
34
+ option '-f', '--[no-]full', TrueClass, default: false, desc: str_desc
35
+
36
+ str_desc = 'Generate files in csv format?'
37
+ option '-c', '--csv', TrueClass, default: true, desc: str_desc
38
+
39
+ str_desc = 'Specifies the date when the export was done (default: now).'
40
+ option '-a', '--asat [DATE]', Time, default: Time.now.iso8601, desc: str_desc do |value|
28
41
  value&.iso8601
29
42
  end
30
43
 
44
+ option '-m', '--no-email', FalseClass, desc: 'Do not notify'
45
+
31
46
  option_forwarding(**FORWARD_RULES)
32
47
 
33
48
  def task(*_args)
34
- sh_chain(commands) do |ok, _res|
35
- exit 1 unless ok
49
+ sh_chain(commands) do |ok, res|
50
+ next if ok
51
+
52
+ error_notify!(res)
36
53
  end
54
+
55
+ success_notify
37
56
  end
38
57
 
39
58
  private
@@ -60,7 +79,7 @@ class EcoRake
60
79
  end
61
80
 
62
81
  def export_sftp_push
63
- base_command('-export-sftp-push')
82
+ forward_command('-export-sftp-push')
64
83
  end
65
84
 
66
85
  def forward_command(use, *opts)
@@ -81,6 +100,39 @@ class EcoRake
81
100
  use
82
101
  )
83
102
  end
103
+
104
+ def success_notify
105
+ return if options[:simulate]
106
+ return if options[:no_email]
107
+ return unless (inbox = mail_to)
108
+
109
+ email(
110
+ subject: "Payload pushed",
111
+ to: inbox,
112
+ body: 'The data extract has been correctly pushed.',
113
+ enviro: options[:enviro],
114
+ space: options[:space]
115
+ )
116
+ end
117
+
118
+ def error_notify!(res)
119
+ msg = res.to_s
120
+ puts msg
121
+
122
+ exit 1 if options[:simulate]
123
+ exit 1 if options[:no_email]
124
+ exit 1 unless (inbox = mail_to)
125
+
126
+ email(
127
+ subject: "Error exporting payload",
128
+ to: inbox,
129
+ body: 'Could not push latest extract.',
130
+ enviro: options[:enviro],
131
+ space: options[:space]
132
+ )
133
+
134
+ exit 1
135
+ end
84
136
  end
85
137
  end
86
138
  end
@@ -17,7 +17,7 @@ class EcoRake
17
17
  target_files.each do |file|
18
18
  delete_file(gpg_to_csv_filename(file))
19
19
 
20
- stat = sh_continue(
20
+ stat = sh_continue(
21
21
  decrypt_command(file, ignore_mdc_error: ignore_mdc_error)
22
22
  )
23
23
 
@@ -63,7 +63,12 @@ class EcoRake
63
63
  exit 1 if options[:no_email]
64
64
  exit 1 unless (inbox = mail_to)
65
65
 
66
- email_missing_files(enviro: target_enviro, to: inbox)
66
+ email_missing_files(
67
+ to: inbox,
68
+ enviro: target_enviro,
69
+ space: options[:space]
70
+ )
71
+
67
72
  exit 1
68
73
  end
69
74
 
@@ -156,7 +161,9 @@ class EcoRake
156
161
  deleted << file
157
162
  end
158
163
 
159
- puts "Deleted these files:\n • #{deleted_files.join("\n • ")}" unless deleted_files.empty?
164
+ return if deleted_files.empty?
165
+
166
+ puts "Deleted these files:\n • #{deleted_files.join("\n • ")}"
160
167
  end
161
168
  end
162
169
  end
@@ -66,11 +66,19 @@ class EcoRake
66
66
  def failed_decryption_notify
67
67
  msg = 'File decryption failed'
68
68
  puts msg
69
+
69
70
  exit 1 if options[:simulate]
70
71
  exit 1 if options[:no_email]
71
72
  exit 1 unless (inbox = mail_to)
72
73
 
73
- email(enviro: target_enviro, to: inbox, subject: msg, body: msg)
74
+ email(
75
+ to: inbox,
76
+ subject: msg,
77
+ body: msg,
78
+ enviro: target_enviro,
79
+ space: options[:space]
80
+ )
81
+
74
82
  exit 1
75
83
  end
76
84
  end
@@ -65,9 +65,9 @@ class EcoRake
65
65
  # and changes its extension to `csv`.
66
66
  # @return [String]
67
67
  def gpg_to_csv_filename(gpg_file)
68
- return nil unless gpg_file
68
+ return unless gpg_file
69
69
 
70
- ext = gpg_file.split('.')[1..-1].join('.')
70
+ ext = gpg_file.split('.')[1..].join('.')
71
71
  base = File.basename(gpg_file, ".#{ext}")
72
72
  folder = File.dirname(gpg_file)
73
73
  File.join(folder, "#{base}.csv")
@@ -13,16 +13,20 @@ class EcoRake
13
13
  # is different. This is the reason why we check what is the option for a `loopback`
14
14
  # @param gpg_file [String] the file meant to be decrypted.
15
15
  # @return [String] the command to decrypt `gpg_file`
16
- def decrypt_command(gpg_file, gpg_key: ENV["GPG_KEY"], ignore_mdc_error: false)
16
+ def decrypt_command(gpg_file, gpg_key: ENV['GPG_KEY'], ignore_mdc_error: false)
17
17
  csv_file = gpg_to_csv_filename(gpg_file)
18
18
  no_error = ignore_mdc_error ? '--ignore-mdc-error' : nil
19
- loopback = gpg_version_gte?(major: 2, minor: 1)? "--pinentry-mode=loopback" : "--batch --yes"
19
+
20
+ loopback = '--batch --yes'
21
+ loopback = '--pinentry-mode=loopback' if gpg_version_gte?(major: 2, minor: 1)
22
+
20
23
  args = [
21
24
  no_error, loopback,
22
25
  '--passphrase', double_quote(gpg_key),
23
26
  '-o', double_quote(csv_file),
24
27
  '-d', double_quote(gpg_file)
25
28
  ]
29
+
26
30
  string_cmd('gpg', *args)
27
31
  end
28
32
 
@@ -37,10 +41,10 @@ class EcoRake
37
41
  # @note the versioning format is `MAJOR.MINOR.PATCH`
38
42
  # @example if the host has this gpg version: `gpg (GnuPG) 2.1.10`. The following is to be expected:
39
43
  # 1. `gpg_version_gte?(major: 1, minor: 10)` return `true`
40
- # 2. `gpg_version_gte?(major: 3, minor: 0)` return `false`
41
- # 3. `gpg_version_gte?(major: 2, minor: 0)` return `true`
42
- # 4. `gpg_version_gte?(major: 2, minor: 1)` return `true`
43
- # 5. `gpg_version_gte?(major: 2, minor: 3)` return `false`
44
+ # 2. `gpg_version_gte?(major: 3, minor: 0)` return `false`
45
+ # 3. `gpg_version_gte?(major: 2, minor: 0)` return `true`
46
+ # 4. `gpg_version_gte?(major: 2, minor: 1)` return `true`
47
+ # 5. `gpg_version_gte?(major: 2, minor: 3)` return `false`
44
48
  # @return [Boolean]
45
49
  def gpg_version_gte?(major:, minor:)
46
50
  result = shell_gpg_version
@@ -6,9 +6,15 @@ class EcoRake
6
6
  @mailer ||= EcoRake::Utils::Mailer.new
7
7
  end
8
8
 
9
- def email(subject:, body:, to:, enviro: nil)
9
+ def email(subject:, body:, to:, enviro: nil, space: nil)
10
10
  has_enviro = enviro && subject&.downcase&.include?(enviro.downcase)
11
- subject = "#{enviro.upcase} - #{subject}" if enviro && !has_enviro
11
+
12
+ if enviro && !has_enviro
13
+ env_str = enviro.upcase
14
+ env_str << " (space: #{space})" if space
15
+ subject = "#{env_str} - #{subject}"
16
+ end
17
+
12
18
  mailer.mail(
13
19
  to: to,
14
20
  subject: subject,
@@ -17,11 +23,13 @@ class EcoRake
17
23
  end
18
24
 
19
25
  # Helper to notify that there are no files to be processed
20
- def email_missing_files(enviro:, to:)
26
+ def email_missing_files(enviro:, to:, space: nil)
21
27
  email(
22
28
  to: to,
23
- subject: "#{enviro.upcase} (No files to be processed)",
24
- body: 'No files found to be processed. Aborting...'
29
+ subject: "No files to be processed",
30
+ body: 'No files found to be processed. Aborting...',
31
+ enviro: enviro,
32
+ space: space
25
33
  )
26
34
  end
27
35
  end
@@ -1,5 +1,5 @@
1
1
  require 'rake-commander'
2
2
 
3
3
  class EcoRake < RakeCommander
4
- VERSION = '0.2.16'.freeze
4
+ VERSION = '0.2.17'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-rake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.16
4
+ version: 0.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura Samper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-11 00:00:00.000000000 Z
11
+ date: 2025-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake