ey_cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +57 -0
- data/LICENSE +22 -0
- data/README.md +104 -0
- data/Rakefile +129 -0
- data/bin/ey_cli +5 -0
- data/ey_cli.gemspec +117 -0
- data/history.md +3 -0
- data/lib/ey_cli/api.rb +96 -0
- data/lib/ey_cli/cli.rb +17 -0
- data/lib/ey_cli/command_manager.rb +29 -0
- data/lib/ey_cli/commands/accounts.rb +26 -0
- data/lib/ey_cli/commands/apps.rb +24 -0
- data/lib/ey_cli/commands/base.rb +16 -0
- data/lib/ey_cli/commands/console.rb +38 -0
- data/lib/ey_cli/commands/create_app.rb +76 -0
- data/lib/ey_cli/commands/create_env.rb +106 -0
- data/lib/ey_cli/commands/deploy.rb +23 -0
- data/lib/ey_cli/commands/help.rb +65 -0
- data/lib/ey_cli/commands/show.rb +65 -0
- data/lib/ey_cli/controllers/accounts.rb +23 -0
- data/lib/ey_cli/controllers/apps.rb +66 -0
- data/lib/ey_cli/controllers/environments.rb +78 -0
- data/lib/ey_cli/git_utils.rb +12 -0
- data/lib/ey_cli/models/account.rb +6 -0
- data/lib/ey_cli/models/app.rb +15 -0
- data/lib/ey_cli/models/base.rb +54 -0
- data/lib/ey_cli/models/environment.rb +32 -0
- data/lib/ey_cli/options_parser.rb +47 -0
- data/lib/ey_cli/smarty_parser.rb +29 -0
- data/lib/ey_cli/term.rb +58 -0
- data/lib/ey_cli.rb +46 -0
- data/spec/auth_helper.rb +28 -0
- data/spec/ey_cli/api_spec.rb +70 -0
- data/spec/ey_cli/command_manager_spec.rb +33 -0
- data/spec/ey_cli/commands/help_spec.rb +36 -0
- data/spec/ey_cli/controllers/accounts_spec.rb +40 -0
- data/spec/ey_cli/controllers/apps_spec.rb +97 -0
- data/spec/ey_cli/controllers/environments_spec.rb +101 -0
- data/spec/ey_cli/models/app_spec.rb +50 -0
- data/spec/ey_cli/models/base_spec.rb +98 -0
- data/spec/ey_cli/models/environment_spec.rb +51 -0
- data/spec/ey_cli/options_parser_spec.rb +19 -0
- data/spec/ey_cli/smarty_parser_spec.rb +19 -0
- data/spec/spec_helper.rb +29 -0
- metadata +288 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ey_cli (0.1.0)
|
5
|
+
faraday
|
6
|
+
faraday-stack
|
7
|
+
faraday_middleware
|
8
|
+
hashie
|
9
|
+
highline
|
10
|
+
json
|
11
|
+
multi_json
|
12
|
+
slop
|
13
|
+
|
14
|
+
GEM
|
15
|
+
remote: http://rubygems.org/
|
16
|
+
specs:
|
17
|
+
addressable (2.2.6)
|
18
|
+
crack (0.3.1)
|
19
|
+
diff-lcs (1.1.3)
|
20
|
+
fakefs (0.3.2)
|
21
|
+
faraday (0.7.4)
|
22
|
+
addressable (~> 2.2.6)
|
23
|
+
multipart-post (~> 1.1.0)
|
24
|
+
rack (< 2, >= 1.1.0)
|
25
|
+
faraday-stack (0.1.3)
|
26
|
+
faraday (~> 0.6)
|
27
|
+
faraday_middleware (0.7.0)
|
28
|
+
faraday (~> 0.7.3)
|
29
|
+
hashie (1.0.0)
|
30
|
+
highline (1.6.2)
|
31
|
+
json (1.6.1)
|
32
|
+
multi_json (1.0.3)
|
33
|
+
multipart-post (1.1.3)
|
34
|
+
rack (1.3.3)
|
35
|
+
rake (0.9.2)
|
36
|
+
rspec (2.6.0)
|
37
|
+
rspec-core (~> 2.6.0)
|
38
|
+
rspec-expectations (~> 2.6.0)
|
39
|
+
rspec-mocks (~> 2.6.0)
|
40
|
+
rspec-core (2.6.4)
|
41
|
+
rspec-expectations (2.6.0)
|
42
|
+
diff-lcs (~> 1.1.2)
|
43
|
+
rspec-mocks (2.6.0)
|
44
|
+
slop (2.1.0)
|
45
|
+
webmock (1.7.6)
|
46
|
+
addressable (~> 2.2, > 2.2.5)
|
47
|
+
crack (>= 0.1.7)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
ey_cli!
|
54
|
+
fakefs
|
55
|
+
rake (~> 0.9)
|
56
|
+
rspec
|
57
|
+
webmock
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
== ey_cli
|
2
|
+
|
3
|
+
Copyright (c) 2011 David Calavera
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# ey_cli
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/calavera/ey_cli.png)](http://travis-ci.org/calavera/ey_cli)
|
4
|
+
|
5
|
+
An alternative command line interface for Engine Yard Cloud.
|
6
|
+
|
7
|
+
Still in early development.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install ey_cli
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```
|
18
|
+
ey_cli command [args]
|
19
|
+
```
|
20
|
+
|
21
|
+
More information available about the available commands if you run:
|
22
|
+
|
23
|
+
```
|
24
|
+
ey_cli help
|
25
|
+
```
|
26
|
+
|
27
|
+
## Examples
|
28
|
+
|
29
|
+
- How to create a new application:
|
30
|
+
|
31
|
+
```
|
32
|
+
ey_cli create_app
|
33
|
+
```
|
34
|
+
|
35
|
+
That's all that you need if you're under the application directory and this already is in a git repository. It also runs a first deploy for free.
|
36
|
+
|
37
|
+
- How to perform a new deploy:
|
38
|
+
|
39
|
+
```
|
40
|
+
ey_cli deploy
|
41
|
+
```
|
42
|
+
|
43
|
+
That's all, if the CLI doesn't know what you want to deploy it politely asks you.
|
44
|
+
|
45
|
+
## Avaliable commands
|
46
|
+
|
47
|
+
General info
|
48
|
+
accounts List the accounts associated to a user.
|
49
|
+
console Start an interactive session to use ey_cli.
|
50
|
+
help Show commands information.
|
51
|
+
|
52
|
+
Applications
|
53
|
+
apps List the applications associated to a user.
|
54
|
+
create_app Create a new application. It takes the information from the current directory.
|
55
|
+
show Show information and status of an application.
|
56
|
+
|
57
|
+
Environments
|
58
|
+
create_env Create a new environment for an application.
|
59
|
+
deploy Run a deploy for an application.
|
60
|
+
|
61
|
+
## Motivation
|
62
|
+
|
63
|
+
engineyard gem is strongly coupled to Thor, and I don't like the
|
64
|
+
conventions that you have to assume because of this coupling.
|
65
|
+
|
66
|
+
engineyarg gem connects to your boxes directly to perform tasks. I
|
67
|
+
prefer to connect to the available APIs and have a unique entry point.
|
68
|
+
|
69
|
+
**Is this a replacement for engineyard gem, then?** No, for now it's just an
|
70
|
+
experiment and only implements a few number of commands.
|
71
|
+
|
72
|
+
## Development notes
|
73
|
+
|
74
|
+
Check the opened issues if you want to help and don't know where to
|
75
|
+
start from.
|
76
|
+
|
77
|
+
Run this command to execute the tests:
|
78
|
+
|
79
|
+
```
|
80
|
+
bundle rake
|
81
|
+
```
|
82
|
+
|
83
|
+
Any pull request and contribution is really appreciated.
|
84
|
+
|
85
|
+
## Notes about the structure:
|
86
|
+
|
87
|
+
How this library is structured:
|
88
|
+
|
89
|
+
### Commands
|
90
|
+
|
91
|
+
What the user executes. Each one can provide its own command line parser
|
92
|
+
to accept further options but one is provided by default.
|
93
|
+
|
94
|
+
### Controllers
|
95
|
+
|
96
|
+
Code and stuff. Show messages, decide what to do...
|
97
|
+
|
98
|
+
### Models
|
99
|
+
|
100
|
+
Connect to the api. Abstraction over the json responses.
|
101
|
+
|
102
|
+
# Copyright
|
103
|
+
|
104
|
+
Copyright (c) 2011 David Calavera. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
#############################################################################
|
6
|
+
#
|
7
|
+
# Helper functions
|
8
|
+
#
|
9
|
+
#############################################################################
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
17
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def date
|
21
|
+
Date.today.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def rubyforge_project
|
25
|
+
name
|
26
|
+
end
|
27
|
+
|
28
|
+
def gemspec_file
|
29
|
+
"#{name}.gemspec"
|
30
|
+
end
|
31
|
+
|
32
|
+
def gem_file
|
33
|
+
"#{name}-#{version}.gem"
|
34
|
+
end
|
35
|
+
|
36
|
+
def replace_header(head, header_name)
|
37
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
38
|
+
end
|
39
|
+
|
40
|
+
#############################################################################
|
41
|
+
#
|
42
|
+
# Standard tasks
|
43
|
+
#
|
44
|
+
#############################################################################
|
45
|
+
|
46
|
+
require 'rspec/core/rake_task'
|
47
|
+
|
48
|
+
RSpec::Core::RakeTask.new(:rspec) do |spec|
|
49
|
+
spec.rspec_opts = ['--color', "--format documentation"]
|
50
|
+
end
|
51
|
+
|
52
|
+
task :default => :rspec
|
53
|
+
|
54
|
+
desc "Open an irb session preloaded with this library"
|
55
|
+
task :console do
|
56
|
+
sh "bundle exec irb -rubygems -I ./lib -r #{name}.rb"
|
57
|
+
end
|
58
|
+
|
59
|
+
#############################################################################
|
60
|
+
#
|
61
|
+
# Packaging tasks
|
62
|
+
#
|
63
|
+
#############################################################################
|
64
|
+
|
65
|
+
desc "release a new version of ey_cli, tag the version and push the gem"
|
66
|
+
task :release => :build do
|
67
|
+
unless `git branch` =~ /^\* master$/
|
68
|
+
puts "You must be on the master branch to release!"
|
69
|
+
exit!
|
70
|
+
end
|
71
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
72
|
+
sh "git tag v#{version}"
|
73
|
+
sh "git push origin master"
|
74
|
+
sh "git push --tags"
|
75
|
+
sh "gem push pkg/#{gem_file}"
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "install ey_cli gem in this box"
|
79
|
+
task :install => :build do
|
80
|
+
sh "gem install pkg/#{gem_file}"
|
81
|
+
end
|
82
|
+
|
83
|
+
desc "build ey_cli gem"
|
84
|
+
task :build => 'gemspec' do
|
85
|
+
sh "mkdir -p pkg"
|
86
|
+
sh "gem build #{gemspec_file}"
|
87
|
+
sh "mv #{gem_file} pkg"
|
88
|
+
end
|
89
|
+
|
90
|
+
desc "generate a valid gemspec file"
|
91
|
+
task :gemspec => :validate do
|
92
|
+
# read spec file and split out manifest section
|
93
|
+
spec = File.read(gemspec_file)
|
94
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
95
|
+
|
96
|
+
# replace name version and date
|
97
|
+
replace_header(head, :name)
|
98
|
+
replace_header(head, :version)
|
99
|
+
replace_header(head, :date)
|
100
|
+
#comment this out if your rubyforge_project has a different name
|
101
|
+
replace_header(head, :rubyforge_project)
|
102
|
+
|
103
|
+
# determine file list from git ls-files
|
104
|
+
files = `git ls-files`.
|
105
|
+
split("\n").
|
106
|
+
sort.
|
107
|
+
reject { |file| file =~ /^\./ }.
|
108
|
+
reject { |file| file =~ /^(rdoc|pkg|src|racklib)/ }.
|
109
|
+
map { |file| " #{file}" }.
|
110
|
+
join("\n")
|
111
|
+
|
112
|
+
# piece file back together and write
|
113
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
114
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
115
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
116
|
+
puts "Updated #{gemspec_file}"
|
117
|
+
end
|
118
|
+
|
119
|
+
task :validate do
|
120
|
+
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
121
|
+
unless libfiles.empty?
|
122
|
+
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
123
|
+
exit!
|
124
|
+
end
|
125
|
+
unless Dir['VERSION*'].empty?
|
126
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
127
|
+
exit!
|
128
|
+
end
|
129
|
+
end
|
data/bin/ey_cli
ADDED
data/ey_cli.gemspec
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
## This is the rakegem gemspec template. Make sure you read and understand
|
2
|
+
## all of the comments. Some sections require modification, and others can
|
3
|
+
## be deleted if you don't need them. Once you understand the contents of
|
4
|
+
## this file, feel free to delete any comments that begin with two hash marks.
|
5
|
+
## You can find comprehensive Gem::Specification documentation, at
|
6
|
+
## http://docs.rubygems.org/read/chapter/20
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.rubygems_version = '1.3.5'
|
11
|
+
|
12
|
+
## Leave these as is they will be modified for you by the rake gemspec task.
|
13
|
+
## If your rubyforge_project name is different, then edit it and comment out
|
14
|
+
## the sub! line in the Rakefile
|
15
|
+
s.name = 'ey_cli'
|
16
|
+
s.version = '0.1.0'
|
17
|
+
s.date = '2011-10-15'
|
18
|
+
s.rubyforge_project = 'ey_cli'
|
19
|
+
|
20
|
+
## Make sure your summary is short. The description may be as long
|
21
|
+
## as you like.
|
22
|
+
s.summary = "More user friendly CLI for Engine Yard cloud"
|
23
|
+
s.description = "More user friendly CLI for Engine Yard cloud. Use undocumented APIs"
|
24
|
+
|
25
|
+
## List the primary authors. If there are a bunch of authors, it's probably
|
26
|
+
## better to set the email to an email list or something. If you don't have
|
27
|
+
## a custom homepage, consider using your GitHub URL or the like.
|
28
|
+
s.authors = ["David Calavera"]
|
29
|
+
s.email = 'david.calavera@gmail.com'
|
30
|
+
s.homepage = 'http://github.com/calavera/ey_cli'
|
31
|
+
|
32
|
+
s.executables = ['ey_cli']
|
33
|
+
|
34
|
+
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
35
|
+
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
36
|
+
s.require_paths = %w[lib]
|
37
|
+
|
38
|
+
## Specify any RDoc options here. You'll want to add your README and
|
39
|
+
## LICENSE files to the extra_rdoc_files list.
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.extra_rdoc_files = %w[README.md LICENSE]
|
42
|
+
|
43
|
+
## List your runtime dependencies here. Runtime dependencies are those
|
44
|
+
## that are needed for an end user to actually USE your code.
|
45
|
+
s.add_dependency('faraday')
|
46
|
+
s.add_dependency('faraday_middleware')
|
47
|
+
s.add_dependency('faraday-stack')
|
48
|
+
s.add_dependency('highline')
|
49
|
+
s.add_dependency('hashie')
|
50
|
+
s.add_dependency('json')
|
51
|
+
s.add_dependency('multi_json')
|
52
|
+
s.add_dependency('slop')
|
53
|
+
|
54
|
+
## List your development dependencies here. Development dependencies are
|
55
|
+
## those that are only needed during development
|
56
|
+
s.add_development_dependency('rake', '~> 0.9')
|
57
|
+
s.add_development_dependency('rspec')
|
58
|
+
s.add_development_dependency('webmock')
|
59
|
+
s.add_development_dependency('fakefs')
|
60
|
+
|
61
|
+
## Leave this section as-is. It will be automatically generated from the
|
62
|
+
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
63
|
+
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
64
|
+
# = MANIFEST =
|
65
|
+
s.files = %w[
|
66
|
+
Gemfile
|
67
|
+
Gemfile.lock
|
68
|
+
LICENSE
|
69
|
+
README.md
|
70
|
+
Rakefile
|
71
|
+
bin/ey_cli
|
72
|
+
ey_cli.gemspec
|
73
|
+
history.md
|
74
|
+
lib/ey_cli.rb
|
75
|
+
lib/ey_cli/api.rb
|
76
|
+
lib/ey_cli/cli.rb
|
77
|
+
lib/ey_cli/command_manager.rb
|
78
|
+
lib/ey_cli/commands/accounts.rb
|
79
|
+
lib/ey_cli/commands/apps.rb
|
80
|
+
lib/ey_cli/commands/base.rb
|
81
|
+
lib/ey_cli/commands/console.rb
|
82
|
+
lib/ey_cli/commands/create_app.rb
|
83
|
+
lib/ey_cli/commands/create_env.rb
|
84
|
+
lib/ey_cli/commands/deploy.rb
|
85
|
+
lib/ey_cli/commands/help.rb
|
86
|
+
lib/ey_cli/commands/show.rb
|
87
|
+
lib/ey_cli/controllers/accounts.rb
|
88
|
+
lib/ey_cli/controllers/apps.rb
|
89
|
+
lib/ey_cli/controllers/environments.rb
|
90
|
+
lib/ey_cli/git_utils.rb
|
91
|
+
lib/ey_cli/models/account.rb
|
92
|
+
lib/ey_cli/models/app.rb
|
93
|
+
lib/ey_cli/models/base.rb
|
94
|
+
lib/ey_cli/models/environment.rb
|
95
|
+
lib/ey_cli/options_parser.rb
|
96
|
+
lib/ey_cli/smarty_parser.rb
|
97
|
+
lib/ey_cli/term.rb
|
98
|
+
spec/auth_helper.rb
|
99
|
+
spec/ey_cli/api_spec.rb
|
100
|
+
spec/ey_cli/command_manager_spec.rb
|
101
|
+
spec/ey_cli/commands/help_spec.rb
|
102
|
+
spec/ey_cli/controllers/accounts_spec.rb
|
103
|
+
spec/ey_cli/controllers/apps_spec.rb
|
104
|
+
spec/ey_cli/controllers/environments_spec.rb
|
105
|
+
spec/ey_cli/models/app_spec.rb
|
106
|
+
spec/ey_cli/models/base_spec.rb
|
107
|
+
spec/ey_cli/models/environment_spec.rb
|
108
|
+
spec/ey_cli/options_parser_spec.rb
|
109
|
+
spec/ey_cli/smarty_parser_spec.rb
|
110
|
+
spec/spec_helper.rb
|
111
|
+
]
|
112
|
+
# = MANIFEST =
|
113
|
+
|
114
|
+
## Test files will be grabbed from the file list. Make sure the path glob
|
115
|
+
## matches what you actually use.
|
116
|
+
s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
|
117
|
+
end
|
data/history.md
ADDED
data/lib/ey_cli/api.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
module EYCli
|
2
|
+
class Api
|
3
|
+
require 'yaml'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'faraday_stack'
|
6
|
+
|
7
|
+
attr_reader :endpoint
|
8
|
+
|
9
|
+
def initialize(endpoint = nil)
|
10
|
+
@endpoint = endpoint || 'https://cloud.engineyard.com/api/v2/'
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_token(file = nil)
|
14
|
+
file ||= ENV['EYRC'] || File.expand_path("~/.eyrc")
|
15
|
+
return nil unless File.exists?(file)
|
16
|
+
|
17
|
+
if data = YAML.load_file(file)
|
18
|
+
(data[endpoint] && data[endpoint]['api_token']) || data['api_token']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def fetch_token(times = 3)
|
23
|
+
EYCli.term.say("I don't know who you are, please log in with your Engine Yard Cloud credentials.")
|
24
|
+
begin
|
25
|
+
email = EYCli.term.ask("Email: ")
|
26
|
+
password = EYCli.term.ask("Password: ", true)
|
27
|
+
|
28
|
+
response = post("authenticate", nil, { :email => email, :password => password }, {}, false)
|
29
|
+
save_token(response.body['api_token'])
|
30
|
+
rescue Faraday::Error::ClientError
|
31
|
+
EYCli.term.warning "Invalid username or password; please try again."
|
32
|
+
if (times -= 1) > 0
|
33
|
+
retry
|
34
|
+
else
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def save_token(token, file = nil)
|
41
|
+
file ||= ENV['EYRC'] || File.expand_path("~/.eyrc")
|
42
|
+
|
43
|
+
data = File.exists?(file) ? YAML.load_file(file) : {}
|
44
|
+
data[endpoint] = {"api_token" => token}
|
45
|
+
|
46
|
+
File.open(file, "w"){|f| YAML.dump(data, f) }
|
47
|
+
token
|
48
|
+
end
|
49
|
+
|
50
|
+
def get(path, params = {}, headers = {})
|
51
|
+
request(path, {:method => :get}.merge(params), headers)
|
52
|
+
end
|
53
|
+
|
54
|
+
def post(path, body, params = {}, headers = {}, auth = true)
|
55
|
+
request(path, {:method => :post, :body => body}.merge(params), headers, auth)
|
56
|
+
end
|
57
|
+
|
58
|
+
def put(path, body, params = {}, headers = {})
|
59
|
+
request(path, {:method => :put, :body => body}.merge(params), headers)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete(path, params = {}, headers = {})
|
63
|
+
request(path, {:method => :delete}.merge(params), headers)
|
64
|
+
end
|
65
|
+
|
66
|
+
def request(path, params = {}, headers = {}, auth = true)
|
67
|
+
http_method = params.delete(:method).to_s.downcase
|
68
|
+
http_body = params.delete(:body)
|
69
|
+
@auth_token ||= read_token || fetch_token if auth
|
70
|
+
|
71
|
+
connection.send(http_method) do |req|
|
72
|
+
req.path = path
|
73
|
+
req.params.merge! params
|
74
|
+
req.headers.merge! headers
|
75
|
+
|
76
|
+
req.headers["X-EY-Cloud-Token"] = @auth_token if auth
|
77
|
+
req.body = http_body if http_body
|
78
|
+
end
|
79
|
+
rescue Faraday::Error::ClientError => e
|
80
|
+
raise e unless e.response[:status] == 401
|
81
|
+
@auth_token = fetch_token if auth
|
82
|
+
params[:method] = http_method
|
83
|
+
params[:body] = http_body
|
84
|
+
retry
|
85
|
+
end
|
86
|
+
|
87
|
+
def connection
|
88
|
+
@connection ||= Faraday::Connection.new(:url => endpoint) do |builder|
|
89
|
+
builder.adapter Faraday.default_adapter
|
90
|
+
builder.use Faraday::Response::ParseJson
|
91
|
+
builder.use FaradayStack::FollowRedirects
|
92
|
+
builder.response :raise_error
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/ey_cli/cli.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module EYCli
|
2
|
+
class CLI
|
3
|
+
def run(args)
|
4
|
+
name = args.shift.downcase
|
5
|
+
command = EYCli.command_manager[name]
|
6
|
+
unless command
|
7
|
+
EYCli.term.say <<-EOF
|
8
|
+
|
9
|
+
Command not available: '#{name}'
|
10
|
+
Try running `ey_cli help' to get more information about the available commands.
|
11
|
+
EOF
|
12
|
+
else
|
13
|
+
command.run(args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module EYCli
|
2
|
+
class CommandManager
|
3
|
+
attr_reader :commands
|
4
|
+
def initialize
|
5
|
+
@commands = {}
|
6
|
+
register_command :accounts, :apps, :console, :create_app, :create_env, :deploy, :help, :show
|
7
|
+
end
|
8
|
+
|
9
|
+
def register_command(*names)
|
10
|
+
names.each do | name |
|
11
|
+
commands[name] = false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](name)
|
16
|
+
command_name = name.to_sym
|
17
|
+
return nil unless commands.key?(command_name)
|
18
|
+
commands[command_name] = load_command(command_name) unless commands[command_name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_command(name)
|
22
|
+
const_name = name.to_s.capitalize.gsub(/_(.)/) { $1.upcase }
|
23
|
+
if EYCli::Command.const_defined?(const_name)
|
24
|
+
EYCli::Command.const_get(const_name).new
|
25
|
+
# TODO: else require and retry (PLUGINS)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module EYCli
|
2
|
+
module Command
|
3
|
+
class Accounts < Base
|
4
|
+
def initialize
|
5
|
+
@accounts = EYCli::Controller::Accounts.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def invoke
|
9
|
+
accounts = @accounts.fetch_accounts.map {|a| " - #{a.name}"}.join("\n")
|
10
|
+
EYCli.term.say <<-EOF
|
11
|
+
|
12
|
+
Available accounts:
|
13
|
+
#{accounts}
|
14
|
+
EOF
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def help
|
19
|
+
<<-EOF
|
20
|
+
Usage: ey_cli accounts
|
21
|
+
Note: it shows the accounts that belong to you and also the ones that you are collaborating with.
|
22
|
+
EOF
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module EYCli
|
2
|
+
module Command
|
3
|
+
class Apps < Base
|
4
|
+
def initialize
|
5
|
+
@apps = EYCli::Controller::Apps.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def invoke
|
9
|
+
apps = @apps.fetch_apps.map {|a| " - #{a.name}"}.join("\n")
|
10
|
+
EYCli.term.say <<-EOF
|
11
|
+
Available applications:
|
12
|
+
#{apps}
|
13
|
+
EOF
|
14
|
+
end
|
15
|
+
|
16
|
+
def help
|
17
|
+
<<-EOF
|
18
|
+
List the applications created under your account and the accounts you are collaborating with.
|
19
|
+
Usage: ey_cli apps
|
20
|
+
EOF
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module EYCli
|
2
|
+
module Command
|
3
|
+
class Base
|
4
|
+
attr_reader :options
|
5
|
+
|
6
|
+
def run(args = [])
|
7
|
+
@options = options_parser.parse(args)
|
8
|
+
invoke
|
9
|
+
end
|
10
|
+
|
11
|
+
def options_parser
|
12
|
+
EYCli::OptionsParser.new # TODO: Override to extend
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module EYCli
|
2
|
+
module Command
|
3
|
+
class Console < Base
|
4
|
+
include EYCli
|
5
|
+
require 'irb'
|
6
|
+
|
7
|
+
def invoke
|
8
|
+
ARGV.clear
|
9
|
+
IRB.setup(nil)
|
10
|
+
@irb = IRB::Irb.new(nil)
|
11
|
+
IRB.conf[:MAIN_CONTEXT] = @irb.context
|
12
|
+
IRB.conf[:PROMPT][:EY_CLI] = IRB.conf[:PROMPT][:SIMPLE].dup
|
13
|
+
IRB.conf[:PROMPT][:EY_CLI][:RETURN] = "%s\n"
|
14
|
+
@irb.context.prompt_mode = :EY_CLI
|
15
|
+
@irb.context.workspace = IRB::WorkSpace.new(binding)
|
16
|
+
term.say('Welcome to ey_cli interactive!')
|
17
|
+
|
18
|
+
catch(:IRB_EXIT) { @irb.eval_input }
|
19
|
+
end
|
20
|
+
|
21
|
+
def help
|
22
|
+
<<-EOF
|
23
|
+
|
24
|
+
Usage: ey_cli console
|
25
|
+
Note: starts an interactive session.
|
26
|
+
EOF
|
27
|
+
end
|
28
|
+
|
29
|
+
def term
|
30
|
+
EYCli.term
|
31
|
+
end
|
32
|
+
|
33
|
+
def api
|
34
|
+
EYCli.api
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|