Wipe data from users not recognized by authd.
parent
b2fdc4df5b
commit
c8cd9a1fb2
|
@ -263,22 +263,23 @@ class DNSManager::Storage
|
||||||
def get_orphan_domains(authd : AuthD::Client, user_id : UserDataID) : IPC::JSON
|
def get_orphan_domains(authd : AuthD::Client, user_id : UserDataID) : IPC::JSON
|
||||||
user_must_be_admin! user_id
|
user_must_be_admin! user_id
|
||||||
|
|
||||||
Baguette::Log.warning "list all orphan domains (long computation)"
|
#Baguette::Log.warning "list all orphan domains (long computation)"
|
||||||
# Get all removed users from `authd`.
|
# Get all removed users from `authd`.
|
||||||
orphans = [] of String
|
orphans = [] of String
|
||||||
user_data.each do |user|
|
user_data.each do |user|
|
||||||
begin
|
begin
|
||||||
authd.get_user? user.uid
|
authd.get_user? user.uid
|
||||||
rescue e
|
rescue e
|
||||||
Baguette::Log.warning "cannot get authd info on user #{user.uid}: #{e}"
|
#Baguette::Log.warning "no authd info on user #{user.uid}: #{e}"
|
||||||
Baguette::Log.warning "-> get his domains!"
|
|
||||||
# Verify the user still exists in `authd`.
|
|
||||||
user.domains.each do |domain|
|
user.domains.each do |domain|
|
||||||
orphans << domain
|
orphans << domain
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#Baguette::Log.warning "Removing #{user.uid}!"
|
||||||
|
wipe_user_data user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Baguette::Log.warning "total: #{orphans.size} orphans"
|
#Baguette::Log.warning "total: #{orphans.size} orphans"
|
||||||
|
|
||||||
Response::OrphanDomainList.new orphans
|
Response::OrphanDomainList.new orphans
|
||||||
end
|
end
|
||||||
|
@ -291,6 +292,19 @@ class DNSManager::Storage
|
||||||
Response::Zone.new zone
|
Response::Zone.new zone
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wipe_user_data(user_data : UserData)
|
||||||
|
# Remove the user's domains.
|
||||||
|
user_data.domains.each do |domain|
|
||||||
|
tokens_by_domain.delete domain
|
||||||
|
zones_by_domain.delete domain
|
||||||
|
rescue e
|
||||||
|
Baguette::Log.error "while removing a domain: #{e}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Remove the user.
|
||||||
|
user_data_by_uid.delete user_data.uid.to_s
|
||||||
|
end
|
||||||
|
|
||||||
def delete_user_data(user_id : UserDataID, user_to_delete : UserDataID?) : IPC::JSON
|
def delete_user_data(user_id : UserDataID, user_to_delete : UserDataID?) : IPC::JSON
|
||||||
user_data = user_must_exist! user_id
|
user_data = user_must_exist! user_id
|
||||||
user_data_to_delete = if u = user_to_delete
|
user_data_to_delete = if u = user_to_delete
|
||||||
|
@ -302,15 +316,7 @@ class DNSManager::Storage
|
||||||
user_data
|
user_data
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove the user's domains.
|
wipe_user_data user_data_to_delete
|
||||||
user_data_to_delete.domains.each do |domain|
|
|
||||||
zones_by_domain.delete domain
|
|
||||||
rescue e
|
|
||||||
Baguette::Log.error "while removing a user: #{e}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Remove the user.
|
|
||||||
user_data_by_uid.delete user_data_to_delete.uid.to_s
|
|
||||||
|
|
||||||
Response::Success.new
|
Response::Success.new
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue