mozzn 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/mozzn +2 -0
- data/lib/mozzn/api.rb +5 -1
- data/lib/mozzn/cli.rb +11 -320
- data/lib/mozzn/commands/app.rb +222 -0
- data/lib/mozzn/commands/auth.rb +102 -0
- data/lib/mozzn/commands/key.rb +56 -0
- data/lib/mozzn/version.rb +1 -1
- data/spec/app_spec.rb +61 -0
- data/spec/auth_spec.rb +184 -0
- data/spec/cli_spec.rb +0 -308
- data/spec/key_spec.rb +52 -0
- data/spec/spec_helper.rb +12 -8
- metadata +12 -12
- data/spec/factories/applications.rb +0 -14
- data/spec/factories/components.rb +0 -10
- data/spec/factories/datastores.rb +0 -10
- data/spec/factories/keys.rb +0 -10
- data/spec/factories/users.rb +0 -10
@@ -0,0 +1,102 @@
|
|
1
|
+
module Mozzn
|
2
|
+
module Commands
|
3
|
+
class Auth < Thor
|
4
|
+
desc 'register', 'Create an account on mozzn'
|
5
|
+
|
6
|
+
method_option :name, :aliases => "-n", :desc => "Username."
|
7
|
+
method_option :email, :aliases => "-u", :desc => "User email used to login."
|
8
|
+
method_option :password, :aliases => "-p", :desc => "User password."
|
9
|
+
method_option :password_confirmation, :aliases => "-c", :desc => "Password_confirmation."
|
10
|
+
def register
|
11
|
+
mozzn = Mozzn::Api.new
|
12
|
+
if options.present?
|
13
|
+
name = options[:name]
|
14
|
+
email = options[:email]
|
15
|
+
password = options[:password]
|
16
|
+
password_confirmation = options[:password_confirmation]
|
17
|
+
else
|
18
|
+
h = HighLine.new
|
19
|
+
name = h.ask("Username: ")
|
20
|
+
email = h.ask("Email: ")
|
21
|
+
password = h.ask("Password: ")
|
22
|
+
password_confirmation = h.ask("password_confirmation: ")
|
23
|
+
end
|
24
|
+
params = {
|
25
|
+
user: {
|
26
|
+
name: name,
|
27
|
+
email: email,
|
28
|
+
password: password,
|
29
|
+
password_confirmation: password_confirmation
|
30
|
+
}
|
31
|
+
}
|
32
|
+
response = mozzn.post(:registrations, params)
|
33
|
+
errors = response['data']['errors']
|
34
|
+
if errors.present?
|
35
|
+
errors = JSON.parse(errors)
|
36
|
+
say "#{response['info']}, the following errors were found:\n * #{errors.map {|e| e.join(' ')}.join("\n * ")}\nPlease try again.", :red
|
37
|
+
# TODO: re-run registration
|
38
|
+
else
|
39
|
+
say response['info'], :green
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'login', 'Login with your mozzn credentials, an interactive shell will ask you about your email and password'
|
44
|
+
# mozzn login
|
45
|
+
method_option :email, :aliases => "-u", :desc => "Mozzn email"
|
46
|
+
method_option :password, :aliases => "-p", :desc => "Mozzn password"
|
47
|
+
def login
|
48
|
+
mozzn = Mozzn::Api.new
|
49
|
+
if options[:email].nil? && options[:password].nil?
|
50
|
+
hl = HighLine.new
|
51
|
+
email = hl.ask 'Mozzn email: '
|
52
|
+
password = hl.ask('Mozzn password (we will not store this): ') { |q| q.echo = "*" }
|
53
|
+
elsif options[:email].nil? || options[:password].nil?
|
54
|
+
raise Thor::Error, "Email and password must be provided!"
|
55
|
+
else
|
56
|
+
email = options[:email]
|
57
|
+
password = options[:password]
|
58
|
+
end
|
59
|
+
params = {
|
60
|
+
user: {
|
61
|
+
email: email,
|
62
|
+
password: password
|
63
|
+
}
|
64
|
+
}
|
65
|
+
response = mozzn.post(:sessions, params)
|
66
|
+
auth_token = response['data']['auth_token']
|
67
|
+
if auth_token == nil
|
68
|
+
raise Thor::Error, response['info']
|
69
|
+
else
|
70
|
+
Mozzn::Config.new.add('token', auth_token)
|
71
|
+
say response['info'], :green
|
72
|
+
git_check
|
73
|
+
ssh_key_check
|
74
|
+
end
|
75
|
+
rescue Mozzn::Disconnected
|
76
|
+
say 'Unable to connect to Mozzn. Please check your internet connection.', :red
|
77
|
+
rescue Mozzn::UnexpectedOutput
|
78
|
+
say 'UnexpectedOutput', :red
|
79
|
+
end
|
80
|
+
|
81
|
+
no_commands do
|
82
|
+
desc 'git_check', 'checks if user has git installed in $PATH or not'
|
83
|
+
def git_check
|
84
|
+
line = Cocaine::CommandLine.new("which git")
|
85
|
+
begin
|
86
|
+
output = line.run
|
87
|
+
rescue Cocaine::ExitStatusError => e
|
88
|
+
raise Thor::Error, 'Unable to find git it is either not installed or not in your $PATH. You may need to install it or add it to $PATH.'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
desc 'ssh_key_check', 'checks if user has ssh key in ~/.ssh path'
|
93
|
+
def ssh_key_check
|
94
|
+
ssh = ['~/.ssh/id_rsa.pub','~/.ssh/id_dsa.pub']
|
95
|
+
unless ssh.map { |ssh| File.exist?(File.expand_path(ssh))}
|
96
|
+
raise Thor::Error, "Unable to find an SSH key in #{File.expand_path('~/.ssh/')}. "
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Mozzn
|
2
|
+
module Commands
|
3
|
+
class Key < Thor
|
4
|
+
desc 'add', 'Add your SSH Public Key directily or add its path'
|
5
|
+
method_option :public_key, :aliases => "-k", :desc => "RSA/DSA public key"
|
6
|
+
method_option :key_path, :aliases => "-p", :desc => "Path to RSA/DSA public key"
|
7
|
+
def add
|
8
|
+
token = Mozzn::Config.new.read['token']
|
9
|
+
if token.nil?
|
10
|
+
raise Thor::Error,"You need to login in order to continue."
|
11
|
+
end
|
12
|
+
mozzn = Mozzn::Api.new(Mozzn::Config.new.read['token'])
|
13
|
+
if options[:key_path].present?
|
14
|
+
key_path = File.expand_path(options[:key_path])
|
15
|
+
elsif options[:public_key].present?
|
16
|
+
public_key = options[:public_key]
|
17
|
+
else
|
18
|
+
raise Thor::Error, "Neither a key path or an SSH key were provided. You must use -p or -k options."
|
19
|
+
end
|
20
|
+
|
21
|
+
if public_key.nil?
|
22
|
+
if File.exist?(key_path)
|
23
|
+
File.open(key_path, "rb") do |f|
|
24
|
+
public_key = f.read
|
25
|
+
end
|
26
|
+
else
|
27
|
+
raise Thor::Error, "Unable to read #{key_path}. File does not exist or not accessible."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
path = 'keys'
|
32
|
+
params = {
|
33
|
+
key: {
|
34
|
+
public: public_key
|
35
|
+
}
|
36
|
+
}
|
37
|
+
response = mozzn.post(path, params)
|
38
|
+
say response['info'], :green
|
39
|
+
rescue Mozzn::Disconnected
|
40
|
+
say 'Unable to connect to Mozzn check the internet connection!', :red
|
41
|
+
rescue Mozzn::UnexpectedOutput
|
42
|
+
say 'UnexpectedOutput', :red
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'destroy', 'Delete specific SSH public Key.'
|
46
|
+
def destroy
|
47
|
+
# TODO
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'list', 'List all your SSH public keys.'
|
51
|
+
def list
|
52
|
+
# TODO
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/mozzn/version.rb
CHANGED
data/spec/app_spec.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mozzn::Commands::App do
|
4
|
+
before :each do
|
5
|
+
@app = Mozzn::Commands::App.new
|
6
|
+
end
|
7
|
+
describe "mozzn create_app" do
|
8
|
+
describe "with valid params" do
|
9
|
+
it "returns Application created successfuly" do
|
10
|
+
capture(:stdout) { valid_user }
|
11
|
+
output = capture(:stdout) { @app.create "#{unique_name}" }
|
12
|
+
one,two = output.split("\n")
|
13
|
+
expect(one).to match('Application created successfuly')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
describe "with invalid params" do
|
17
|
+
it "returns creating faild " do
|
18
|
+
capture(:stdout) { valid_user }
|
19
|
+
expect { @app.create "App name" }.to raise_error(Thor::Error, "creating faild")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "without params " do
|
24
|
+
it "returns You must enter Application Name! " do
|
25
|
+
expect { @app.create }.to raise_error(Thor::Error, "You must enter application name.")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
describe "mozzn resources" do
|
30
|
+
describe "With valid params" do
|
31
|
+
describe "With an existing App" do
|
32
|
+
it "returns No assigned resources for this application." do
|
33
|
+
pending
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "With an existing App having no datastores or components" do
|
38
|
+
it "returns No assigned resources for this application." do
|
39
|
+
pending
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
describe "With invalid parameters" do
|
44
|
+
describe "with unauthorized user" do
|
45
|
+
it "returns HTTP code 422" do
|
46
|
+
pending
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "With not existing App" do
|
51
|
+
it "returns Application not found" do
|
52
|
+
name = 'not_existing_app'
|
53
|
+
@app.options = {
|
54
|
+
appname: name
|
55
|
+
}
|
56
|
+
expect { @app.resources }.to raise_error(Thor::Error, "Application was not found")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/auth_spec.rb
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mozzn::Commands::Auth do
|
4
|
+
before :each do
|
5
|
+
@auth = Mozzn::Commands::Auth.new
|
6
|
+
end
|
7
|
+
describe "mozzn login" do
|
8
|
+
describe "with valid params " do
|
9
|
+
it "returns Successfully logged in." do
|
10
|
+
@auth.options = {
|
11
|
+
email:'test@mozzn.com',
|
12
|
+
password: '12345678'
|
13
|
+
}
|
14
|
+
output = capture(:stdout) { @auth.login }
|
15
|
+
one,two = output.split("\n")
|
16
|
+
expect(one).to match('Signed in successfully.')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "with long_string email and password " do
|
21
|
+
it "returns Long email or password." do
|
22
|
+
@auth.options = {
|
23
|
+
email: long_string,
|
24
|
+
password: long_string
|
25
|
+
}
|
26
|
+
expect { @auth.login }.to raise_error(Thor::Error, "Invalid email or password.")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "with invalid params " do
|
31
|
+
it "returns Invalid email or password." do
|
32
|
+
@auth.options = {
|
33
|
+
email: 'invalid@example.com',
|
34
|
+
password: '12345678'
|
35
|
+
}
|
36
|
+
expect { @auth.login }.to raise_error(Thor::Error, "Invalid email or password.")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "with nil params " do
|
41
|
+
it "returns Invalid email or password." do
|
42
|
+
@auth.options = {
|
43
|
+
email: '',
|
44
|
+
password: ''
|
45
|
+
}
|
46
|
+
expect { @auth.login }.to raise_error(Thor::Error, "Invalid email or password.")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "without email " do
|
51
|
+
it "returns Email and password must be provided! " do
|
52
|
+
@auth.options = {
|
53
|
+
password: '12345678'
|
54
|
+
}
|
55
|
+
expect { @auth.login }.to raise_error(Thor::Error, "Email and password must be provided!")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "without password " do
|
60
|
+
it "returns Email and password must be provided! " do
|
61
|
+
@auth.options = {
|
62
|
+
email: 'rania@overcstudios.com'
|
63
|
+
}
|
64
|
+
expect { @auth.login }.to raise_error(Thor::Error, "Email and password must be provided!")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "with no params " do
|
69
|
+
it "returns an interactive shell asking for email and password" do
|
70
|
+
pending
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
describe "mozzn registration" do
|
75
|
+
describe "with valid params" do
|
76
|
+
it "returns Succesfully registered" do
|
77
|
+
@auth.options = {
|
78
|
+
name: 'rania',
|
79
|
+
email: unique_email ,
|
80
|
+
password: '12345678',
|
81
|
+
password_confirmation: '12345678'
|
82
|
+
}
|
83
|
+
output = capture(:stdout) { @auth.register }
|
84
|
+
output.chomp!
|
85
|
+
expect(output).to match("Successfully registered")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "with missing email" do
|
90
|
+
it "should return email missing" do
|
91
|
+
@auth.options = {
|
92
|
+
name: 'rania',
|
93
|
+
password: '12345678',
|
94
|
+
password_confirmation: '12345678'
|
95
|
+
}
|
96
|
+
output = capture(:stdout) { @auth.register }
|
97
|
+
output.chomp!
|
98
|
+
expect(output).to be =~ /email/
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "with missing password" do
|
103
|
+
it "should return password missing" do
|
104
|
+
@auth.options = {
|
105
|
+
name: 'rania',
|
106
|
+
email: unique_name,
|
107
|
+
password_confirmation: '12345678'
|
108
|
+
}
|
109
|
+
output = capture(:stdout) { @auth.register }
|
110
|
+
output.chomp!
|
111
|
+
expect(output).to be =~ /password/
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "with missing confirmation Password" do
|
116
|
+
it "should return password confirmation Missing" do
|
117
|
+
@auth.options = {
|
118
|
+
name: 'rania',
|
119
|
+
email: unique_email,
|
120
|
+
password: '12345678'
|
121
|
+
}
|
122
|
+
output = capture(:stdout) { @auth.register }
|
123
|
+
output.chomp!
|
124
|
+
expect(output).to be =~ /password_confirmation/
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "with invalid email" do
|
129
|
+
it "should return invalid email" do
|
130
|
+
@auth.options = {
|
131
|
+
name: 'rania',
|
132
|
+
email: 'qqqqqqq',
|
133
|
+
password: '12345678',
|
134
|
+
password_confirmation: '12345678'
|
135
|
+
}
|
136
|
+
output = capture(:stdout) { @auth.register }
|
137
|
+
output.chomp!
|
138
|
+
expect(output).to be =~ /email/
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "with short password" do
|
143
|
+
it "should short password" do
|
144
|
+
@auth.options = {
|
145
|
+
name: 'rania',
|
146
|
+
email: unique_email,
|
147
|
+
password: '123',
|
148
|
+
password_confirmation: '123'
|
149
|
+
}
|
150
|
+
output = capture(:stdout) { @auth.register }
|
151
|
+
output.chomp!
|
152
|
+
expect(output).to be =~ /password/
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe "with unmatched password and confirmation password" do
|
157
|
+
it "should return password and confirmation password are not matched" do
|
158
|
+
@auth.options = {
|
159
|
+
name: 'rania',
|
160
|
+
email: unique_email,
|
161
|
+
password: '12345678',
|
162
|
+
password_confirmation: '87654321'
|
163
|
+
}
|
164
|
+
output = capture(:stdout) { @auth.register }
|
165
|
+
output.chomp!
|
166
|
+
expect(output).to be =~ /password_confirmation/
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "with nil parammeters" do
|
171
|
+
it "should return Parameter Missing" do
|
172
|
+
@auth.options = {
|
173
|
+
name: nil,
|
174
|
+
email: nil,
|
175
|
+
password: nil,
|
176
|
+
password_confirmation: nil
|
177
|
+
}
|
178
|
+
output = capture(:stdout) { @auth.register }
|
179
|
+
output.chomp!
|
180
|
+
expect(output).to be =~ /email/
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|