magellan-gcs-proxy 0.3.1 → 0.3.2

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
  SHA1:
3
- metadata.gz: fbfdc826b779db7cec5c24192988e35247c56e33
4
- data.tar.gz: 56879281961eebe651ac777a034505bb8cb060b7
3
+ metadata.gz: 8b318e66fc008a5c8b62110610219509a0b32edf
4
+ data.tar.gz: 15d802d7b358ea6f8a6be0802c038372ea7eda28
5
5
  SHA512:
6
- metadata.gz: 67dccc48b4ab362d2090cf1f82d2a2caa16201fbdf053e15e97ea89b94f03c6bd7deaeaec741321dfc92ce877aa2535a47dce84ba08e67cf2a252db94cbb0a5b
7
- data.tar.gz: b5c10a2f63c1ed87498d92ad40d7a1882c49e8dae503f61b34d98c317b1abd6909cdea858dd48e13c105ad660c20674c33be8b8575d2ebe03fcf2cdd371ab84c
6
+ metadata.gz: c682dcf84498989de79b73208ac2481196e6900e303d7028bb8b385f5a165046769359ccf5b550d8209220c0d535286cd7611581b8de64e2229ebe8ff4411439
7
+ data.tar.gz: eb9f9661ce1afa3517f77c7abb76c8e52fa3e43a16da1157d17b5d9a9212a40546aec23feeda79cbbfb6ce6942737c3ea5dc0b6500b1a71d067d2a2f3a3452ae
data/.rubocop.yml CHANGED
@@ -1,6 +1,12 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+
1
4
  Style/Documentation:
2
5
  Enabled: false
3
6
 
7
+ Style/GuardClause:
8
+ Enabled: false
9
+
4
10
  LineLength:
5
11
  Max: 130
6
12
 
data/example/Gemfile.lock CHANGED
@@ -12,10 +12,10 @@ GEM
12
12
  coderay (1.1.1)
13
13
  debug_inspector (0.0.2)
14
14
  digest-crc (0.4.1)
15
- dotenv (2.1.2)
15
+ dotenv (2.2.0)
16
16
  faraday (0.11.0)
17
17
  multipart-post (>= 1.2, < 3)
18
- google-api-client (0.9.20)
18
+ google-api-client (0.9.28)
19
19
  addressable (~> 2.3)
20
20
  googleauth (~> 0.5)
21
21
  httpclient (~> 2.7)
@@ -66,7 +66,7 @@ GEM
66
66
  logging (2.1.0)
67
67
  little-plugger (~> 1.1)
68
68
  multi_json (~> 1.10)
69
- magellan-gcs-proxy (0.3.1)
69
+ magellan-gcs-proxy (0.3.2)
70
70
  dotenv
71
71
  google-cloud-logging
72
72
  google-cloud-storage
@@ -9,6 +9,9 @@ require 'logger_pipe'
9
9
  module Magellan
10
10
  module Gcs
11
11
  module Proxy
12
+ class BuildError < StandardError
13
+ end
14
+
12
15
  class Cli
13
16
  include Log
14
17
 
@@ -35,30 +38,67 @@ module Magellan
35
38
  verbose("Backtrace\n " << e.backtrace.join("\n "))
36
39
  end
37
40
 
38
- TOTAL = 14
41
+ PROCESSING = 1
42
+ DOWNLOADING = 2
43
+ DOWNLOAD_OK = 3
44
+ DOWNLOAD_ERROR = 4
45
+ EXECUTING = 5
46
+ EXECUTE_OK = 6
47
+ EXECUTE_ERROR = 7
48
+ UPLOADING = 8
49
+ UPLOAD_OK = 9
50
+ UPLOAD_ERROR = 10
51
+ ACKSENDING = 11
52
+ ACKSEND_OK = 12
53
+ ACKSEND_ERROR = 13
54
+ CLEANUP = 14
55
+
56
+ TOTAL = CLEANUP
57
+
39
58
  def process(msg)
