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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/aws_cli_wrapper.rb +43 -32
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7245ce854b5b4d40376fe587718c4b99800313f8
4
- data.tar.gz: 108abd1520c872659fa4612398be5dafc7e2e096
3
+ metadata.gz: f3dc6339114c3c685a2df14e4ef74b72a50cfb3d
4
+ data.tar.gz: 557c41d9fd2d76cee4959d7d6e7c0ae32ed4335e
5
5
  SHA512:
6
- metadata.gz: 7d44a026e4624f60ddb91e9da847987d83bab446497e290b8c617d52546263b9e2f6bd98826b6a66ad71eafdc60da83ae615d670d55583197726596d9f985e40
7
- data.tar.gz: 3d1a1e119dfc5852f6814fbe6ac77596e54073cd087ac12b3b1473a305eb1e025971ade3e57a835c790d88fcd7e918ec927e6670528a3bb54c83518426431fbc
6
+ metadata.gz: aec5f15e10b1e95ab326464269dfe5796f66d7ef191b0039425a182fbdc2f2bb576b6d2ae8afb053fb0d3c8cd3ef88f88d297f7fcc613f5bfcbdb63f7472e70c
7
+ data.tar.gz: 2efe803368f0d75757d605e8c711193c4c500af67cbd7b0e94f3dde69872d0c7befd8ba6a00943ea42db3f4182f72adaf755ce4f247a4a4fd2767203fe42ac97
@@ -2,49 +2,60 @@ require 'erb'
2
2
  require 'tempfile'
3
3
  require 'json'
4
4
 
5
- module AwsCliWrapper
6
- def erb(file)
7
- path = "#{file}.json.erb"
8
- if File.exists?(path)
9
- tmp = Tempfile.new(file.gsub('/', '_') + '.json')
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
- def run(_scope, _command, _opts = {})
17
- def fmt(s)
18
- s.to_s.gsub(/[ _]/, '-')
12
+ def method_missing(meth, *args)
13
+ _run(meth, *args)
19
14
  end
20
15
 
21
- scope, command = *[_scope, _command].map{|p| fmt(p) }
22
- opts = _opts.inject({}){|o,(k,v)| o.update(fmt(k) => v) }
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
- if file = opts.delete('json')
25
- path = ((tmp = erb(file)) ? tmp : file + '.json')
26
- opts['cli-input-json'] = 'file://' + path
26
+ def _format_token(s)
27
+ s.to_s.gsub(/[ _]/, '-')
27
28
  end
28
29
 
29
- sh = (
30
- ['aws', scope, command] +
31
- opts.map{|(k,v)| "--#{k} '#{v}'" }
32
- ) * ' '
33
- puts sh
34
-
35
- out = %x{#{sh}}
36
- begin
37
- JSON.parse(out)
38
- rescue JSON::ParserError
39
- out
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 |svc|
44
- define_method(svc) do |cmd, opts = {}|
45
- run(cmd, opts)
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.1.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-09-26 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael.k.pabst@gmail.com