vp-login 0.3.0 → 0.4.1
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 +4 -4
- data/README.md +38 -3
- data/lib/vplogin/admin.rb +93 -26
- data/lib/vplogin/configuration.rb +18 -0
- data/lib/vplogin/controller.rb +62 -8
- data/lib/vplogin/devise_token_auth_controller.rb +17 -3
- data/lib/vplogin/devise_token_auth_logout.rb +24 -7
- data/lib/vplogin/devise_user.rb +109 -17
- data/lib/vplogin/discovery.rb +22 -6
- data/lib/vplogin/errors.rb +5 -0
- data/lib/vplogin/http.rb +39 -1
- data/lib/vplogin/log.rb +115 -0
- data/lib/vplogin/oidc.rb +89 -12
- data/lib/vplogin/password_check.rb +23 -6
- data/lib/vplogin/railtie.rb +4 -0
- data/lib/vplogin/state_store.rb +23 -4
- data/lib/vplogin/tasks.rake +63 -0
- data/lib/vplogin/version.rb +1 -1
- data/lib/vplogin.rb +1 -0
- metadata +17 -1
data/lib/vplogin/state_store.rb
CHANGED
|
@@ -25,9 +25,11 @@ module VpLogin
|
|
|
25
25
|
|
|
26
26
|
# Without consuming it, for callers that must refuse before spending the state.
|
|
27
27
|
def read_attempt(state)
|
|
28
|
-
return
|
|
28
|
+
return invalid_id(:attempt, state) unless state.is_a?(String) && state.match?(ID_FORMAT)
|
|
29
29
|
|
|
30
|
-
@config.cache.read(key(:attempt, state))
|
|
30
|
+
@config.cache.read(key(:attempt, state)).tap do |value|
|
|
31
|
+
Log.debug('state.read', config: @config, kind: :attempt, id: Log.fingerprint(state), found: !value.nil?)
|
|
32
|
+
end
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def write_handoff(attempt)
|
|
@@ -43,18 +45,35 @@ module VpLogin
|
|
|
43
45
|
private
|
|
44
46
|
|
|
45
47
|
def write(kind, id, value, ttl)
|
|
46
|
-
@config.cache.write(key(kind, id), value, expires_in: ttl)
|
|
48
|
+
written = @config.cache.write(key(kind, id), value, expires_in: ttl)
|
|
49
|
+
Log.debug('state.write', config: @config, kind:, id: Log.fingerprint(id), ttl:,
|
|
50
|
+
fields: value.respond_to?(:keys) ? value.keys : nil, cache: @config.cache.class.name)
|
|
51
|
+
# Rails cache stores return false when the write failed (e.g. Redis down, value unserializable).
|
|
52
|
+
Log.error('state.write_failed', config: @config, report: true, kind:, id: Log.fingerprint(id), cache: @config.cache.class.name) if written == false
|
|
53
|
+
written
|
|
47
54
|
end
|
|
48
55
|
|
|
56
|
+
# A miss is an expired, already-used or never-issued id - or a cache not shared between the
|
|
57
|
+
# process that wrote it and this one.
|
|
49
58
|
def take(kind, id)
|
|
50
|
-
return
|
|
59
|
+
return invalid_id(kind, id) unless id.is_a?(String) && id.match?(ID_FORMAT)
|
|
51
60
|
|
|
52
61
|
cache_key = key(kind, id)
|
|
53
62
|
value = @config.cache.read(cache_key)
|
|
54
63
|
@config.cache.delete(cache_key) unless value.nil?
|
|
64
|
+
if value.nil?
|
|
65
|
+
Log.warn('state.miss', config: @config, kind:, id: Log.fingerprint(id), cache: @config.cache.class.name)
|
|
66
|
+
else
|
|
67
|
+
Log.debug('state.take', config: @config, kind:, id: Log.fingerprint(id))
|
|
68
|
+
end
|
|
55
69
|
value
|
|
56
70
|
end
|
|
57
71
|
|
|
72
|
+
def invalid_id(kind, id)
|
|
73
|
+
Log.warn('state.invalid_id', config: @config, kind:, type: id.class.name, length: id.to_s.length)
|
|
74
|
+
nil
|
|
75
|
+
end
|
|
76
|
+
|
|
58
77
|
def key(kind, id)
|
|
59
78
|
"#{@config.cache_namespace}:#{kind}:#{id}"
|
|
60
79
|
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Bulk migration of an app's existing users into vpLogin, for models that include
|
|
4
|
+
# VpLogin::DeviseUser. One VpLogin::ProvisionJob per user; every step is a no-op when already done,
|
|
5
|
+
# so re-running after a partial run only finishes what's left.
|
|
6
|
+
namespace :vplogin do
|
|
7
|
+
vplogin_scope = lambda do
|
|
8
|
+
model = VpLogin.configuration.user_model
|
|
9
|
+
model = model.constantize if model.is_a?(String)
|
|
10
|
+
scope = model.vplogin_migration_scope
|
|
11
|
+
ids = ENV['IDS'].to_s.split(',').map(&:strip).reject(&:empty?)
|
|
12
|
+
ids.empty? ? scope : scope.where(id: ids)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc 'Create vpLogin identities for existing users (DRY_RUN=true to only count; IDS=1,2 to limit)'
|
|
16
|
+
task migrate_users: :environment do
|
|
17
|
+
abort 'vpLogin admin API is not configured (VPLOGIN_ADMIN_API_URL / VPLOGIN_API_TOKEN)' unless VpLogin.configuration.admin_api?
|
|
18
|
+
|
|
19
|
+
scope = vplogin_scope.call
|
|
20
|
+
if ENV['DRY_RUN'] == 'true'
|
|
21
|
+
puts "DRY_RUN: would enqueue #{scope.count} #{scope.model.name} users for vpLogin migration"
|
|
22
|
+
next
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
count = 0
|
|
26
|
+
scope.find_each do |user|
|
|
27
|
+
VpLogin::ProvisionJob.perform_later(user.class.name, user.id)
|
|
28
|
+
count += 1
|
|
29
|
+
end
|
|
30
|
+
VpLogin::Log.info('task.migrate_users.enqueued', count:, queue: VpLogin.configuration.job_queue)
|
|
31
|
+
puts "Enqueued #{count} VpLogin::ProvisionJob jobs on #{VpLogin.configuration.job_queue}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
desc 'Report which users have a vpLogin identity and password (one admin API call per user; IDS=1,2 to limit)'
|
|
35
|
+
task migration_status: :environment do
|
|
36
|
+
abort 'vpLogin admin API is not configured (VPLOGIN_ADMIN_API_URL / VPLOGIN_API_TOKEN)' unless VpLogin.configuration.admin_api?
|
|
37
|
+
|
|
38
|
+
admin = VpLogin::Admin.new
|
|
39
|
+
counts = Hash.new(0)
|
|
40
|
+
missing = []
|
|
41
|
+
vplogin_scope.call.find_each do |user|
|
|
42
|
+
identity = admin.find_user(email: user.email)
|
|
43
|
+
if identity.nil?
|
|
44
|
+
counts[:missing] += 1
|
|
45
|
+
missing << user.email
|
|
46
|
+
elsif identity['has_usable_password'] == false
|
|
47
|
+
counts[:no_password] += 1
|
|
48
|
+
else
|
|
49
|
+
counts[:migrated] += 1
|
|
50
|
+
end
|
|
51
|
+
rescue VpLogin::Error => e
|
|
52
|
+
counts[:errors] += 1
|
|
53
|
+
VpLogin::Log.error('task.migration_status.failed', exception: e, user_id: user.id)
|
|
54
|
+
warn "#{user.email}: #{e.class}: #{e.message}"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
puts "migrated (identity + password): #{counts[:migrated]}"
|
|
58
|
+
puts "identity without a password: #{counts[:no_password]}"
|
|
59
|
+
puts "no vpLogin identity: #{counts[:missing]}"
|
|
60
|
+
puts "errors: #{counts[:errors]}"
|
|
61
|
+
puts "missing: #{missing.first(20).join(', ')}#{' ...' if missing.size > 20}" if missing.any?
|
|
62
|
+
end
|
|
63
|
+
end
|
data/lib/vplogin/version.rb
CHANGED
data/lib/vplogin.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vp-login
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Volopay
|
|
@@ -58,6 +58,20 @@ dependencies:
|
|
|
58
58
|
- - ">="
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
60
|
version: '7.0'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: rake
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '13'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '13'
|
|
61
75
|
- !ruby/object:Gem::Dependency
|
|
62
76
|
name: rspec
|
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -105,6 +119,7 @@ files:
|
|
|
105
119
|
- lib/vplogin/discovery.rb
|
|
106
120
|
- lib/vplogin/errors.rb
|
|
107
121
|
- lib/vplogin/http.rb
|
|
122
|
+
- lib/vplogin/log.rb
|
|
108
123
|
- lib/vplogin/memory_cache.rb
|
|
109
124
|
- lib/vplogin/oidc.rb
|
|
110
125
|
- lib/vplogin/password_check.rb
|
|
@@ -112,6 +127,7 @@ files:
|
|
|
112
127
|
- lib/vplogin/railtie.rb
|
|
113
128
|
- lib/vplogin/routes.rb
|
|
114
129
|
- lib/vplogin/state_store.rb
|
|
130
|
+
- lib/vplogin/tasks.rake
|
|
115
131
|
- lib/vplogin/version.rb
|
|
116
132
|
homepage:
|
|
117
133
|
licenses:
|