40
59
  context = Context.new(msg)
41
- context.notify(1, TOTAL, "Processing message: #{msg.inspect}")
60
+ context.notify(PROCESSING, TOTAL, "Processing message: #{msg.inspect}")
42
61
  context.setup do
43
- context.process_with_notification([2, 3, 4], TOTAL, 'Download', &:download)
62
+ context.process_with_notification([DOWNLOADING, DOWNLOAD_OK, DOWNLOAD_ERROR], TOTAL, 'Download', &:download)
44
63
 
45
- cmd = build_command(context)
64
+ cmd = build_command_with_error(context)
65
+ return unless cmd
46
66
 
47
67
  exec = ->(*) { LoggerPipe.run(logger, cmd, returns: :none, logging: :both, dry_run: Proxy.config[:dryrun]) }
48
- context.process_with_notification([5, 6, 7], TOTAL, 'Command', exec) do
49
- context.process_with_notification([8, 9, 10], TOTAL, 'Upload', &:upload)
68
+ context.process_with_notification([EXECUTING, EXECUTE_OK, EXECUTE_ERROR], TOTAL, 'Command', exec) do
69
+ context.process_with_notification([UPLOADING, UPLOAD_OK, UPLOAD_ERROR], TOTAL, 'Upload', &:upload)
50
70
 
51
- context.process_with_notification([11, 12, 13], TOTAL, 'Acknowledge') do
71
+ context.process_with_notification([ACKSENDING, ACKSEND_OK, ACKSEND_ERROR], TOTAL, 'Acknowledge') do
52
72
  msg.acknowledge!
53
73
  end
54
74
  end
55
75
  end
56
- context.notify(14, TOTAL, 'Cleanup')
76
+ context.notify(CLEANUP, TOTAL, 'Cleanup')
77
+ end
78
+
79
+ def build_command_with_error(context)
80
+ return build_command(context)
81
+ rescue BuildError => e
82
+ err = "[#{e.class.name}] #{e.message} with message: #{context.message.inspect}, the message will be acknowledged"
83
+ context.notify(EXECUTE_ERROR, TOTAL, e.message)
84
+ logger.error(err)
85
+ context.message.acknowledge! # Send ACK not to process this message again
86
+ return nil
57
87
  end
58
88
 
59
89
  def build_command(context)
60
90
  msg_wrapper = MessageWrapper.new(context)
61
- ExpandVariable.expand_variables(cmd_template, msg_wrapper)
91
+ r = ExpandVariable.expand_variables(cmd_template, msg_wrapper)
92
+ if commands = Proxy.config[:commands]
93
+ if template = commands[r]
94
+ msg_wrapper = MessageWrapper.new(context)
95
+ return ExpandVariable.expand_variables(template, msg_wrapper)
96
+ else
97
+ raise BuildError, "Invalid command key #{r.inspect} was given"
98
+ end
99
+ else
100
+ return r
101
+ end
62
102
  end
63
103
  end
64
104
  end
@@ -44,11 +44,19 @@ module Magellan
44
44
 
45
45
  case value
46
46
  when String then quote_string ? value.to_s : value
47
- when Array then value.flatten.join(' ')
47
+ when Array, Hash then flatten(value).join(' ')
48
48
  else value.to_s
49
49
  end
50
50
  end
51
51
  end
52
+
53
+ def flatten(obj)
54
+ case obj
55
+ when Array then obj.map { |i| flatten(i) }
56
+ when Hash then flatten(obj.values)
57
+ else obj
58
+ end
59
+ end
52
60
  end
53
61
  end
54
62
  end
@@ -1,7 +1,7 @@
1
1
  module Magellan
2
2
  module Gcs
3
3
  module Proxy
4
- VERSION = '0.3.1'.freeze
4
+ VERSION = '0.3.2'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-gcs-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-24 00:00:00.000000000 Z
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv