shacho 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'heroku'
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.3.0"
7
+ gem "ruby-debug19"
8
+ gem "mocha"
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.6.4"
11
+ gem "rcov", ">= 0"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.6)
5
+ archive-tar-minitar (0.5.2)
6
+ columnize (0.3.4)
7
+ diff-lcs (1.1.3)
8
+ git (1.2.5)
9
+ heroku (2.9.0)
10
+ launchy (>= 0.3.2)
11
+ rest-client (~> 1.6.1)
12
+ rubyzip
13
+ term-ansicolor (~> 1.0.5)
14
+ jeweler (1.6.4)
15
+ bundler (~> 1.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ launchy (2.0.5)
19
+ addressable (~> 2.2.6)
20
+ linecache19 (0.5.12)
21
+ ruby_core_source (>= 0.1.4)
22
+ metaclass (0.0.1)
23
+ mime-types (1.16)
24
+ mocha (0.10.0)
25
+ metaclass (~> 0.0.1)
26
+ rake (0.9.2)
27
+ rcov (0.9.11)
28
+ rest-client (1.6.7)
29
+ mime-types (>= 1.16)
30
+ rspec (2.3.0)
31
+ rspec-core (~> 2.3.0)
32
+ rspec-expectations (~> 2.3.0)
33
+ rspec-mocks (~> 2.3.0)
34
+ rspec-core (2.3.1)
35
+ rspec-expectations (2.3.0)
36
+ diff-lcs (~> 1.1.2)
37
+ rspec-mocks (2.3.0)
38
+ ruby-debug-base19 (0.11.25)
39
+ columnize (>= 0.3.1)
40
+ linecache19 (>= 0.5.11)
41
+ ruby_core_source (>= 0.1.4)
42
+ ruby-debug19 (0.11.6)
43
+ columnize (>= 0.3.1)
44
+ linecache19 (>= 0.5.11)
45
+ ruby-debug-base19 (>= 0.11.19)
46
+ ruby_core_source (0.1.5)
47
+ archive-tar-minitar (>= 0.5.2)
48
+ rubyzip (0.9.4)
49
+ term-ansicolor (1.0.6)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (~> 1.0.0)
56
+ heroku
57
+ jeweler (~> 1.6.4)
58
+ mocha
59
+ rcov
60
+ rspec (~> 2.3.0)
61
+ ruby-debug19
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Kelly
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.md ADDED
@@ -0,0 +1,63 @@
1
+ ```
2
+ +++++++=++=+++====++====+==========+=============+=======+$ODD8ZD8D++++++++++++?
3
+ =++=~++=~~============================================++ID$$????77O8DD++=+++++++
4
+ ~+++$+===============================================?O8??++++++++???Z8+=?+?++++
5
+ ~+=+================================================I$$+??+++++++++???$D+=====+=
6
+ ~==================================================I7?I????+?++++?????777======+
7
+ ~==================================================$87III???+=+++++III78O=======
8
+ ===================================================$DZII??+++++++??+?IZDD=====+=
9
+ ===================================================$DO??III7I?$$8DDO7?7DZ=====+=
10
+ +==================================================8NIO8Z8DDDZZDD8O78Z?8O?======
11
+ +==================================================D8IOODDDN7??IZ7$8+ZI8Z:======
12
+ ===================================================8$I?+?7?I?++????I?$7Z$=======
13
+ ====?+==?7I~======~=,+~~=======~=,:=========+======:Z$Z$???ZI?+???++I$787=====DI
14
+ ====~NNN:$NND====.NNNDMNND====NDNNMNND===DNDMDND:===D7ZZI?IDDZZ88I?777IZ$=======
15
+ =====NNN===NNM==7NNM~===NNN~=.NN===~MD==MND====NM===8D$$ZI?7DDDD??I7I$I7========
16
+ =====NNN==MNN===NNN=====~NNN=:NNN~~==~~=NNN7=~=~?~====O7$7777I7?II?I77I=========
17
+ =====NNNNNND.==:NNN=~~===NNN==DNNNDN====:NNNNN.~======88$7+???+?+?7I77==========
18
+ =====NNN~=7NNN=~NNN==~~~=NNN~=~~NNNNNN====MNNNNN=====~ODOZ7Z$O$?$Z$Z88==~=====OI
19
+ =====NNN===DNN:=NND=~~~~,NND=,=~~~=NNN.======MNNN~~==ONDD8ZII7+?II$DD:~~~~~~~=?Z
20
+ =====NNN==~NNN~~.NNM=~~=NNM~~NN~~~~=NN:~NZ~~==DNN~==DM?7DDD888DD88DD??8:~~~~~=~I
21
+ ===$NNNNNNNNN==~=:NNNMDNND~=~INNM,,NNN=~NND~=~NNNNNNDM=?7$DDDDNND8D7?=888N:~~~:7
22
+ =========~~~~~~~~~~==,:=~~~~~~~:IDN.~$$7=~=Z8DZNNDDDDD===?$DDDDDD87+~=8888888O:$
23
+ =========~~~~~~~~~~~~~~~~~~~~~~~~~~~~IOO777$$ZOMDDNDDD=====7$NDN7=~~~=88888888~I
24
+ =======~~~~~=~~~~~~~~~~~~~~~~~~~~~~NDD877$7?IIIMDNDDDD=~=~~=DZ$7~~~~~88888O88O=I
25
+ =====~~~~=~~~=~~~~~~~~==~~~~~~~~~~DDDN$$?I??7ZDNDDDNDD:~~~~D$D$Z8:~~=O8O88888O=Z
26
+ ```
27
+
28
+ # what
29
+ A command-line utility that helps manage all your accounts and associated keys for heroku.
30
+
31
+ # why
32
+ A collection of bash scripts and heroku_plus wasn't cutting it for me. I like my utilities to be RESTy.
33
+
34
+ # installation
35
+
36
+ ```
37
+ gem install shacho
38
+ ```
39
+
40
+ # usage
41
+ ```
42
+ shacho action resource params
43
+ ```
44
+
45
+ Where `action` is one of the standard CRUDy actions:
46
+ - create
47
+ - use
48
+
49
+ And `resource` is account (for now).
50
+
51
+ `params` refers to any additional parameters you might want to pass in. For now, that's just the name of the account you want to create
52
+
53
+ # examples!
54
+
55
+ ```
56
+ # Create:
57
+ shacho create account default
58
+ ```
59
+
60
+ ```
61
+ # Use:
62
+ shacho use account default
63
+ ```
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "shacho"
18
+ gem.homepage = "http://github.com/kellydunn/shacho"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{manages keysets for multiple heroku accounts}
21
+ gem.description = %Q{manages keysets for multiple heroku accounts}
22
+ gem.email = "defaultstring@gmail.com"
23
+ gem.authors = ["Kelly"]
24
+ gem.executables = ["shacho"]
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "shacho #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/shacho ADDED
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'shacho'
4
+ require 'shacho/runner'
5
+ exit Shacho::Runner.run!(*ARGV)
@@ -0,0 +1,25 @@
1
+ require 'fileutils'
2
+
3
+ module Shacho
4
+ class Account
5
+ def self.create(options)
6
+ # TODO Throw error for incorrect usage
7
+ name = options.first
8
+ filename = "#{HEROKU_PREFIX}/accounts/#{name}"
9
+ if !File.exists?(filename) || !File.directory?(filename)
10
+ FileUtils.mkdir_p(filename)
11
+ credential = Credential.new
12
+ credential.prompt(name)
13
+ credential.write(filename)
14
+ end
15
+ end
16
+
17
+ def self.use(options)
18
+ # TODO Throw error for incorrect usage
19
+ name = options.first
20
+ credential_file = "#{HEROKU_PREFIX}/accounts/#{name}/credentials"
21
+ heroku_credentials = "#{HEROKU_PREFIX}/credentials"
22
+ FileUtils.ln_s credential_file, heroku_credentials, :force => true
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ module Shacho
2
+ class Credential
3
+ attr_accessor :email, :password
4
+
5
+ def prompt(name)
6
+ puts "Enter your Heroku credentials for #{name}."
7
+ print "Email: "
8
+ @email = STDIN.gets.chomp
9
+ print "Password: "
10
+ @password = STDIN.gets.chomp
11
+ end
12
+
13
+ def write(filename)
14
+ credentials_filename = "#{filename}/credentials"
15
+ FileUtils.touch(credentials_filename)
16
+ File.open(credentials_filename, 'w') do |f|
17
+ f.write("#{@email}\n#{@password}")
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/shacho/key.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Shacho
2
+ class Key
3
+ end
4
+ end
@@ -0,0 +1,38 @@
1
+ module Shacho
2
+ class Runner
3
+ class << self
4
+ def run!(*args)
5
+ options = parse_options(args)
6
+ delegate_command(options)
7
+ return 0
8
+ end
9
+
10
+ def parse_options(args)
11
+ options = {}
12
+ COMMANDS.each do |element, types|
13
+ value = args.shift
14
+ if types.include?(value)
15
+ options[element] = value
16
+ else
17
+ next if !options["action"].empty?
18
+ error "Run shacho help for usage"
19
+ end
20
+ end
21
+ options["params"] = args
22
+ return options
23
+ end
24
+
25
+ def error(message)
26
+ STDERR.puts(message)
27
+ exit 1
28
+ end
29
+
30
+ # TODO include active support?
31
+ def delegate_command(options)
32
+ resource_name = Util.camelize(options["resource"])
33
+ resource = Util.constantize(resource_name, Shacho)
34
+ resource.send(options["action"], options["params"])
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ module Shacho
2
+ class Util
3
+ #shamelessly ripped from active_support
4
+ def self.constantize(camel_cased_word, constant)
5
+ names = camel_cased_word.split('::')
6
+ names.shift if names.empty? || names.first.empty?
7
+
8
+ names.each do |name|
9
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
10
+ end
11
+ constant
12
+ end
13
+
14
+ # again, shamelessly ripped from active_support
15
+ def self.camelize(string)
16
+ string.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
17
+ end
18
+ end
19
+ end
data/lib/shacho.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Shacho
2
+ HEROKU_PREFIX = "#{ENV['HOME']}/.heroku"
3
+ autoload :Runner, "shacho/runner"
4
+ autoload :Account, "shacho/account"
5
+ autoload :Credential, "shacho/credential"
6
+ autoload :Util, "shacho/util"
7
+
8
+ # TODO only need to use actions
9
+ # method_missing willl help with error handling
10
+ COMMANDS = {"action" => ["create", "use", "help"],
11
+ "resource" => ["account"]}
12
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "A New Account" do
4
+ include CoreHelper
5
+
6
+ before :each do
7
+ create_account
8
+ @filename = "#{Shacho::HEROKU_PREFIX}/accounts/test"
9
+ end
10
+
11
+ it "should be created" do
12
+ File.exists?(@filename).should == true
13
+ end
14
+
15
+ it "should create a credentials file specifically for that account" do
16
+ File.exists?("#{@filename}/credentials").should == true
17
+ end
18
+
19
+ it "should contain the correct credentials after prompting the user" do
20
+ contents = get_credentials(@filename)
21
+ email_test = contents[0] == "test@test.com"
22
+ password_test = contents[1] == "password"
23
+ (email_test && password_test).should == true
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Using an account" do
4
+ include CoreHelper
5
+
6
+ before :each do
7
+ create_account
8
+ end
9
+
10
+ it "should be able to use an account" do
11
+ Shacho::Account.use(["test"])
12
+ current_creds = get_credentials("#{Shacho::HEROKU_PREFIX}")
13
+ account_creds = get_credentials("#{Shacho::HEROKU_PREFIX}/accounts/test/")
14
+ current_creds.should == account_creds
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module CoreHelper
2
+ def create_account
3
+ STDIN.stubs(:gets).returns("test@test.com", "password")
4
+ @account = Shacho::Account.create(["test"])
5
+ end
6
+
7
+ def get_credentials(filename)
8
+ file = File.open("#{filename}/credentials", "r")
9
+ contents = file.read.split("\n")
10
+ contents
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Shacho" do
4
+ it "needs tests"
5
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'mocha'
5
+
6
+ require 'shacho'
7
+
8
+ Shacho::HEROKU_PREFIX = "#{File.dirname(__FILE__)}/helpers"
9
+
10
+ Dir["#{File.dirname(__FILE__)}/helpers/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ config.mock_with :mocha
14
+
15
+ config.after :each do
16
+ if File.exists?("#{File.dirname(__FILE__)}/helpers/accounts")
17
+ FileUtils.rm_r("#{File.dirname(__FILE__)}/helpers/accounts")
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shacho
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kelly
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: heroku
16
+ requirement: &13481600 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *13481600
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &13480420 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.3.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *13480420
36
+ - !ruby/object:Gem::Dependency
37
+ name: ruby-debug19
38
+ requirement: &13478220 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *13478220
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: &13477020 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *13477020
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &13475480 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *13475480
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &13474540 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.6.4
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *13474540
80
+ - !ruby/object:Gem::Dependency
81
+ name: rcov
82
+ requirement: &13458700 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *13458700
91
+ description: manages keysets for multiple heroku accounts
92
+ email: defaultstring@gmail.com
93
+ executables:
94
+ - shacho
95
+ extensions: []
96
+ extra_rdoc_files:
97
+ - LICENSE.txt
98
+ - README.md
99
+ files:
100
+ - .document
101
+ - .rspec
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - VERSION
108
+ - bin/shacho
109
+ - lib/shacho.rb
110
+ - lib/shacho/account.rb
111
+ - lib/shacho/credential.rb
112
+ - lib/shacho/key.rb
113
+ - lib/shacho/runner.rb
114
+ - lib/shacho/util.rb
115
+ - spec/accounts/new_account_spec.rb
116
+ - spec/accounts/use_account_spec.rb
117
+ - spec/helpers/core.rb
118
+ - spec/shacho_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: http://github.com/kellydunn/shacho
121
+ licenses:
122
+ - MIT
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ segments:
134
+ - 0
135
+ hash: -8561316424044421
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.10
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: manages keysets for multiple heroku accounts
148
+ test_files: []