zillabyte-cli 0.0.24 → 0.1.0
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 +6 -14
- data/lib/#zillabyte-cli.rb# +5 -0
- data/lib/zillabyte/api/apps.rb +16 -132
- data/lib/zillabyte/api/components.rb +115 -0
- data/lib/zillabyte/api/flows.rb +121 -0
- data/lib/zillabyte/api/keys.rb +70 -0
- data/lib/zillabyte/api.rb +15 -2
- data/lib/zillabyte/auth.rb +43 -16
- data/lib/zillabyte/cli/#logs.rb# +12 -0
- data/lib/zillabyte/cli/#repl.rb# +43 -0
- data/lib/zillabyte/cli/apps.rb +52 -893
- data/lib/zillabyte/cli/auth.rb +3 -8
- data/lib/zillabyte/cli/base.rb +28 -7
- data/lib/zillabyte/cli/components.rb +245 -0
- data/lib/zillabyte/cli/flows.rb +549 -0
- data/lib/zillabyte/cli/git.rb +38 -0
- data/lib/zillabyte/cli/help.rb +11 -4
- data/lib/zillabyte/cli/keys.rb +177 -0
- data/lib/zillabyte/cli/query.rb +0 -1
- data/lib/zillabyte/cli/relations.rb +2 -1
- data/lib/zillabyte/cli/templates/{js → apps/js}/simple_function.js +0 -0
- data/lib/zillabyte/cli/templates/{js → apps/js}/zillabyte.conf.yaml +0 -0
- data/lib/zillabyte/cli/templates/apps/python/app.py +17 -0
- data/lib/zillabyte/cli/templates/{python → apps/python}/requirements.txt +0 -0
- data/lib/zillabyte/cli/templates/{python → apps/python}/zillabyte.conf.yaml +1 -1
- data/lib/zillabyte/cli/templates/{ruby → apps/ruby}/Gemfile +0 -0
- data/lib/zillabyte/cli/templates/{ruby → apps/ruby}/app.rb +1 -1
- data/lib/zillabyte/cli/templates/{ruby → apps/ruby}/zillabyte.conf.yaml +0 -0
- data/lib/zillabyte/cli/templates/python/{simple_function.py → #simple_function.py#} +3 -6
- data/lib/zillabyte/common/session.rb +3 -1
- data/lib/zillabyte/helpers.rb +64 -1
- data/lib/zillabyte/runner/app_runner.rb +226 -0
- data/lib/zillabyte/runner/component_operation.rb +529 -0
- data/lib/zillabyte/runner/component_runner.rb +244 -0
- data/lib/zillabyte/runner/multilang_operation.rb +1133 -0
- data/lib/zillabyte/runner/operation.rb +11 -0
- data/lib/zillabyte/runner.rb +6 -0
- data/lib/zillabyte-cli/version.rb +1 -1
- data/zillabyte-cli.gemspec +1 -0
- metadata +83 -52
data/lib/zillabyte/auth.rb
CHANGED
@@ -9,9 +9,9 @@ class Zillabyte::Auth
|
|
9
9
|
|
10
10
|
attr_accessor :credentials
|
11
11
|
|
12
|
-
def login(auth_token)
|
13
|
-
if valid_credentials?(auth_token)
|
14
|
-
write_credentials(auth_token)
|
12
|
+
def login(email, auth_token)
|
13
|
+
if valid_credentials?(email, auth_token)
|
14
|
+
write_credentials(email, auth_token)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -31,17 +31,21 @@ class Zillabyte::Auth
|
|
31
31
|
def host
|
32
32
|
default_host
|
33
33
|
end
|
34
|
+
|
35
|
+
def git_host
|
36
|
+
ENV['ZILLABYTE_GIT_HOST'] || 'git.zillabyte.com'
|
37
|
+
end
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
39
|
+
def user # :nodoc:
|
40
|
+
get_credentials[0]
|
41
|
+
end
|
38
42
|
|
39
43
|
# def password # :nodoc:
|
40
44
|
# get_credentials[1]
|
41
45
|
# end
|
42
46
|
|
43
47
|
def api_key
|
44
|
-
get_credentials
|
48
|
+
get_credentials[1]
|
45
49
|
end
|
46
50
|
|
47
51
|
def get_credentials # :nodoc:
|
@@ -71,15 +75,25 @@ class Zillabyte::Auth
|
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
78
|
+
|
79
|
+
|
80
|
+
def email?(s)
|
81
|
+
!!(s =~ /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i)
|
82
|
+
end
|
74
83
|
|
75
84
|
def read_credentials
|
76
85
|
if ENV['ZILLABYTE_API_KEY']
|
77
|
-
ENV['ZILLABYTE_API_KEY']
|
86
|
+
ary = ENV['ZILLABYTE_API_KEY'].split(",")
|
87
|
+
if ary.size != 2 or !email?(ary[0])
|
88
|
+
abort("ZILLABYTE_API_KEY must be comma delimited: user@email.com,api_key")
|
89
|
+
end
|
90
|
+
ary
|
78
91
|
else
|
79
92
|
# read netrc credentials if they exist
|
80
93
|
if netrc
|
81
|
-
if netrc[host]
|
82
|
-
|
94
|
+
if netrc[host] && email?(netrc[host][0])
|
95
|
+
# Make sure we have the email address
|
96
|
+
netrc[host]
|
83
97
|
else
|
84
98
|
nil
|
85
99
|
end
|
@@ -87,11 +101,12 @@ class Zillabyte::Auth
|
|
87
101
|
end
|
88
102
|
end
|
89
103
|
|
90
|
-
def write_credentials(auth_token)
|
104
|
+
def write_credentials(email, auth_token)
|
91
105
|
begin
|
92
106
|
FileUtils.mkdir_p(File.dirname(netrc_path))
|
93
107
|
FileUtils.touch(netrc_path)
|
94
|
-
|
108
|
+
FileUtils.chmod 0600, netrc_path
|
109
|
+
netrc[host] = [email, auth_token]
|
95
110
|
netrc.save
|
96
111
|
rescue Zillabyte::Auth::NetrcError => error
|
97
112
|
display 'Netrc Read or Save Error'
|
@@ -135,7 +150,7 @@ class Zillabyte::Auth
|
|
135
150
|
end
|
136
151
|
end
|
137
152
|
|
138
|
-
def valid_credentials?(auth_token)
|
153
|
+
def valid_credentials?(email, auth_token)
|
139
154
|
api = Zillabyte::API.new(:api_key => auth_token, :session => self)
|
140
155
|
response = api.request(
|
141
156
|
:expects => 200,
|
@@ -143,7 +158,6 @@ class Zillabyte::Auth
|
|
143
158
|
:path => "/cli/login"
|
144
159
|
)
|
145
160
|
response.body != "authentication error"
|
146
|
-
|
147
161
|
end
|
148
162
|
|
149
163
|
def ask_for_and_save_credentials
|
@@ -162,17 +176,30 @@ class Zillabyte::Auth
|
|
162
176
|
msg = "Enter your Zillabyte credentials"
|
163
177
|
msg += " (or press enter to continue as an anonymous user)." if current_command == "relations"
|
164
178
|
puts msg
|
179
|
+
|
180
|
+
# Get the email address
|
181
|
+
print "Email: "
|
182
|
+
$stdout.flush()
|
183
|
+
email = ask
|
184
|
+
if email?(email) == false
|
185
|
+
display "invalid email"
|
186
|
+
exit 1
|
187
|
+
end
|
188
|
+
|
189
|
+
# Get the auth token
|
165
190
|
print "Auth Token: "
|
166
191
|
$stdout.flush()
|
167
192
|
auth_token = ask
|
168
193
|
print "\n"
|
194
|
+
|
169
195
|
if current_command == "relations" and auth_token == ""
|
170
196
|
display "No auth token provided, continuing as anonymous user. Note that you will only be shown publicly available listings."
|
171
197
|
else
|
172
|
-
if not valid_credentials?(auth_token)
|
198
|
+
if not valid_credentials?(email, auth_token)
|
173
199
|
raise Zillabyte::Auth::InvalidCredentialsException
|
174
200
|
else
|
175
|
-
|
201
|
+
# Success...
|
202
|
+
write_credentials(email, auth_token)
|
176
203
|
end
|
177
204
|
end
|
178
205
|
rescue Zillabyte::Auth::InvalidCredentialsException => e
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "zillabyte/cli/base"
|
2
|
+
require 'readline'
|
3
|
+
# REPL console for zillabyte commands
|
4
|
+
#
|
5
|
+
class Zillabyte::Command::Repl < Zillabyte::Command::Base
|
6
|
+
|
7
|
+
# repl
|
8
|
+
#
|
9
|
+
# start a console session for zillabyte
|
10
|
+
# --quiet # HIDDEN
|
11
|
+
# --history HISTORY# HIDDEN hack to allow history for readline
|
12
|
+
def index
|
13
|
+
if !options[:quiet]
|
14
|
+
v = `zillabyte version`
|
15
|
+
display "\n#{v}Type q,exit or Ctrl+D to quit\n\n"
|
16
|
+
end
|
17
|
+
server = `echo $ZILLABYTE_API_HOST` || ""
|
18
|
+
prompt = ""
|
19
|
+
if server && server.chomp.length > 0
|
20
|
+
prompt = "#{server.chomp} "
|
21
|
+
end
|
22
|
+
prompt += "zillabyte $ "
|
23
|
+
if options[:history]
|
24
|
+
#p options[:history]
|
25
|
+
history = JSON.parse(options[:history])
|
26
|
+
history.last(50).each do |his|
|
27
|
+
# TODO: Handle single quotes ??
|
28
|
+
Readline::HISTORY << his
|
29
|
+
end
|
30
|
+
end
|
31
|
+
# TODO: Add tab completion for basic commands, app/relation names etc.
|
32
|
+
while cmd = Readline.readline(prompt, true)
|
33
|
+
if cmd && cmd.length > 0
|
34
|
+
if cmd.downcase == "exit" || cmd.downcase == "q"
|
35
|
+
display "" # TODO Make Ctrl+D print a newline too
|
36
|
+
return
|
37
|
+
else
|
38
|
+
exec "zillabyte #{cmd}; zillabyte repl --quiet --history '#{Readline::HISTORY.to_a.to_json}'"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|