nuvado 1.0.0.rc1
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.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +69 -0
- data/Rakefile +33 -0
- data/bin/nuvado +12 -0
- data/lib/nuvado/apps.rb +76 -0
- data/lib/nuvado/backend/app.rb +6 -0
- data/lib/nuvado/backend/authenticated_resource.rb +25 -0
- data/lib/nuvado/backend/basic_resource.rb +12 -0
- data/lib/nuvado/backend/build.rb +7 -0
- data/lib/nuvado/backend/git.rb +23 -0
- data/lib/nuvado/backend/key.rb +9 -0
- data/lib/nuvado/backend/local_key.rb +50 -0
- data/lib/nuvado/backend/session.rb +6 -0
- data/lib/nuvado/backend/token_store.rb +26 -0
- data/lib/nuvado/backend/user.rb +6 -0
- data/lib/nuvado/backend.rb +15 -0
- data/lib/nuvado/base_command.rb +41 -0
- data/lib/nuvado/exceptions.rb +17 -0
- data/lib/nuvado/generate.rb +39 -0
- data/lib/nuvado/keys.rb +57 -0
- data/lib/nuvado/nuvado.rb +33 -0
- data/lib/nuvado/os.rb +22 -0
- data/lib/nuvado/templates/empty_project/%product_name%/%product_name%-Info.plist.tt +45 -0
- data/lib/nuvado/templates/empty_project/%product_name%/%product_name%-Prefix.pch.tt +14 -0
- data/lib/nuvado/templates/empty_project/%product_name%/AppDelegate.h.tt +15 -0
- data/lib/nuvado/templates/empty_project/%product_name%/AppDelegate.m.tt +49 -0
- data/lib/nuvado/templates/empty_project/%product_name%/Default-568h@2x.png +0 -0
- data/lib/nuvado/templates/empty_project/%product_name%/Default.png +0 -0
- data/lib/nuvado/templates/empty_project/%product_name%/Default@2x.png +0 -0
- data/lib/nuvado/templates/empty_project/%product_name%/en.lproj/InfoPlist.strings +2 -0
- data/lib/nuvado/templates/empty_project/%product_name%/main.m.tt +18 -0
- data/lib/nuvado/templates/empty_project/%product_name%.xcodeproj/project.pbxproj.tt +452 -0
- data/lib/nuvado/templates/empty_project/%product_name%.xcodeproj/project.xcworkspace/contents.xcworkspacedata.tt +7 -0
- data/lib/nuvado/templates/empty_project/%product_name%Tests/%product_name%Tests-Info.plist.tt +22 -0
- data/lib/nuvado/templates/empty_project/%product_name%Tests/%product_name%Tests.h.tt +13 -0
- data/lib/nuvado/templates/empty_project/%product_name%Tests/%product_name%Tests.m.tt +32 -0
- data/lib/nuvado/templates/empty_project/%product_name%Tests/en.lproj/InfoPlist.strings +2 -0
- data/lib/nuvado/version.rb +3 -0
- data/lib/nuvado.rb +9 -0
- data/nuvado.gemspec +35 -0
- data/post_install.sh +2 -0
- data/test/apps_test.rb +107 -0
- data/test/backend_local_key_test.rb +46 -0
- data/test/keys_test.rb +102 -0
- data/test/login_test.rb +25 -0
- data/test/ssh/jmendoza.pub +1 -0
- data/test/ssh/kramos.pub +1 -0
- data/test/test_helper.rb +24 -0
- metadata +272 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e7e8066f85859ffd40466cb86762fd50143a6dd
|
4
|
+
data.tar.gz: 02c3ba2fff1cd6de945a461d5fd3488c83fb4068
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e0360aba2e61d265372a96d9363da08bd3352820bebf46cbfbe933912c0a0d84230ee6bed8a8b3466eab876bcf74ef465b1acb737c604d7efc79fa3604f3726
|
7
|
+
data.tar.gz: 9999a03c71dc552774e01ff3bfecd9a21297214ca9b0c2dba70c6fb3bbdd4b9f6c73f5ba30573f357200465a02a580327d399e24117c1d2e9b60f2abd3874e73
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.deb
|
2
|
+
.ruby-gemset
|
3
|
+
*.gem
|
4
|
+
*.rbc
|
5
|
+
.bundle
|
6
|
+
.config
|
7
|
+
.yardoc
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
_yardoc
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
20
|
+
.rvmrc
|
21
|
+
.ruby-version
|
22
|
+
.DS_Store
|
23
|
+
vendor/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 robertomiranda
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Nuvado
|
2
|
+
|
3
|
+
Client library and command-line tool to deploy and manage apps on Nuvado.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'nuvado'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install nuvado
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### What you need to know
|
22
|
+
|
23
|
+
As you will see soon, nuvado leverages much of git's awesomeness to do its job.
|
24
|
+
http://try.github.com is a very useful resource to get an overview of what git can do for you. It only
|
25
|
+
takes about 15 mins to complete.
|
26
|
+
|
27
|
+
### Login
|
28
|
+
|
29
|
+
Type <code>nuvado login</code> in your terminal and follow the authentication process.
|
30
|
+
From then on, any interaction via the CLI will be done with that user.
|
31
|
+
You can redo the authentication process at any time to change your current user.
|
32
|
+
|
33
|
+
### Uploading a ssh key
|
34
|
+
|
35
|
+
Type <code>nuvado keys add</code> in your terminal. If you don't have a ssh key available in your system,
|
36
|
+
nuvado can create one for you. If you have many, you will be asked to choose which one you want
|
37
|
+
to use. Nuvado will ask what name you want to give to your soon-to-be-uploaded ssh key.
|
38
|
+
|
39
|
+
### Listing remote and local ssh keys
|
40
|
+
|
41
|
+
By typing <code>nuvado keys list</code> you can see a list of your local and remote ssh keys.
|
42
|
+
|
43
|
+
### Creating a new app
|
44
|
+
|
45
|
+
Type <code>nuvado apps create [NAME]</code> to create a new app.
|
46
|
+
Then, if you are just beginning development, you can <code>git clone -o nuvado [nuvado git server hostname]:your_username/your_app_name</code> and start hacking away.
|
47
|
+
|
48
|
+
If you have already started development and already use git, nuvado will add a new remote for you.
|
49
|
+
|
50
|
+
### Do a build
|
51
|
+
|
52
|
+
To queue a build you need to run <code>nuvado apps build</code> from your project folder, or <code>nuvado apps build [APP NAME]</code> from somewhere else. In both cases nuvado will output the job id for the build.
|
53
|
+
|
54
|
+
You can check the status of your last 5 builds by running <code>nuvado apps build_status [APP NAME]</code> (Again, app name is only needed if you are not running the command from your project folder).
|
55
|
+
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create new Pull Request
|
64
|
+
|
65
|
+
License
|
66
|
+
-------
|
67
|
+
|
68
|
+
Nuvado is Copyright © 2013 Lacides Charris and Firebase. It is free software,
|
69
|
+
and may be redistributed under the terms specified in the MIT-LICENSE file.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rake/testtask'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
task :console do
|
7
|
+
puts "Loading development console..."
|
8
|
+
system("irb -r nuvado")
|
9
|
+
end
|
10
|
+
|
11
|
+
task :help do
|
12
|
+
puts "Available rake tasks: "
|
13
|
+
puts "rake console - Run a IRB console with all enviroment loaded"
|
14
|
+
puts "rake spec - Run specs"
|
15
|
+
end
|
16
|
+
|
17
|
+
task :test do
|
18
|
+
Dir.chdir('test')
|
19
|
+
end
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << '../lib'
|
23
|
+
t.libs << '../test'
|
24
|
+
t.test_files = FileList['*_test.rb']
|
25
|
+
t.verbose = false
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Build .deb package for nuvado"
|
29
|
+
task :build_deb do
|
30
|
+
%x{fpm -s empty -t deb -n nuvado-toolbelt -d git-core -d ruby1.9.1 --after-install post_install.sh -a all}
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => :test
|
data/bin/nuvado
ADDED
data/lib/nuvado/apps.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Nuvado
|
2
|
+
class Apps < BaseCommand
|
3
|
+
|
4
|
+
desc "list", "List your apps"
|
5
|
+
def list
|
6
|
+
authenticating_action do
|
7
|
+
terminal.say Backend::App.all.map(&:name).join("\n")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "create [NAME]", "Create a new app"
|
12
|
+
def create(appname = nil)
|
13
|
+
authenticating_action do
|
14
|
+
appname ||= terminal.ask("Please type the app name")
|
15
|
+
app = Backend::App.new name: appname
|
16
|
+
unless app.save
|
17
|
+
terminal.say app.errors.full_messages.join(", ")
|
18
|
+
return app
|
19
|
+
end
|
20
|
+
if on_git_repo?
|
21
|
+
add_remote("nuvado", app.remote)
|
22
|
+
else
|
23
|
+
terminal.say app.remote
|
24
|
+
end
|
25
|
+
app
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "delete [NAME]", "Delete an app"
|
30
|
+
def delete(appname = nil)
|
31
|
+
authenticating_action do
|
32
|
+
appname ||= get_appname
|
33
|
+
app = load_app(appname)
|
34
|
+
raise SystemExitException.new("App not found") unless app
|
35
|
+
app.destroy
|
36
|
+
app
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "build [NAME]", "Triggers a build for an app"
|
41
|
+
def build(appname = nil)
|
42
|
+
authenticating_action do
|
43
|
+
appname ||= get_appname
|
44
|
+
app = load_app(appname)
|
45
|
+
raise SystemExitException.new("App not found") unless app
|
46
|
+
|
47
|
+
build = Backend::Build.new({:app_id => app.id})
|
48
|
+
if build.save
|
49
|
+
terminal.say "Build Queued with the job id #{build.id}"
|
50
|
+
else
|
51
|
+
terminal.say build.errors.full_messages.join(", ")
|
52
|
+
end
|
53
|
+
build
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "build_status [NAME]", "Shows the status of the last 5 builds for a given app"
|
58
|
+
def build_status(appname = nil)
|
59
|
+
authenticating_action do
|
60
|
+
appname ||= get_appname
|
61
|
+
app = load_app(appname)
|
62
|
+
raise SystemExitException.new("App not found") unless app
|
63
|
+
|
64
|
+
builds = Backend::Build.all(:params => {:app_id => app.id, :limit => 5})
|
65
|
+
builds.each do |build|
|
66
|
+
terminal.say "#{build.id} - #{build.created_at} - #{build.status}\n"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def load_app(appname)
|
73
|
+
Backend::App.all.find{|app| app.name == appname}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "base64"
|
2
|
+
|
3
|
+
module Nuvado
|
4
|
+
module Backend
|
5
|
+
class AuthenticatedResource < BasicResource
|
6
|
+
class << self
|
7
|
+
def configure_authentication(token)
|
8
|
+
encoded_token = Base64.strict_encode64(token)
|
9
|
+
headers['Accept'] = 'application/json'
|
10
|
+
headers['Authorization'] = "Basic #{encoded_token}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def headers
|
14
|
+
if defined?(@headers)
|
15
|
+
@headers
|
16
|
+
elsif superclass != Object && superclass.headers
|
17
|
+
superclass.headers
|
18
|
+
else
|
19
|
+
@headers ||= {}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Nuvado
|
2
|
+
module Backend
|
3
|
+
class Git
|
4
|
+
def has_git?
|
5
|
+
%x{git --version}
|
6
|
+
$?.success?
|
7
|
+
end
|
8
|
+
|
9
|
+
def on_git_repo?
|
10
|
+
return unless File.exist?('.git')
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_remote(url)
|
15
|
+
%x{git remote add nuvado #{url}}
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_remote
|
19
|
+
%x{git config remote.nuvado.url}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Nuvado
|
2
|
+
KEY_FOLDER = File.join(OS.home_directory, '.ssh')
|
3
|
+
module Backend
|
4
|
+
class LocalKey
|
5
|
+
attr_accessor :filepath, :blob
|
6
|
+
class << self
|
7
|
+
def all
|
8
|
+
all_filepaths.map{|filepath| from_filepath(filepath)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def all_filepaths
|
12
|
+
Dir.glob(File.join(KEY_FOLDER, '*.pub')).sort
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_by_name(filename)
|
16
|
+
filepath = File.join(KEY_FOLDER, filename)
|
17
|
+
return unless File.exist? filepath
|
18
|
+
from_filepath filepath
|
19
|
+
end
|
20
|
+
|
21
|
+
def from_filepath(filepath)
|
22
|
+
blob = File.read(filepath)
|
23
|
+
self.new(filepath, blob)
|
24
|
+
end
|
25
|
+
|
26
|
+
# lacides: KEY_FOLDER is OS aware, but I'm not sure what happens with FileUtils.mkdir_p or ssh-keygen on windows
|
27
|
+
def generate(name = 'id_rsa')
|
28
|
+
raise SystemExitException.new("Can't generate. There's already a ssh key with that name") if find_by_name("#{name}.pub")
|
29
|
+
FileUtils.mkdir_p(KEY_FOLDER) unless File.exists?(KEY_FOLDER)
|
30
|
+
filepath = File.join(KEY_FOLDER, name)
|
31
|
+
`ssh-keygen -t rsa -N "" -f \"#{filepath}\"`
|
32
|
+
find_by_name("#{name}.pub")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(filepath, blob)
|
37
|
+
@filepath = filepath
|
38
|
+
@blob = blob
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
filename
|
43
|
+
end
|
44
|
+
|
45
|
+
def filename
|
46
|
+
File.basename filepath
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'netrc'
|
2
|
+
|
3
|
+
module Nuvado
|
4
|
+
module Backend
|
5
|
+
class TokenStore
|
6
|
+
def self.read_token
|
7
|
+
if OS.unix?
|
8
|
+
user, token = Netrc.read[API_END_POINT]
|
9
|
+
token
|
10
|
+
else
|
11
|
+
raise SystemExitException.new("Sorry, your platform is not supported")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.write_token(user, pass)
|
16
|
+
if OS.unix?
|
17
|
+
dotnetrc = Netrc.read
|
18
|
+
dotnetrc[API_END_POINT] = user, pass
|
19
|
+
dotnetrc.save
|
20
|
+
else
|
21
|
+
raise SystemExitException.new("Sorry, your platform is not supported")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'nuvado/backend/git'
|
2
|
+
require 'nuvado/backend/local_key'
|
3
|
+
require 'nuvado/backend/token_store'
|
4
|
+
require 'nuvado/backend/basic_resource'
|
5
|
+
require 'nuvado/backend/authenticated_resource'
|
6
|
+
require 'nuvado/backend/session'
|
7
|
+
require 'nuvado/backend/user'
|
8
|
+
require 'nuvado/backend/key'
|
9
|
+
require 'nuvado/backend/app'
|
10
|
+
require 'nuvado/backend/build'
|
11
|
+
|
12
|
+
module Nuvado
|
13
|
+
module Backend
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Nuvado
|
2
|
+
class BaseCommand < Thor
|
3
|
+
private
|
4
|
+
def terminal
|
5
|
+
@terminal ||= HighLine.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def authenticating_action
|
9
|
+
raise AuthParamsNotSet unless token = Backend::TokenStore.read_token
|
10
|
+
Backend::AuthenticatedResource.configure_authentication(token)
|
11
|
+
|
12
|
+
yield if block_given?
|
13
|
+
rescue ActiveResource::UnauthorizedAccess => e
|
14
|
+
raise WrongAuthParamsException
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_appname
|
18
|
+
get_appname_from_remote || terminal.ask("Please type the app name")
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_appname_from_remote
|
22
|
+
return unless on_git_repo?
|
23
|
+
return unless git.get_remote =~ /(?<=\/)(.+)(\.git)?$/
|
24
|
+
# gituser@hostname:username/appname[.git]
|
25
|
+
$1
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_remote(remote, url)
|
29
|
+
terminal.say "Adding nuvado remote pointing to #{url}"
|
30
|
+
git.add_remote(url)
|
31
|
+
end
|
32
|
+
|
33
|
+
def on_git_repo?
|
34
|
+
git.has_git? && git.on_git_repo?
|
35
|
+
end
|
36
|
+
|
37
|
+
def git
|
38
|
+
@git ||= Backend::Git.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Nuvado
|
2
|
+
#TODO: Better error messages
|
3
|
+
|
4
|
+
class SystemExitException < RuntimeError; end
|
5
|
+
|
6
|
+
class WrongAuthParamsException < SystemExitException
|
7
|
+
def initialize
|
8
|
+
super "Wrong username/password"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class AuthParamsNotSet < SystemExitException
|
13
|
+
def initialize
|
14
|
+
super "You have not set your auth params, please run 'nuvado login'"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'uuid'
|
2
|
+
|
3
|
+
module Nuvado
|
4
|
+
class Generate < Thor::Group
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
File.join File.dirname(__FILE__), 'templates'
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.valid_templates
|
12
|
+
Dir.glob("#{source_root}/**").map{|f| File.basename(f)}.join ", "
|
13
|
+
end
|
14
|
+
|
15
|
+
argument :product_name
|
16
|
+
argument :organization_name, :optional => true
|
17
|
+
argument :company_name, :optional => true
|
18
|
+
|
19
|
+
class_option :template, :default => "empty_project", :desc => "Valid templates: #{valid_templates} "
|
20
|
+
|
21
|
+
desc "Generate a new ios project from a template"
|
22
|
+
|
23
|
+
def create_project_from_template
|
24
|
+
self.organization_name ||= product_name
|
25
|
+
self.company_name ||= product_name
|
26
|
+
|
27
|
+
directory options[:template], product_name
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def uuid(id)
|
32
|
+
(@uuid ||= {})[id] ||= uuid_generator.generate.gsub("-","")
|
33
|
+
end
|
34
|
+
|
35
|
+
def uuid_generator
|
36
|
+
@uuid_generator ||= UUID.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/nuvado/keys.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Nuvado
|
2
|
+
class Keys < BaseCommand
|
3
|
+
|
4
|
+
desc "list [--source=[local|remote]]", "list your keys"
|
5
|
+
option :source
|
6
|
+
def list
|
7
|
+
case options[:source]
|
8
|
+
when "local"
|
9
|
+
terminal.say Backend::LocalKey.all.map(&:filename).join("\n")
|
10
|
+
when "remote"
|
11
|
+
authenticating_action do
|
12
|
+
terminal.say Backend::Key.all.map(&:title).join("\n")
|
13
|
+
end
|
14
|
+
else
|
15
|
+
terminal.say "Local keys:"
|
16
|
+
terminal.say Backend::LocalKey.all.map(&:filename).join("\n")
|
17
|
+
terminal.say "Associated Keys:"
|
18
|
+
authenticating_action do
|
19
|
+
terminal.say Backend::Key.all.map(&:title).join("\n")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "add [TITLE]", "add a new key"
|
25
|
+
def add(title = nil)
|
26
|
+
authenticating_action do
|
27
|
+
if key = get_or_generate_local_key
|
28
|
+
title ||= terminal.ask("Preparing to upload #{key.filename}. What title do you want to give it?")
|
29
|
+
remote_key = Backend::Key.from_local_key(key, title)
|
30
|
+
unless remote_key.save
|
31
|
+
terminal.say remote_key.errors.full_messages.join(", ")
|
32
|
+
end
|
33
|
+
else
|
34
|
+
terminal.say("Ok, remember that you'll need one if you want to upload code")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def get_or_generate_local_key
|
41
|
+
local_keys = Backend::LocalKey.all
|
42
|
+
case local_keys.length
|
43
|
+
when 0
|
44
|
+
Backend::LocalKey.generate if terminal.agree("Could not find a existing public key. Do you want me to create one? [Yn]")
|
45
|
+
when 1
|
46
|
+
terminal.say("Found a existing key: #{local_keys.first.filepath}")
|
47
|
+
local_keys.first
|
48
|
+
else
|
49
|
+
terminal.say("Found these keys:")
|
50
|
+
terminal.choose do |menu|
|
51
|
+
menu.prompt = "Please choose the one you want to use:"
|
52
|
+
menu.choices(*local_keys)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'highline'
|
3
|
+
|
4
|
+
require 'nuvado/base_command'
|
5
|
+
require 'nuvado/keys'
|
6
|
+
require 'nuvado/apps'
|
7
|
+
require 'nuvado/generate'
|
8
|
+
|
9
|
+
module Nuvado
|
10
|
+
class Nuvado < BaseCommand
|
11
|
+
|
12
|
+
desc "login [USERNAME] [PASSWORD]", "Login to nuvado"
|
13
|
+
def login(username = nil, password = nil)
|
14
|
+
username ||= terminal.ask("Please type your username")
|
15
|
+
password ||= terminal.ask("Please type your password"){|q| q.echo = false}
|
16
|
+
token = Backend::Session.create(username: username, password: password).authentication_token
|
17
|
+
Backend::TokenStore.write_token username, token
|
18
|
+
terminal.say "Login successful!"
|
19
|
+
Keys.start(["add"])
|
20
|
+
token
|
21
|
+
rescue ActiveResource::UnauthorizedAccess => e
|
22
|
+
raise WrongAuthParamsException
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "apps SUBCOMMAND [<ARGS>]", "Manage apps"
|
26
|
+
subcommand "apps", Apps
|
27
|
+
|
28
|
+
desc "keys SUBCOMMAND [<ARGS>]", "Manage keys"
|
29
|
+
subcommand "keys", Keys
|
30
|
+
|
31
|
+
register Generate, 'generate', 'generate', 'Generate an application from a template'
|
32
|
+
end
|
33
|
+
end
|
data/lib/nuvado/os.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module OS
|
2
|
+
def self.windows?
|
3
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.mac?
|
7
|
+
(/darwin/ =~ RUBY_PLATFORM) != nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.unix?
|
11
|
+
!windows?
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.linux?
|
15
|
+
unix? && !mac?
|
16
|
+
end
|
17
|
+
|
18
|
+
# for ssh stuff
|
19
|
+
def self.home_directory
|
20
|
+
windows? ? ENV['USERPROFILE'].gsub("\\","/") : ENV['HOME']
|
21
|
+
end
|
22
|
+
end
|