aws-profile_parser 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e691e46e5a2aa76a5edcc2394ef56d4425dfa290
4
+ data.tar.gz: 42988ff662413b11b8f57387fda1f51aae461139
5
+ SHA512:
6
+ metadata.gz: 8a29484e6817a39c40ffd3f631ab9e259849b6d565790f465aa370b8880b0547deea643a0eb5505ce387cb9b698f371d87bc2150c4208f4e8b2b225fd550cba5
7
+ data.tar.gz: b638d65d7e9586e753414769d3c630def899d8784abe2db89d56d841a68ff7c6d566558c0a612c005914663d388504173d569eb08d52aa3b105e6dbc248a69a4
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aws-profile_parser.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Masao Mochizuki
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # Aws::ProfileParser
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ gem 'aws-profileparser'
6
+
7
+ And then execute:
8
+
9
+ $ bundle
10
+
11
+ Or install it yourself as:
12
+
13
+ $ gem install aws-profileparser
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem 'aws-profile_parser'
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install aws-profile_parser
28
+
29
+ ## Usage
30
+
31
+ You have to set ENV['AWS_CONFIG_FILE'] beofre using this gem.
32
+
33
+ $ export AWS_CONFIG_FILE=/path/to/your/config
34
+
35
+ And write simple code as below.
36
+
37
+ ```ruby
38
+
39
+ require 'aws-profile_parser'
40
+ require 'aws-sdk'
41
+
42
+ ARGV.options do |opt|
43
+ profile = default
44
+ opt.on('--profile PROFILE') { |v| profile = v}
45
+ opt.parse!
46
+
47
+ parser = ProfileParser.new
48
+ options = parser.get(profile)
49
+
50
+ AWS.config(options)
51
+ end
52
+
53
+ ```
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( https://github.com/masaomoc/aws-profile_parser/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aws/profile_parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aws-profile_parser"
8
+ spec.version = AWS::ProfileParser::VERSION
9
+ spec.authors = ["Masao Mochizuki"]
10
+ spec.email = ["masaomoc.0301988@gmail.com"]
11
+ spec.summary = %q{Parse AWS CLI $AWS_CONFIG_FILE setting in Ruby}
12
+ spec.description = %q{Parse AWS CLI $AWS_CONFIG_FILE setting in Ruby}
13
+ spec.homepage = "https://github.com/masaomoc/aws-profile_parser/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,44 @@
1
+ require "aws/profile_parser/version"
2
+
3
+ module AWS
4
+ class ProfileParser
5
+
6
+ def initialize
7
+ @file = ENV['AWS_CONFIG_FILE']
8
+ @credentials = nil
9
+ end
10
+
11
+ # returns hash of AWS credential
12
+ def get(profile='default')
13
+ raise 'Config File does not exist' unless File.exists?(@file)
14
+
15
+ @credentials = parse if @credentials.nil?
16
+ raise 'The profile is not specified in the config file' unless @credentials.has_key?(profile)
17
+
18
+ @credentials[profile]
19
+ end
20
+
21
+ def parse
22
+ section = { "" => {} }
23
+ current = {}
24
+ s = StringScanner.new(File.read(@file))
25
+
26
+ while !s.eos?
27
+ case
28
+ when s.scan(/\s+/)
29
+ # do nothing
30
+ when s.scan(/\[(profile\s+)?(.+?)\]/)
31
+ # strip 'profile' from each profile key and set to section key
32
+ section[s[2]] = current = {}
33
+ when s.scan(/(\w+)\s*=\s*([^\n]+)/)
34
+ # strip 'aws_' from each key
35
+ current[s[1].sub(/^aws_/, '').to_sym] = s[2]
36
+ else
37
+ raise "Parse Error. I guess config file syntax is something wrong."
38
+ end
39
+ end
40
+
41
+ @credentials = section
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module AWS
2
+ class ProfileParser
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe AWS::ProfileParser do
4
+
5
+ it 'has a version number' do
6
+ expect(AWS::ProfileParser::VERSION).not_to be nil
7
+ end
8
+
9
+ end
10
+
11
+ describe "ProfileParser" do
12
+
13
+ before :all do
14
+ ENV['AWS_CONFIG_FILE'] = File.dirname(__FILE__) + "/../data/awsconfig.sample"
15
+ @parser = AWS::ProfileParser.new
16
+ end
17
+
18
+ it 'should have the default config file' do
19
+ expect(File.exists?(ENV['AWS_CONFIG_FILE'])).to be_true
20
+ end
21
+
22
+ it 'should return Hash' do
23
+ expect(@parser.get('default')).to be_a(Hash)
24
+ end
25
+
26
+ it 'should have keys' do
27
+ option = @parser.get('default')
28
+ expect(option).to have_key(:access_key_id)
29
+ expect(option).to have_key(:secret_access_key)
30
+ expect(option).to have_key(:region)
31
+ end
32
+
33
+ end
@@ -0,0 +1,9 @@
1
+ [default]
2
+ aws_access_key_id = AKIAXXXXXXXXXXXXX
3
+ aws_secret_access_key = yyyyyyyyyyyyyyy
4
+ region = us-east-1
5
+
6
+ [profile foobar]
7
+ aws_access_key_id = AKIAYYYYYYYYYYYYYY
8
+ aws_secret_access_key = 23563423hhhhhh
9
+ region = ap-northeast-1
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'aws/profile_parser'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-profile_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masao Mochizuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Parse AWS CLI $AWS_CONFIG_FILE setting in Ruby
56
+ email:
57
+ - masaomoc.0301988@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - .travis.yml
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - aws-profile_parser.gemspec
70
+ - lib/aws/profile_parser.rb
71
+ - lib/aws/profile_parser/version.rb
72
+ - spec/aws/profile_parser_spec.rb
73
+ - spec/data/awsconfig.sample
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/masaomoc/aws-profile_parser/
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Parse AWS CLI $AWS_CONFIG_FILE setting in Ruby
99
+ test_files:
100
+ - spec/aws/profile_parser_spec.rb
101
+ - spec/data/awsconfig.sample
102
+ - spec/spec_helper.rb