ec2select 0.0.2

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Brian Kaney
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,57 @@
1
+ = ec2-select
2
+
3
+ A little command line script to switch between multiple EC2 profiles.
4
+
5
+ == Install
6
+
7
+ Setup gemcutter as a source (http://gemcutter.org) and:
8
+
9
+ $ gem install ec2-select
10
+
11
+
12
+ == Usage
13
+
14
+ Add this line to your ~/.profile (or ~/.bashrc) or whatever
15
+
16
+ source ~/.ec2-select
17
+
18
+ Then run the command:
19
+
20
+ $ ec2-select [profile]
21
+
22
+ Where profile is the name of the EC2 profile you want to use. If
23
+ you run ec2-select without any arguments, the current profile is returned.
24
+
25
+ You can set and environment EC2_PEMFILES to whatever you want. This should
26
+ be the path where you are going to store all your private key and cert files.
27
+
28
+ The command writes a file ~/.ec2-select with the paths to the appropiate pem key
29
+ and cert.
30
+
31
+
32
+ == Profiles
33
+
34
+ Profiles are defined by the names of your private key and cert from Amazon.
35
+ Each has to be named consistently. For example:
36
+
37
+ $EC2_PEMFILES/floog-pk.pem
38
+ $EC2_PEMFILES/floog-cert.pem
39
+
40
+ Would set EC2_PRIVATE_KEY to floog-pk.pem and EC2_CERT to floog-cert.pem when you run
41
+ the following:
42
+
43
+ $ ec2-select floog
44
+
45
+ == Note on Patches/Pull Requests
46
+
47
+ * Fork the project.
48
+ * Make your feature addition or bug fix.
49
+ * Add tests for it. This is important so I don't break it in a
50
+ future version unintentionally.
51
+ * Commit, do not mess with rakefile, version, or history.
52
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
53
+ * Send me a pull request. Bonus points for topic branches.
54
+
55
+ == Copyright
56
+
57
+ Copyright (c) 2009 Brian Kaney. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ec2select"
8
+ gem.summary = %Q{Command-line tool to switch EC2 environments}
9
+ gem.description = %Q{Resets your env EC2 variables via a quick command-line.}
10
+ gem.email = "brian@vermonster.com"
11
+ gem.homepage = "http://github.com/bkaney/ec2-select"
12
+ gem.authors = ["Brian Kaney"]
13
+ gem.add_development_dependency "minitest"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ if File.exist?('VERSION')
47
+ version = File.read('VERSION')
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "ec2select #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
data/bin/ec2-select ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib ])
4
+
5
+ require 'ec2_select'
6
+ include Ec2Select
7
+
8
+ begin
9
+ response = Ec2Select.rewrite_or_show(ARGV.first)
10
+ puts response
11
+ rescue
12
+ $stderr.puts "ERROR: #{$!}"
13
+ end
data/bin/ec2select ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.dirname(__FILE__) + '/ec2-select'
4
+
data/ec2select.gemspec ADDED
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ec2select}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brian Kaney"]
12
+ s.date = %q{2009-10-07}
13
+ s.description = %q{Resets your env EC2 variables via a quick command-line.}
14
+ s.email = %q{brian@vermonster.com}
15
+ s.executables = ["ec2-select", "ec2select"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bin/ec2-select",
28
+ "bin/ec2select",
29
+ "ec2select.gemspec",
30
+ "lib/ec2_select.rb",
31
+ "test/ec2-select_test.rb",
32
+ "test/test_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/bkaney/ec2-select}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Command-line tool to switch EC2 environments}
39
+ s.test_files = [
40
+ "test/ec2-select_test.rb",
41
+ "test/test_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<minitest>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<minitest>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<minitest>, [">= 0"])
55
+ end
56
+ end
data/lib/ec2_select.rb ADDED
@@ -0,0 +1,77 @@
1
+ module Ec2Select
2
+
3
+ class NoEctwoFile < StandardError; end;
4
+
5
+ ECTWOS_FILE = File.expand_path('~/.ec2-select')
6
+
7
+ def rewrite_or_show(profile=nil)
8
+ return show if profile.nil?
9
+ rewrite(profile) and show unless profile.nil?
10
+ end
11
+
12
+ def show
13
+ current = ENV['EC2_PRIVATE_KEY'].gsub(/.*pk-(.*)\.pem$/, '\\1')
14
+ "Your current profile is: #{current}"
15
+ end
16
+
17
+ def pempath
18
+ ENV['EC2_PEMFILES'] ? File.expand_path(ENV['EC2_PEMFILES']) : File.expand_path('~/.ec2')
19
+ end
20
+
21
+ def shell
22
+ unless const_defined? 'SHELL'
23
+ begin
24
+ require File.expand_path('~/.ec2-select')
25
+ rescue LoadError
26
+ const_set("SHELL", 'bash')
27
+ end
28
+ end
29
+ SHELL
30
+ end
31
+
32
+ def private_key(profile)
33
+ "#{pempath}/pk-#{profile}.pem"
34
+ end
35
+
36
+ def cert(profile)
37
+ "#{pempath}/cert-#{profile}.pem"
38
+ end
39
+
40
+ def rewrite(profile)
41
+ # Validation
42
+ if profile !~ /[A-Za-z0-9\.\-_~+=]/
43
+ raise "Uh Oh! Profile can only have valid filename characters!"
44
+ end
45
+ if !File.exist? private_key(profile)
46
+ raise "Private key #{private_key(profile)} does not exist!"
47
+ end
48
+ if !File.exist? cert(profile)
49
+ raise "Cert #{cert(profile)} does not exist!"
50
+ end
51
+
52
+ # Content
53
+ content = "# Dynamically created by ec2-select\n"
54
+ content << "# Currently PROFILE=#{profile}\n\n"
55
+ content << case shell
56
+ when /bash|.?sh/
57
+ "export EC2_PRIVATE_KEY=\"#{private_key(profile)}\"\n" +
58
+ "export EC2_CERT=\"#{cert(profile)}\"\n"
59
+ when /.?csh/
60
+ "setenv EC2_PRIVATE_KEY \"#{private_key(profile)}\"\n" +
61
+ "setenv EC2_CERT \"#{cert(profile)}\"\n"
62
+ else
63
+ $stderr.puts "Unknown shell `#{shell}'"
64
+ exit 1
65
+ end
66
+
67
+ File.open(ECTWOS_FILE, 'w') {|f| f.write(content) }
68
+
69
+ "IMPORTANT!!! You need re-source if you want to use #{profile}" +
70
+ "in this terminal session! This should do the trick:" +
71
+ "\n source #{ECTWOS_FILE}\n\n" +
72
+ "Any new terminal sessions will use this profile as long as you" +
73
+ "have 'source #{ECTWOS_FILE}' in your ~/.profile or" +
74
+ "~/.bashrc, ~/.bash_profile (or similar)."
75
+ end
76
+
77
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class Ec2SelectTest < Mini::Test::TestCase
4
+ def test_show
5
+ assert Ec2Select.show =~ /foob/
6
+ end
7
+
8
+ def test_rewrite_or_show
9
+ assert_equal Ec2Select.rewrite_or_show, Ec2Select.show, "should show with no params"
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'mini/test'
3
+ require 'mocha'
4
+
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ require 'ec2_select'
9
+ include Ec2Select
10
+
11
+ class Mini::Test::TestCase
12
+ def setup
13
+ ENV['EC2_PRIVATE_KEY'] = 'pk-foob.pem'
14
+ ENV['EC2_CERT'] = 'cert-foob.pem'
15
+ end
16
+ end
17
+
18
+ Mini::Test.autorun
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ec2select
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Brian Kaney
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-07 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: minitest
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Resets your env EC2 variables via a quick command-line.
26
+ email: brian@vermonster.com
27
+ executables:
28
+ - ec2-select
29
+ - ec2select
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ - README.rdoc
35
+ files:
36
+ - .document
37
+ - .gitignore
38
+ - LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - bin/ec2-select
43
+ - bin/ec2select
44
+ - ec2select.gemspec
45
+ - lib/ec2_select.rb
46
+ - test/ec2-select_test.rb
47
+ - test/test_helper.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/bkaney/ec2-select
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Command-line tool to switch EC2 environments
76
+ test_files:
77
+ - test/ec2-select_test.rb
78
+ - test/test_helper.rb