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 +4 -4
- data/.rubocop.yml +6 -0
- data/example/Gemfile.lock +3 -3
- data/lib/magellan/gcs/proxy/cli.rb +49 -9
- data/lib/magellan/gcs/proxy/expand_variable.rb +9 -1
- data/lib/magellan/gcs/proxy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b318e66fc008a5c8b62110610219509a0b32edf
|
4
|
+
data.tar.gz: 15d802d7b358ea6f8a6be0802c038372ea7eda28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c682dcf84498989de79b73208ac2481196e6900e303d7028bb8b385f5a165046769359ccf5b550d8209220c0d535286cd7611581b8de64e2229ebe8ff4411439
|
7
|
+
data.tar.gz: eb9f9661ce1afa3517f77c7abb76c8e52fa3e43a16da1157d17b5d9a9212a40546aec23feeda79cbbfb6ce6942737c3ea5dc0b6500b1a71d067d2a2f3a3452ae
|
data/.rubocop.yml
CHANGED
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.
|
15
|
+
dotenv (2.2.0)
|
16
16
|
faraday (0.11.0)
|
17
17
|
multipart-post (>= 1.2, < 3)
|
18
|
-
google-api-client (0.9.
|
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.
|
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
|
-
|
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(
|
60
|
+
context.notify(PROCESSING, TOTAL, "Processing message: #{msg.inspect}")
|
42
61
|
context.setup do
|
43
|
-
context.process_with_notification([
|
62
|
+
context.process_with_notification([DOWNLOADING, DOWNLOAD_OK, DOWNLOAD_ERROR], TOTAL, 'Download', &:download)
|
44
63
|
|
45
|
-
cmd =
|
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([
|
49
|
-
context.process_with_notification([
|
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([
|
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(
|
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.
|
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
|
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.
|
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-
|
11
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|