aws_cli_wrapper 0.1.0 → 0.2.0
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/lib/aws_cli_wrapper.rb +43 -32
- 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: f3dc6339114c3c685a2df14e4ef74b72a50cfb3d
|
|
4
|
+
data.tar.gz: 557c41d9fd2d76cee4959d7d6e7c0ae32ed4335e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aec5f15e10b1e95ab326464269dfe5796f66d7ef191b0039425a182fbdc2f2bb576b6d2ae8afb053fb0d3c8cd3ef88f88d297f7fcc613f5bfcbdb63f7472e70c
|
|
7
|
+
data.tar.gz: 2efe803368f0d75757d605e8c711193c4c500af67cbd7b0e94f3dde69872d0c7befd8ba6a00943ea42db3f4182f72adaf755ce4f247a4a4fd2767203fe42ac97
|
data/lib/aws_cli_wrapper.rb
CHANGED
|
@@ -2,49 +2,60 @@ require 'erb'
|
|
|
2
2
|
require 'tempfile'
|
|
3
3
|
require 'json'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
tmp.write(ERB.new(File.read(path)).result)
|
|
11
|
-
tmp.close # flush to disk
|
|
12
|
-
tmp.path
|
|
5
|
+
class AwsCliWrapper < Struct.new(:binding)
|
|
6
|
+
|
|
7
|
+
class Inner < Struct.new(:binding, :service)
|
|
8
|
+
def initialize(binding, service)
|
|
9
|
+
super(binding, _format_token(service))
|
|
13
10
|
end
|
|
14
|
-
end
|
|
15
11
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
s.to_s.gsub(/[ _]/, '-')
|
|
12
|
+
def method_missing(meth, *args)
|
|
13
|
+
_run(meth, *args)
|
|
19
14
|
end
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
def _erb(file)
|
|
17
|
+
path = "#{file}.json.erb"
|
|
18
|
+
if File.exists?(path)
|
|
19
|
+
tmp = Tempfile.new(file.gsub('/', '_') + '.json')
|
|
20
|
+
tmp.write(ERB.new(File.read(path)).result(binding))
|
|
21
|
+
tmp.close # flush to disk
|
|
22
|
+
tmp.path
|
|
23
|
+
end
|
|
24
|
+
end
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
opts['cli-input-json'] = 'file://' + path
|
|
26
|
+
def _format_token(s)
|
|
27
|
+
s.to_s.gsub(/[ _]/, '-')
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
opts.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
def _run(_command, _opts = {})
|
|
31
|
+
command = _format_token(_command)
|
|
32
|
+
opts = _opts.inject({}){|o,(k,v)| o.update(_format_token(k) => v) }
|
|
33
|
+
|
|
34
|
+
if file = opts.delete('json')
|
|
35
|
+
path = ((tmp = erb(file)) ? tmp : file + '.json')
|
|
36
|
+
opts['cli-input-json'] = 'file://' + path
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
sh = (
|
|
40
|
+
['aws', service, command] +
|
|
41
|
+
opts.map{|(k,v)| "--#{k} '#{v}'" }
|
|
42
|
+
) * ' '
|
|
43
|
+
puts sh
|
|
44
|
+
|
|
45
|
+
out = %x{#{sh}}
|
|
46
|
+
begin
|
|
47
|
+
JSON.parse(out)
|
|
48
|
+
rescue JSON::ParserError
|
|
49
|
+
out
|
|
50
|
+
end
|
|
40
51
|
end
|
|
41
52
|
end
|
|
42
53
|
|
|
43
|
-
%w( opsworks ec2 elb rds elasticache s3api cloudfront ).each do |
|
|
44
|
-
define_method(
|
|
45
|
-
|
|
54
|
+
%w( opsworks ec2 elb rds elasticache s3api cloudfront ).each do |service|
|
|
55
|
+
define_method(service) do |command = nil, opts = {}|
|
|
56
|
+
i = Inner.new(binding, service)
|
|
57
|
+
command ? i._run(command, opts) : i
|
|
46
58
|
end
|
|
47
59
|
end
|
|
48
60
|
|
|
49
|
-
extend self
|
|
50
61
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aws_cli_wrapper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Pabst
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-10-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email: michael.k.pabst@gmail.com
|