visor-auth 0.0.2 → 0.0.3
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.
- data/bin/visor-admin +38 -56
- data/lib/auth/cli.rb +7 -10
- data/lib/auth/client.rb +1 -1
- data/lib/auth/server.rb +14 -6
- data/lib/auth/version.rb +1 -1
- metadata +2 -2
data/bin/visor-admin
CHANGED
@@ -63,7 +63,6 @@ class VisorAdminCLI
|
|
63
63
|
|
64
64
|
opts.separator ""
|
65
65
|
opts.separator "Common options:"
|
66
|
-
opts.on_tail("-D", "--dry-run", "Don't persist results, just print what would it do") { options[:dry] = true }
|
67
66
|
opts.on_tail('-v', '--verbose', "Enable verbose") { options[:verbose] = true }
|
68
67
|
opts.on_tail("-h", "--help", "Show this help message") { puts opts; exit 0 }
|
69
68
|
opts.on_tail('-V', '--version', "Show version") { puts "VISoR Admin CLI v#{VERSION}"; exit 0 }
|
@@ -80,22 +79,31 @@ class VisorAdminCLI
|
|
80
79
|
def run!
|
81
80
|
abort parser.to_s if command.nil?
|
82
81
|
start = Time.now
|
83
|
-
|
84
|
-
|
85
|
-
list
|
86
|
-
|
87
|
-
get
|
88
|
-
|
89
|
-
add
|
90
|
-
|
91
|
-
update
|
92
|
-
|
93
|
-
delete
|
94
|
-
|
95
|
-
help
|
96
|
-
|
97
|
-
|
82
|
+
begin
|
83
|
+
case command
|
84
|
+
when 'list' then
|
85
|
+
list
|
86
|
+
when 'get' then
|
87
|
+
get
|
88
|
+
when 'add' then
|
89
|
+
add
|
90
|
+
when 'update' then
|
91
|
+
update
|
92
|
+
when 'delete' then
|
93
|
+
delete
|
94
|
+
when 'help' then
|
95
|
+
help
|
96
|
+
else
|
97
|
+
abort "Unknown command '#{command}'"
|
98
|
+
end
|
99
|
+
rescue NotFound => e
|
100
|
+
puts e.message
|
101
|
+
rescue Errno::ECONNREFUSED
|
102
|
+
abort "Failure while executing '#{command}': VISOR Auth System server not found. Is it running?"
|
103
|
+
rescue => e
|
104
|
+
abort "Failure while executing '#{command}': #{e}"
|
98
105
|
end
|
106
|
+
|
99
107
|
finish = Time.now
|
100
108
|
printf("Done in %-0.4f seconds", finish - start) if verbose?
|
101
109
|
exit 0
|
@@ -106,10 +114,6 @@ class VisorAdminCLI
|
|
106
114
|
users = client.get_users(options[:query])
|
107
115
|
puts "Found #{users.size} users..."
|
108
116
|
print_users(users)
|
109
|
-
rescue NotFound => e
|
110
|
-
puts e.message
|
111
|
-
rescue => e
|
112
|
-
abort "Failure while executing 'list':\n#{e.message}"
|
113
117
|
end
|
114
118
|
|
115
119
|
# Retrieve an user
|
@@ -118,56 +122,34 @@ class VisorAdminCLI
|
|
118
122
|
abort "No user access key provided as first argument, please provide it." unless access_key
|
119
123
|
user = client.get_user(access_key)
|
120
124
|
print_users(user)
|
121
|
-
rescue NotFound => e
|
122
|
-
puts e.message
|
123
|
-
rescue => e
|
124
|
-
abort "Failure while executing 'get':\n#{e.message}"
|
125
125
|
end
|
126
126
|
|
127
127
|
# Add a new user
|
128
128
|
def add
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
print_users(user)
|
134
|
-
rescue NotFound => e
|
135
|
-
puts e.message
|
136
|
-
rescue => e
|
137
|
-
abort "Failure while executing 'add':\n#{e.message}"
|
138
|
-
end
|
129
|
+
info = parse_info_from_args
|
130
|
+
user = client.post_user(info)
|
131
|
+
puts "Successfully added new user with access key '#{user[:access_key]}'."
|
132
|
+
print_users(user)
|
139
133
|
end
|
140
134
|
|
141
135
|
# Update an user
|
142
136
|
def update
|
143
137
|
access_key = argv.shift
|
144
138
|
abort "No user access key provided as first argument, please provide it." unless access_key
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
print_users(user) if verbose?
|
150
|
-
rescue NotFound => e
|
151
|
-
puts e.message
|
152
|
-
rescue => e
|
153
|
-
abort "Failure while executing 'update':\n#{e.message}"
|
154
|
-
end
|
139
|
+
info = parse_info_from_args
|
140
|
+
user = client.put_user(access_key, info)
|
141
|
+
puts "Successfully updated the user #{access_key}."
|
142
|
+
print_users(user) if verbose?
|
155
143
|
end
|
156
144
|
|
157
145
|
# Delete an user
|
158
146
|
def delete
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
print_users(user) if verbose?
|
165
|
-
end
|
147
|
+
argv.each do |access_key|
|
148
|
+
abort "No user access key provided as first argument, please provide it." unless access_key
|
149
|
+
user = client.delete_user(access_key)
|
150
|
+
puts "Successfully deleted user #{access_key}."
|
151
|
+
print_users(user) if verbose?
|
166
152
|
end
|
167
|
-
rescue NotFound => e
|
168
|
-
puts e.message
|
169
|
-
rescue => e
|
170
|
-
abort "Failure while executing 'delete':\n#{e.message}"
|
171
153
|
end
|
172
154
|
|
173
155
|
# Show help message for one of the above commands
|
@@ -185,7 +167,7 @@ You can filter results based on a query using the --query (-q) option.
|
|
185
167
|
|
186
168
|
Examples:
|
187
169
|
$ visor-admin list
|
188
|
-
$ visor-admin list --query email=foo@bar.com]
|
170
|
+
$ visor-admin list --query 'access_key=foo&email=foo@bar.com']
|
189
171
|
when :get
|
190
172
|
puts %q[Usage: visor-admin get <ACCESS KEY> [options]
|
191
173
|
|
data/lib/auth/cli.rb
CHANGED
@@ -61,34 +61,31 @@ module Visor
|
|
61
61
|
opts.on("-c", "--config FILE", "Load a custom configuration file") do |file|
|
62
62
|
options[:config] = File.expand_path(file)
|
63
63
|
end
|
64
|
-
opts.on("-
|
64
|
+
opts.on("-a", "--address HOST", "Bind to HOST address (default: #{DEFAULT_HOST})") do |host|
|
65
65
|
options[:host] = host.to_s
|
66
66
|
end
|
67
|
-
opts.on("-p", "--port PORT", "
|
67
|
+
opts.on("-p", "--port PORT", "Bind to PORT number (default: #{DEFAULT_PORT})") do |port|
|
68
68
|
options[:port] = port.to_i
|
69
69
|
end
|
70
|
-
opts.on("-
|
71
|
-
options[:no_proxy] = true
|
72
|
-
end
|
73
|
-
opts.on("-e", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: #{DEFAULT_ENV})") do |env|
|
70
|
+
opts.on("-e", "--env ENV", "Set execution environment (default: #{DEFAULT_ENV})") do |env|
|
74
71
|
options[:environment] = env.to_sym
|
75
72
|
end
|
76
|
-
opts.on("-
|
73
|
+
opts.on("-f", "--foreground", "Do not daemonize, run in foreground") do
|
77
74
|
options[:foreground] = true
|
78
75
|
end
|
79
76
|
|
80
77
|
opts.separator ""
|
81
78
|
opts.separator "Common options:"
|
82
79
|
|
83
|
-
opts.on_tail("-d", "--debug", "
|
80
|
+
opts.on_tail("-d", "--debug", "Enable debugging") do
|
84
81
|
options[:debug] = true
|
85
82
|
end
|
86
|
-
opts.on_tail("-h", "--help", "Show this message") do
|
83
|
+
opts.on_tail("-h", "--help", "Show this help message") do
|
87
84
|
puts opts
|
88
85
|
exit
|
89
86
|
end
|
90
87
|
opts.on_tail('-v', '--version', "Show version") do
|
91
|
-
puts "
|
88
|
+
puts "visor-auth #{Visor::Auth::VERSION}"
|
92
89
|
exit
|
93
90
|
end
|
94
91
|
end
|
data/lib/auth/client.rb
CHANGED
@@ -74,7 +74,7 @@ module Visor
|
|
74
74
|
|
75
75
|
# Generate a valid URI query string from key/value pairs of the given hash.
|
76
76
|
#
|
77
|
-
# @param
|
77
|
+
# @param h [Hash] The hash with the key/value pairs to generate query from.
|
78
78
|
#
|
79
79
|
# @return [String] The generated query in the form of "?k=v&k1=v1".
|
80
80
|
#
|
data/lib/auth/server.rb
CHANGED
@@ -5,7 +5,7 @@ require 'uri'
|
|
5
5
|
module Visor
|
6
6
|
module Auth
|
7
7
|
|
8
|
-
# The VISoR Auth
|
8
|
+
# The VISoR Auth System (VAS) server class. This class supports all users management
|
9
9
|
# operations through the REST API implemented along the following routes.
|
10
10
|
#
|
11
11
|
class Server < Sinatra::Base
|
@@ -18,12 +18,20 @@ module Visor
|
|
18
18
|
backend_map = {'mongodb' => Visor::Auth::Backends::MongoDB,
|
19
19
|
'mysql' => Visor::Auth::Backends::MySQL}
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
begin
|
22
|
+
conf = Visor::Common::Config.load_config(:visor_auth)
|
23
|
+
log = Visor::Common::Config.build_logger(:visor_auth)
|
24
|
+
rescue => e
|
25
|
+
STDERR.puts "ERROR starting visor-auth: (config file) 'visor_auth' section not found"
|
26
|
+
exit! 1
|
27
|
+
end
|
25
28
|
|
26
|
-
|
29
|
+
begin
|
30
|
+
DB = backend_map[conf[:backend].split(':').first].connect uri: conf[:backend]
|
31
|
+
rescue => e
|
32
|
+
STDERR.puts "ERROR starting visor-auth: (#{conf[:backend].split(':').first}) #{e}"
|
33
|
+
exit! 1
|
34
|
+
end
|
27
35
|
|
28
36
|
disable :show_exceptions, :logging #, :protection
|
29
37
|
use Rack::CommonLogger, log
|
data/lib/auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visor-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|