awsprofile 0.0.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/awsprofile.rb +38 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43443a46a2df7cd95718a4286adcd9698f749b96
4
+ data.tar.gz: 497f3e82a604b6f9a92a6565f81e983d0368d8c5
5
+ SHA512:
6
+ metadata.gz: cc71cff392082de3ce365db4613891b4036d52ae51a9b1f08ab8705fb7fb1c4d223f9e3084c547443ddbf704d47c874242f06a21a75cae7e6d121ce90978d3f0
7
+ data.tar.gz: bc932e8df1a15b2fd7ee2cc5ab7d86139b40b4308201324a41915d6f3748373c0e5a3b6e8e6561fb32cae994695daa4706cc9bed5e691b5b2d01bb6f2bc82509
data/lib/awsprofile.rb ADDED
@@ -0,0 +1,38 @@
1
+ # Class/methods to load AWS profile and provide credentials
2
+ require 'parseconfig'
3
+ require 'open-uri'
4
+
5
+ class Awsprofile
6
+ def initialize(profilename)
7
+ # Exception for using roles, this can probably be done via automatic detection
8
+ # But this is nice and simple
9
+ if profilename == "role"
10
+ # Get the current region from the metadata service
11
+ @config["region"] = open("http://169.254.169.254/latest/meta-data/placement/availability-zone").each.first(1)[0][0..-2]
12
+ else
13
+ # Look for the files and load the profile into variables
14
+ @config = ParseConfig.new(ENV['HOME'] + "/.aws/config")
15
+
16
+ # Make sure we have the profile we're looking for
17
+ if @config["profile " + profilename].nil?
18
+ raise "Profile #{profilename} not found."
19
+ else
20
+ @config = @config["profile " + profilename]
21
+ end
22
+
23
+ # Now handle the credentials and stick them into the same @config variable
24
+ credentials = ParseConfig.new(ENV['HOME'] + "/.aws/credentials")
25
+
26
+ if credentials[profilename].nil?
27
+ raise "Credentials not found for #{profilename}."
28
+ else
29
+ @config = @config.merge(credentials[profilename])
30
+ end
31
+ end
32
+ end
33
+
34
+ def config
35
+ return @config
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awsprofile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitriy M
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple class to automate AWS profile loading
14
+ email: dmitriy.mar@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/awsprofile.rb
20
+ homepage: http://rubygems.org/gems/awsprofile
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.14
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: AWS profile reading class
44
+ test_files: []