thor-aws 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: 634180d416277d86f63e90d24bba4424fecf6990
4
+ data.tar.gz: aa388aee4b73137e61d396dbc6968295a9093882
5
+ SHA512:
6
+ metadata.gz: acb35e7a549f3a9466ee524c063aca4ba52efb8babb181f7d7c0eadd1d479b1e8fcde84498e428aefb2971f57db6e9722bfeccc40ade6ef1472e122278a4a690
7
+ data.tar.gz: 03d76cd1ffe979e8cb21d1c0267f22bb1a0d8c64eb57cab0e30ce57424db313e5eb22679d55f315f75468133f658cbbdb8ae6e51bafe5e4e7f7796bf62f9dd39
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in thor-aws.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 y13i
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,54 @@
1
+ # Thor::Aws
2
+
3
+ Thor extension for building CLI to deal with AWS.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'thor-aws'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```sh
22
+ $ gem install thor-aws
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Just add `include Thor::Aws` to your CLI class. Then you can use private methods such as `#ec2` or `#rds` to call a instance of `Aws::EC2::Resource` or so in your CLI.
28
+
29
+ Also, `--access-key-id`, `--secret-access-key`, `--region` and `--profile` options will be added to your CLI (of course, these credentials are used by Aws clients).
30
+
31
+ ## Example
32
+
33
+ ```ruby
34
+ require "thor"
35
+ require "thor/aws"
36
+
37
+ class MyAwsCLI < Thor
38
+ include Thor::Aws
39
+
40
+ desc :list, "Show list of EC2 instance"
41
+
42
+ def list
43
+ p ec2.instances.to_a
44
+ end
45
+ end
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. [Fork it](https://github.com/y13i/thor-aws/fork)
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 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,107 @@
1
+ require "thor"
2
+ require "thor/aws/version"
3
+ require "aws-sdk"
4
+
5
+ module Thor::Aws
6
+ DEFAULT_REGION = "us-east-1"
7
+ DEFAULT_REGION_TIMEOUT = 3
8
+
9
+ def self.included klass
10
+ klass.class_eval do
11
+ class_option(:profile,
12
+ desc: "Load credentials by profile name from shared credentials file (~/.aws/credentials).",
13
+ aliases: [:p],
14
+ )
15
+
16
+ class_option(:access_key_id,
17
+ desc: "AWS access key id.",
18
+ aliases: [:k],
19
+ )
20
+
21
+ class_option(:secret_access_key,
22
+ desc: "AWS secret access key.",
23
+ aliases: [:s],
24
+ )
25
+
26
+ class_option(:region,
27
+ desc: "AWS region.",
28
+ aliases: [:r],
29
+ )
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def aws_configuration
36
+ hash = {}
37
+
38
+ [:profile, :access_key_id, :secret_access_key, :region].each do |option|
39
+ hash.update(option => options[option]) if options[option]
40
+ end
41
+
42
+ hash.update(region: own_region) if hash[:region].nil? && ENV["AWS_REGION"].nil?
43
+ hash
44
+ end
45
+
46
+ def own_region
47
+ @own_region ||= begin
48
+ require "net/http"
49
+
50
+ timeout DEFAULT_REGION_TIMEOUT do
51
+ Net::HTTP.get("169.254.169.254", "/latest/meta-data/placement/availability-zone").chop
52
+ end
53
+ rescue
54
+ DEFAULT_REGION
55
+ end
56
+ end
57
+
58
+ {
59
+ autoscaling: Aws::AutoScaling::Resource,
60
+ cloudformation: Aws::CloudFormation::Resource,
61
+ cloudfront: Aws::CloudFront::Resource,
62
+ cloudhsm: Aws::CloudHSM::Resource,
63
+ cloudsearch: Aws::CloudSearch::Resource,
64
+ # cloudsearchdomain: Aws::CloudSearchDomain::Resource, # Pending 'cause '`missing required option :endpoint`
65
+ cloudtrail: Aws::CloudTrail::Resource,
66
+ cloudwatch: Aws::CloudWatch::Resource,
67
+ cloudwatchlogs: Aws::CloudWatchLogs::Resource,
68
+ codedeploy: Aws::CodeDeploy::Resource,
69
+ cognitoidentity: Aws::CognitoIdentity::Resource,
70
+ cognitosync: Aws::CognitoSync::Resource,
71
+ configservice: Aws::ConfigService::Resource,
72
+ datapipeline: Aws::DataPipeline::Resource,
73
+ directconnect: Aws::DirectConnect::Resource,
74
+ dynamodb: Aws::DynamoDB::Resource,
75
+ ec2: Aws::EC2::Resource,
76
+ ecs: Aws::ECS::Resource,
77
+ elasticache: Aws::ElastiCache::Resource,
78
+ elasticbeanstalk: Aws::ElasticBeanstalk::Resource,
79
+ elasticloadbalancing: Aws::ElasticLoadBalancing::Resource,
80
+ elastictranscoder: Aws::ElasticTranscoder::Resource,
81
+ emr: Aws::EMR::Resource,
82
+ glacier: Aws::Glacier::Resource,
83
+ iam: Aws::IAM::Resource,
84
+ importexport: Aws::ImportExport::Resource,
85
+ kinesis: Aws::Kinesis::Resource,
86
+ kms: Aws::KMS::Resource,
87
+ lambda: Aws::Lambda::Resource,
88
+ opsworks: Aws::OpsWorks::Resource,
89
+ rds: Aws::RDS::Resource,
90
+ redshift: Aws::Redshift::Resource,
91
+ route53: Aws::Route53::Resource,
92
+ route53domains: Aws::Route53Domains::Resource,
93
+ s3: Aws::S3::Resource,
94
+ ses: Aws::SES::Resource,
95
+ simpledb: Aws::SimpleDB::Resource,
96
+ sns: Aws::SNS::Resource,
97
+ sqs: Aws::SQS::Resource,
98
+ storagegateway: Aws::StorageGateway::Resource,
99
+ sts: Aws::STS::Resource,
100
+ support: Aws::Support::Resource,
101
+ swf: Aws::SWF::Resource,
102
+ }.each do |name, klass|
103
+ define_method name do
104
+ klass.new aws_configuration
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,3 @@
1
+ module Thor::Aws
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'thor/aws'
@@ -0,0 +1,12 @@
1
+ require "thor"
2
+ require "thor/aws"
3
+
4
+ class MyAwsCLI < Thor
5
+ include Thor::Aws
6
+
7
+ desc :list, "Show list of EC2 instance"
8
+
9
+ def list
10
+ p ec2.instances.to_a
11
+ end
12
+ end
@@ -0,0 +1,72 @@
1
+ require_relative "my_aws_cli"
2
+
3
+ describe MyAwsCLI do
4
+ it "is a instance of the class which has a superclass Thor" do
5
+ expect(subject.class.superclass).to be Thor
6
+ end
7
+
8
+ it "is a instance of the class including Thor::Aws" do
9
+ expect(subject.class.included_modules).to include Thor::Aws
10
+ end
11
+
12
+ {
13
+ autoscaling: Aws::AutoScaling::Resource,
14
+ cloudformation: Aws::CloudFormation::Resource,
15
+ cloudfront: Aws::CloudFront::Resource,
16
+ cloudhsm: Aws::CloudHSM::Resource,
17
+ cloudsearch: Aws::CloudSearch::Resource,
18
+ # cloudsearchdomain: Aws::CloudSearchDomain::Resource,
19
+ cloudtrail: Aws::CloudTrail::Resource,
20
+ cloudwatch: Aws::CloudWatch::Resource,
21
+ cloudwatchlogs: Aws::CloudWatchLogs::Resource,
22
+ codedeploy: Aws::CodeDeploy::Resource,
23
+ cognitoidentity: Aws::CognitoIdentity::Resource,
24
+ cognitosync: Aws::CognitoSync::Resource,
25
+ configservice: Aws::ConfigService::Resource,
26
+ datapipeline: Aws::DataPipeline::Resource,
27
+ directconnect: Aws::DirectConnect::Resource,
28
+ dynamodb: Aws::DynamoDB::Resource,
29
+ ec2: Aws::EC2::Resource,
30
+ ecs: Aws::ECS::Resource,
31
+ elasticache: Aws::ElastiCache::Resource,
32
+ elasticbeanstalk: Aws::ElasticBeanstalk::Resource,
33
+ elasticloadbalancing: Aws::ElasticLoadBalancing::Resource,
34
+ elastictranscoder: Aws::ElasticTranscoder::Resource,
35
+ emr: Aws::EMR::Resource,
36
+ glacier: Aws::Glacier::Resource,
37
+ iam: Aws::IAM::Resource,
38
+ importexport: Aws::ImportExport::Resource,
39
+ kinesis: Aws::Kinesis::Resource,
40
+ kms: Aws::KMS::Resource,
41
+ lambda: Aws::Lambda::Resource,
42
+ opsworks: Aws::OpsWorks::Resource,
43
+ rds: Aws::RDS::Resource,
44
+ redshift: Aws::Redshift::Resource,
45
+ route53: Aws::Route53::Resource,
46
+ route53domains: Aws::Route53Domains::Resource,
47
+ s3: Aws::S3::Resource,
48
+ ses: Aws::SES::Resource,
49
+ simpledb: Aws::SimpleDB::Resource,
50
+ sns: Aws::SNS::Resource,
51
+ sqs: Aws::SQS::Resource,
52
+ storagegateway: Aws::StorageGateway::Resource,
53
+ sts: Aws::STS::Resource,
54
+ support: Aws::Support::Resource,
55
+ swf: Aws::SWF::Resource,
56
+ }.each do |name, klass|
57
+ it "has private method ##{name} that returns #{klass} instance" do
58
+ expect(subject.send name).to be_a klass
59
+ end
60
+ end
61
+
62
+ context "when invoked from shell" do
63
+ subject do
64
+ MyAwsCLI.new.help
65
+ end
66
+
67
+ it {expect {subject}.to output(/--access-key-id/).to_stdout}
68
+ it {expect {subject}.to output(/--secret-access-key/).to_stdout}
69
+ it {expect {subject}.to output(/--region/).to_stdout}
70
+ it {expect {subject}.to output(/--profile/).to_stdout}
71
+ end
72
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe Thor::Aws do
4
+ it "has a version number" do
5
+ expect(subject::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "thor"
5
+ require "thor/aws/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "thor-aws"
9
+ spec.version = Thor::Aws::VERSION
10
+ spec.authors = ["y13i"]
11
+ spec.email = ["email@y13i.com"]
12
+ spec.summary = %(Thor += AWS)
13
+ spec.description = %(Thor extension for building CLI to deal with AWS.)
14
+ spec.homepage = "https://github.com/y13i/thor-aws"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "pry"
26
+
27
+ spec.add_dependency "thor"
28
+ spec.add_dependency "aws-sdk"
29
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thor-aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - y13i
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-11 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: aws-sdk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Thor extension for building CLI to deal with AWS.
98
+ email:
99
+ - email@y13i.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/thor/aws.rb
112
+ - lib/thor/aws/version.rb
113
+ - spec/spec_helper.rb
114
+ - spec/thor/aws/my_aws_cli.rb
115
+ - spec/thor/aws/my_aws_cli_spec.rb
116
+ - spec/thor/aws_spec.rb
117
+ - thor-aws.gemspec
118
+ homepage: https://github.com/y13i/thor-aws
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.5
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Thor += AWS
142
+ test_files:
143
+ - spec/spec_helper.rb
144
+ - spec/thor/aws/my_aws_cli.rb
145
+ - spec/thor/aws/my_aws_cli_spec.rb
146
+ - spec/thor/aws_spec.rb