eco-helpers 1.1.3 → 1.1.4

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: a2efa416d986a9c212bc99ec69bf667778392737f0c635d54a18d19ff8bced9b
4
- data.tar.gz: 7747bbfa3253f537d08b65148f8fc7418b0f4190d2754873daeb0b9fc5642b41
3
+ metadata.gz: d691b4d2eccce894adbff1cfa42b20adb8a24a06bbb7518e7367458f91fd7f96
4
+ data.tar.gz: 1fd8f054a63d1bd3204bbbc13dcebda52edee0160db37746ec4c50521b381970
5
5
  SHA512:
6
- metadata.gz: 60457d180398b01377aaeb6bced7c57fb24010da7acecbca8cbdac46a16d617759a23175e6b7be8c2b8eb4ec3834119e5173d8f2ff14212493a3db35298441ed
7
- data.tar.gz: 5fab0a498910811d86f63419193aa02d1aebd52d4a1c63db1d11c173d9905f651e47c1082090ef0a83236f8c1d48d2c206572d25b1881b05dddc6cbc4be69c0e
6
+ metadata.gz: 2b5abae5d92712bcf46f0559221679d1bb47970aa24c902bb91edeee5f40b43a2e3eb209b2980bfe228cf3bd0a47d13c64b3d4bb4ed3dba51846ab31e653d135
7
+ data.tar.gz: dc0d66aefeb659f8ee7d64a0462c49df1d77667584d09257c64beadd57da5cba7e6c9712419d42651c0607fc606803d57e963e00925f8966109b6a0162d369dd
@@ -44,14 +44,26 @@ module Eco
44
44
  enviro.mailer
45
45
  end
46
46
 
47
+ def mailer?
48
+ enviro.mailer?
49
+ end
50
+
47
51
  def sftp
48
52
  enviro.sftp
49
53
  end
50
-
54
+
55
+ def sftp?
56
+ enviro.sftp?
57
+ end
58
+
51
59
  def s3uploader
52
60
  enviro.s3uploader
53
61
  end
54
62
 
63
+ def s3uploader?
64
+ enviro.s3uploader?
65
+ end
66
+
55
67
  def logger
56
68
  enviro.logger
57
69
  end
@@ -28,15 +28,33 @@ module Eco
28
28
  end
29
29
 
30
30
  def mailer
31
- @mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self)
31
+ if mailer?
32
+ @mailer ||= Eco::API::Common::Session::Mailer.new(enviro: self)
33
+ end
34
+ end
35
+
36
+ def mailer?
37
+ config.mailer.configured?
32
38
  end
33
39
 
34
40
  def sftp
35
- @sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self)
41
+ if sftp?
42
+ @sftp ||= Eco::API::Common::Session::SFTP.new(enviro: self)
43
+ end
44
+ end
45
+
46
+ def sftp?
47
+ config.sftp.configured?
36
48
  end
37
49
 
38
50
  def s3uploader
39
- @s3uploader ||= Eco::API::Common::Session::S3Uploader.new(enviro: self)
51
+ if s3uploader?
52
+ @s3uploader ||= Eco::API::Common::Session::S3Uploader.new(enviro: self)
53
+ end
54
+ end
55
+
56
+ def s3uploader?
57
+ config.s3storage.configured?
40
58
  end
41
59
 
42
60
  def api
@@ -208,7 +208,12 @@ module Eco
208
208
  # Sends an email
209
209
  # @see Eco::API::Common::Session::Mailer#mail
210
210
  def mail(**kargs)
211
- mailer.mail(**kargs)
211
+ if mailer?
212
+ mailer.mail(**kargs)
213
+ else
214
+ logger.error("You are trying to use the mailer, but it's not configured")
215
+ nil
216
+ end
212
217
  end
213
218
 
214
219
  # Uploads content into a file, a file or a directory to S3
@@ -222,19 +227,24 @@ module Eco
222
227
  # @param link [Boolean] **return** _link(s)_ (`true`) or _path(s)_ (`false`: default)
223
228
  # @return [String, Array<String>] either paths to S3 objects if `link` is `false`, or _link_ otherwise
224
229
  def s3upload(content: nil, file: nil, directory: nil, recurse: false, link: false)
