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
|
||||
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`.
|
||||
orphans = [] of String
|
||||
user_data.each do |user|
|
||||
begin
|
||||
authd.get_user? user.uid
|
||||
rescue e
|
||||
Baguette::Log.warning "cannot get authd info on user #{user.uid}: #{e}"
|
||||
Baguette::Log.warning "-> get his domains!"
|
||||
# Verify the user still exists in `authd`.
|
||||
#Baguette::Log.warning "no authd info on user #{user.uid}: #{e}"
|
||||
user.domains.each do |domain|
|
||||
orphans << domain
|
||||
end
|
||||
|
||||
#Baguette::Log.warning "Removing #{user.uid}!"
|
||||
wipe_user_data user
|
||||
end
|
||||
end
|
||||
Baguette::Log.warning "total: #{orphans.size} orphans"
|
||||
#Baguette::Log.warning "total: #{orphans.size} orphans"
|
||||
|
||||
Response::OrphanDomainList.new orphans
|
||||
end
|
||||
|
@ -291,6 +292,19 @@ class DNSManager::Storage
|
|||
Response::Zone.new zone
|
||||
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
|
||||
user_data = user_must_exist! user_id
|
||||
user_data_to_delete = if u = user_to_delete
|
||||
|
@ -302,15 +316,7 @@ class DNSManager::Storage
|
|||
user_data
|
||||
end
|
||||
|
||||
# Remove the user's domains.
|
||||
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
|
||||
wipe_user_data user_data_to_delete
|
||||
|
||||
Response::Success.new
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue