zedkit 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/zedkit.rb +19 -6
- data/lib/zedkit/cli/bottom.rb +12 -10
- data/lib/zedkit/cli/text.rb +57 -55
- data/lib/zedkit/client/client.rb +15 -16
- data/lib/zedkit/rails/sessions.rb +90 -0
- data/test/test_projects.rb +2 -2
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.4
|
data/lib/zedkit.rb
CHANGED
@@ -19,7 +19,7 @@ require 'rubygems'
|
|
19
19
|
require 'json'
|
20
20
|
require 'nestful'
|
21
21
|
|
22
|
-
|
22
|
+
require 'zedkit/ext/hash.rb'
|
23
23
|
|
24
24
|
module Zedkit
|
25
25
|
class << self
|
@@ -60,12 +60,25 @@ module Zedkit
|
|
60
60
|
attr_accessor :configuration
|
61
61
|
def configure
|
62
62
|
self.configuration ||= Configuration.new
|
63
|
-
yield
|
63
|
+
yield configuration
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
require 'zedkit/client/configuration.rb'
|
69
|
+
require 'zedkit/client/client.rb'
|
70
|
+
require 'zedkit/client/exceptions.rb'
|
71
|
+
|
72
|
+
require 'zedkit/cli/bottom.rb'
|
73
|
+
require 'zedkit/cli/exceptions.rb'
|
74
|
+
require 'zedkit/cli/projects.rb'
|
75
|
+
require 'zedkit/cli/runner.rb'
|
76
|
+
require 'zedkit/cli/text.rb'
|
77
|
+
|
78
|
+
require 'zedkit/instances/instance.rb'
|
79
|
+
require 'zedkit/instances/project.rb'
|
80
|
+
|
81
|
+
require 'zedkit/resources/projects.rb'
|
82
|
+
require 'zedkit/resources/users.rb'
|
83
|
+
|
84
|
+
require 'zedkit/rails/sessions' if defined?(Rails::Railtie)
|
data/lib/zedkit/cli/bottom.rb
CHANGED
@@ -15,17 +15,19 @@
|
|
15
15
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
16
|
##
|
17
17
|
|
18
|
-
module Zedkit
|
19
|
-
|
20
|
-
class
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
module Zedkit
|
19
|
+
module CLI
|
20
|
+
class Bottom
|
21
|
+
class << self
|
22
|
+
def method_missing(*args)
|
23
|
+
raise Zedkit::CLI::UnknownCommand.new(:message => "#{Zedkit::CLI.ee(args[1][:locale], :general, :unknown)}" \
|
24
|
+
<< " [#{args[0]}]")
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
protected
|
28
|
+
def dashes(length = 128)
|
29
|
+
Array.new(length, '-').join << "\n"
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/zedkit/cli/text.rb
CHANGED
@@ -15,68 +15,70 @@
|
|
15
15
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
16
|
##
|
17
17
|
|
18
|
-
module Zedkit
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
module Zedkit
|
19
|
+
module CLI
|
20
|
+
class << self
|
21
|
+
def tt(locale, key, item)
|
22
|
+
Zedkit::CLI.lookup_tt("Zedkit::CLI", locale, key, item)
|
23
|
+
end
|
24
|
+
def ee(locale, key, item)
|
25
|
+
Zedkit::CLI.lookup_ee("Zedkit::CLI", locale, key, item)
|
26
|
+
end
|
22
27
|
end
|
23
|
-
def ee(locale, key, item)
|
24
|
-
Zedkit::CLI.lookup_ee("Zedkit::CLI", locale, key, item)
|
25
|
-
end
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
LOCALES = %w(en).freeze
|
30
|
+
CONTENT = {
|
31
|
+
:en => {
|
32
|
+
:commands => {
|
33
|
+
:projects => "Project Commands",
|
34
|
+
:projects_list => "List Zedkit projects",
|
35
|
+
:projects_show => "Show Zedkit project details",
|
36
|
+
:projects_create => "Create a new Zedkit project",
|
37
|
+
:projects_update => "Update an existing Zedkit project",
|
38
|
+
:projects_delete => "Delete an existing Zedkit project"
|
39
|
+
}
|
38
40
|
}
|
39
41
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
42
|
+
ERRORS = {
|
43
|
+
:en => {
|
44
|
+
:runner => {
|
45
|
+
:credentials => "Missing Zedkit Credentials",
|
46
|
+
:zedkit_file => "Missing Zedkit Credentials in ~/.zedkit"
|
47
|
+
},
|
48
|
+
:general => {
|
49
|
+
:error => "Zedkit CLI ERROR.",
|
50
|
+
:message => "Message",
|
51
|
+
:section => "Unknown Section",
|
52
|
+
:unknown => "Unknown Command",
|
53
|
+
:not_done => "This operation is not yet implemented."
|
54
|
+
},
|
55
|
+
:project => {
|
56
|
+
:nil => "Project UUID is nil"
|
57
|
+
}
|
56
58
|
}
|
57
|
-
}
|
58
|
-
}.freeze
|
59
|
+
}.freeze
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
61
|
+
class << self
|
62
|
+
def lookup_tt(ch, locale, key, item)
|
63
|
+
rs = lookup(eval("#{ch}::CONTENT"), locale, key, item)
|
64
|
+
rs = lookup(eval("Zedkit::CLI::CONTENT"), locale, key, item) if rs.nil?
|
65
|
+
rs
|
66
|
+
end
|
67
|
+
def lookup_ee(ch, locale, key, item)
|
68
|
+
rs = lookup(eval("#{ch}::ERRORS"), locale, key, item)
|
69
|
+
rs = lookup(eval("Zedkit::CLI::ERRORS"), locale, key, item) if rs.nil?
|
70
|
+
rs
|
71
|
+
end
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
protected
|
74
|
+
def lookup(set, locale, key, item)
|
75
|
+
if set.has_key?(locale) && set[locale].has_key?(key) && set[locale][key].has_key?(item)
|
76
|
+
set[locale][key][item]
|
77
|
+
elsif set[:en].has_key?(key) && set[:en][key].has_key?(item)
|
78
|
+
set[:en][key][item]
|
79
|
+
else
|
80
|
+
nil end
|
81
|
+
end
|
80
82
|
end
|
81
83
|
end
|
82
84
|
end
|
data/lib/zedkit/client/client.rb
CHANGED
@@ -45,14 +45,15 @@ module Zedkit
|
|
45
45
|
|
46
46
|
protected
|
47
47
|
def submit_request(method, rs, user_key = nil, params = {}, options = {})
|
48
|
-
|
48
|
+
rh = nil
|
49
49
|
begin
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
http_request(method, resource_url(rs), user_key, params.flatten_zedkit_params!, options) do |nh|
|
51
|
+
rh = JSON.parse(nh)
|
52
|
+
if rh.is_a?(Hash) && rh.has_key?('status') && Zedkit.configuration.exceptions?
|
53
|
+
raise DataValidationError.new(:http_code => 200, :api_code => rh['status']['code'],
|
54
|
+
:errors => rh['errors'],
|
55
|
+
:message => rh['status']['message'] << " [#{method.upcase} #{resource_url(rs)}]")
|
56
|
+
end
|
56
57
|
end
|
57
58
|
rescue Net::HTTPBadResponse
|
58
59
|
## TBD
|
@@ -72,25 +73,23 @@ module Zedkit
|
|
72
73
|
:message => "Access Denied to the Resource Requested [#{method.upcase} #{resource_url(rs)}]")
|
73
74
|
end
|
74
75
|
end
|
75
|
-
|
76
|
+
rh
|
76
77
|
end
|
77
78
|
|
78
79
|
private
|
79
|
-
def http_request(method, rs_url, uk, params, options)
|
80
|
-
http = nil
|
80
|
+
def http_request(method, rs_url, uk, params, options, &block)
|
81
81
|
case method
|
82
82
|
when :verify
|
83
|
-
|
83
|
+
yield Nestful.get(rs_url, options.merge({ :params => merged_params(params) }))
|
84
84
|
when :get
|
85
|
-
|
85
|
+
yield Nestful.get(rs_url, options.merge({ :params => merged_params(params, uk) }))
|
86
86
|
when :post
|
87
|
-
|
87
|
+
yield Nestful.post(rs_url, options.merge({ :format => :form, :params => merged_params(params, uk) }))
|
88
88
|
when :put
|
89
|
-
|
89
|
+
yield Nestful.put(rs_url, options.merge({ :format => :form, :params => merged_params(params, uk) }))
|
90
90
|
when :delete
|
91
|
-
|
91
|
+
Nestful.delete(rs_url, options.merge({ :params => merged_params(params, uk) }))
|
92
92
|
end
|
93
|
-
http
|
94
93
|
end
|
95
94
|
def resource_url(rs)
|
96
95
|
"#{Zedkit.configuration.api_url}/#{rs}"
|
@@ -0,0 +1,90 @@
|
|
1
|
+
##
|
2
|
+
# Copyright (c) Zedkit.
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
# modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
# Software is furnished to do so, subject to the following conditions:
|
8
|
+
#
|
9
|
+
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
10
|
+
# Software.
|
11
|
+
#
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
13
|
+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
14
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
15
|
+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
##
|
17
|
+
|
18
|
+
module Zedkit
|
19
|
+
module Sessions
|
20
|
+
protected
|
21
|
+
def session_fresh?(options = {})
|
22
|
+
options[:idle_maximum_in_seconds] = 900 unless options.has_key? :idle_maximum_in_seconds
|
23
|
+
set_last_seen if session[:last_seen].nil?
|
24
|
+
return true if session[:last_seen] > (Time.now.to_i - options[:idle_maximum_in_seconds])
|
25
|
+
Rails.logger.info "Session has EXPIRED [#{options[:idle_maximum_in_seconds]}]"
|
26
|
+
false
|
27
|
+
end
|
28
|
+
def session_fresh_with_redirect?(options = {})
|
29
|
+
options[:idle_maximum_in_seconds] = 900 unless options.has_key? :idle_maximum_in_seconds
|
30
|
+
options[:url] = new_session_url unless options.has_key? :url
|
31
|
+
return true if session_fresh?(options)
|
32
|
+
end_session
|
33
|
+
redirect_to options[:url]
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def has_session?
|
38
|
+
return true if @user && @user.is_a?(Hash)
|
39
|
+
if session[:user_json] && session[:user_json].is_a?(Hash)
|
40
|
+
@user = session[:user_json]
|
41
|
+
return true
|
42
|
+
end
|
43
|
+
false
|
44
|
+
end
|
45
|
+
def has_session_with_redirect?(url = root_url)
|
46
|
+
return true if has_session?
|
47
|
+
redirect_to url
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
def has_had_a_session?
|
52
|
+
set_user_login unless @user_login && @user_login.is_a?(String)
|
53
|
+
return true if @user_login.present?
|
54
|
+
false
|
55
|
+
end
|
56
|
+
def has_user_login?
|
57
|
+
@user_login.present?
|
58
|
+
end
|
59
|
+
|
60
|
+
def start_session(login, password)
|
61
|
+
case request.method.downcase.to_sym
|
62
|
+
when :post
|
63
|
+
|
64
|
+
Rails.logger.info "User Verification Request via Zedkit [#{login.downcase}]"
|
65
|
+
Zedkit::Users.verify(:username => login.downcase, :password => password) do |json|
|
66
|
+
@user = json
|
67
|
+
session[:user_json] = @user ## This does not contain the user's password.
|
68
|
+
cookies[:user_login] = { :value => login.downcase, :expires => 365.days.from_now }
|
69
|
+
return true
|
70
|
+
end
|
71
|
+
|
72
|
+
else set_user_login end
|
73
|
+
false
|
74
|
+
end
|
75
|
+
def end_session
|
76
|
+
session[:user_json] = nil
|
77
|
+
end
|
78
|
+
|
79
|
+
def set_user_login
|
80
|
+
cookies[:user_login] ? @user_login = cookies[:user_login] : @user_login = nil
|
81
|
+
Rails.logger.info "User Login SET [#{@user_login}]"
|
82
|
+
end
|
83
|
+
def set_last_seen
|
84
|
+
session[:last_seen] = Time.new.to_i
|
85
|
+
end
|
86
|
+
def set_logout_method(method)
|
87
|
+
session[:logout_method] = method
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/test/test_projects.rb
CHANGED
@@ -114,13 +114,13 @@ class TestProjects < Test::Unit::TestCase
|
|
114
114
|
lk = Zedkit::Users.verify(:username => TEST_GEMS_LACKY, :password => TEST_GEMS_PASSWORD)
|
115
115
|
ud = Zedkit::Projects::Users.delete(:user_key => @uu['user_key'], :project => { :uuid => @uu['projects'][0] },
|
116
116
|
:user => { :uuid => lk['uuid'] })
|
117
|
-
|
117
|
+
assert_nil ud
|
118
118
|
end
|
119
119
|
def test_delete_user_connection_with_block
|
120
120
|
lk = Zedkit::Users.verify(:username => TEST_GEMS_LACKY, :password => TEST_GEMS_PASSWORD)
|
121
121
|
Zedkit::Projects::Users.delete(:user_key => @uu['user_key'], :project => { :uuid => @uu['projects'][0] },
|
122
122
|
:user => { :uuid => lk['uuid'] }) do |ud|
|
123
|
-
|
123
|
+
assert_nil ud
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 4
|
9
|
+
version: 1.1.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Zedkit
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-20 00:00:00 -08:00
|
18
18
|
default_executable: zedkit
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/zedkit/ext/hash.rb
|
74
74
|
- lib/zedkit/instances/instance.rb
|
75
75
|
- lib/zedkit/instances/project.rb
|
76
|
+
- lib/zedkit/rails/sessions.rb
|
76
77
|
- lib/zedkit/resources/projects.rb
|
77
78
|
- lib/zedkit/resources/users.rb
|
78
79
|
- test/helper.rb
|