225
- if content == :target
226
- path = self.do.s3upload_targets
227
- elsif content && file
228
- path = s3uploader.upload(file, content)
229
- elsif file
230
- path = s3uploader.upload_file(file)
231
- elsif directory
232
- path = s3uploader.upload_directory(directory, recurse: recurse)
230
+ if s3uploader?
231
+ if content == :target
232
+ path = self.do.s3upload_targets
233
+ elsif content && file
234
+ path = s3uploader.upload(file, content)
235
+ elsif file
236
+ path = s3uploader.upload_file(file)
237
+ elsif directory
238
+ path = s3uploader.upload_directory(directory, recurse: recurse)
239
+ else
240
+ logger.error("To use Session.s3upload, you must specify either directory, file or content and file name")
241
+ end
242
+ return path unless link
243
+ s3uploader.link(path)
233
244
  else
234
- logger.error("To use Session.s3upload, you must specify either directory, file or content and file name")
245
+ logger.error("You are trying to use S3 uploader, but it's not configured")
246
+ nil
235
247
  end
236
- return path unless link
237
- s3uploader.link(path)
238
248
  end
239
249
 
240
250
  private
@@ -87,9 +87,9 @@ module Eco
87
87
  requests ||= job.requests
88
88
  [].tap do |msg|
89
89
  if !requests || !requests.is_a?(Enumerable) || requests.empty?
90
- msg << "#{"*" * 20} Nothing for #{signature} so far :) #{"*" * 20}"
90
+ msg << "#{"*" * 10} Nothing for #{signature} so far :) #{"*" * 10}"
91
91
  else
92
- header = "#{"*"*20} #{signature} - Feedback Sample #{"*"*20}"
92
+ header = "#{"*"*10} #{signature} - Feedback Sample #{"*"*10}"
93
93
  msg << header unless only_stats
94
94
  unless only_stats
95
95
  sample_length = 1
@@ -100,7 +100,7 @@ module Eco
100
100
  end
101
101
  msg << "#{sample.slice(0, sample_length).pretty_inspect}"
102
102
  end
103
- msg << "#{"+"*5} STATS (job '#{name}') +++ #{type.to_s.upcase} length: #{requests.length} #{"+"*5}"
103
+ msg << "#{"+"*3} #{type.to_s.upcase} length: #{requests.length} #{"+"*3} STATS (job '#{name}') #{"+"*3}"
104
104
  msg << "#{request_stats(requests).message}"
105
105
  msg << "*" * header.length unless only_stats
106
106
  end
@@ -4,6 +4,11 @@ module Eco
4
4
  class Config
5
5
  class Mailer < BaseConfig
6
6
 
7
+ def configured?
8
+ required = access_key_id && secret_access_key && region
9
+ !!required
10
+ end
11
+
7
12
  def to=(value)
8
13
  self["to"] = value
9
14
  end
@@ -11,7 +16,7 @@ module Eco
11
16
  def to
12
17
  self["to"]
13
18
  end
14
-
19
+
15
20
  def from=(value)
16
21
  self["from"] = value
17
22
  end
@@ -4,6 +4,11 @@ module Eco
4
4
  class Config
5
5
  class S3Storage < BaseConfig
6
6
 
7
+ def configured?
8
+ required = bucket_name && prefix && access_key_id && secret_access_key && region
9
+ !!required
10
+ end
11
+
7
12
  def bucket_name=(value)
8
13
  self["bucket_name"] = value
9
14
  end
@@ -4,6 +4,11 @@ module Eco
4
4
  class Config
5
5
  class SFTP < BaseConfig
6
6
 
7
+ def configured?
8
+ required = host && user && key_file
9
+ !!required
10
+ end
11
+
7
12
  def host=(value)
8
13
  self["host"] = value
9
14
  end
@@ -51,7 +56,7 @@ module Eco
51
56
  def remote_folder
52
57
  base_path + "/" + enviro_subpath
53
58
  end
54
-
59
+
55
60
  end
56
61
  end
57
62
  end
@@ -237,7 +237,7 @@ module Eco
237
237
  raise i
238
238
  rescue Exception => e
239
239
  self.rescue.call(e, io) if self.rescue
240
- raise e
240
+ raise
241
241
  end
242
242
  io
243
243
  end
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura