aws_cli_wrapper 0.1.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 +7 -0
  2. data/lib/aws_cli_wrapper.rb +50 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7245ce854b5b4d40376fe587718c4b99800313f8
4
+ data.tar.gz: 108abd1520c872659fa4612398be5dafc7e2e096
5
+ SHA512:
6
+ metadata.gz: 7d44a026e4624f60ddb91e9da847987d83bab446497e290b8c617d52546263b9e2f6bd98826b6a66ad71eafdc60da83ae615d670d55583197726596d9f985e40
7
+ data.tar.gz: 3d1a1e119dfc5852f6814fbe6ac77596e54073cd087ac12b3b1473a305eb1e025971ade3e57a835c790d88fcd7e918ec927e6670528a3bb54c83518426431fbc
@@ -0,0 +1,50 @@
1
+ require 'erb'
2
+ require 'tempfile'
3
+ require 'json'
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
13
+ end
14
+ end
15
+
16
+ def run(_scope, _command, _opts = {})
17
+ def fmt(s)
18
+ s.to_s.gsub(/[ _]/, '-')
19
+ end
20
+
21
+ scope, command = *[_scope, _command].map{|p| fmt(p) }
22
+ opts = _opts.inject({}){|o,(k,v)| o.update(fmt(k) => v) }
23
+
24
+ if file = opts.delete('json')
25
+ path = ((tmp = erb(file)) ? tmp : file + '.json')
26
+ opts['cli-input-json'] = 'file://' + path
27
+ end
28
+
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
40
+ end
41
+ end
42
+
43
+ %w( opsworks ec2 elb rds elasticache s3api cloudfront ).each do |svc|
44
+ define_method(svc) do |cmd, opts = {}|
45
+ run(cmd, opts)
46
+ end
47
+ end
48
+
49
+ extend self
50
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws_cli_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Pabst
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: michael.k.pabst@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/aws_cli_wrapper.rb
20
+ homepage: http://github.com/mpabst/aws_cli_wrapper
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubyforge_project:
39
+ rubygems_version: 2.2.2
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Ruby wrapper around AWS CLI client, focusing on templatizing JSON parameter
43
+ files with ERb
44
+ test_files: []