UserID: from Int32 to UInt32.

This commit is contained in:
Philippe Pittoli 2024-03-16 05:45:15 +01:00
parent c462bbafa1
commit 5ac733cbc3
10 changed files with 25 additions and 26 deletions

View File

@ -10,8 +10,8 @@ require "ipc"
require "baguette-crystal-base" require "baguette-crystal-base"
# In any message, a user can be referred by its Int32 uid or its login. # In any message, a user can be referred by its UInt32 uid or its login.
alias UserID = Int32 | String alias UserID = UInt32 | String
# Allows get configuration from a provided file. # Allows get configuration from a provided file.
# See Baguette::Configuration::Base.get # See Baguette::Configuration::Base.get

View File

@ -40,7 +40,7 @@ module AuthD
parse_message [Response::User], read parse_message [Response::User], read
end end
def get_user?(uid_or_login : Int32 | String) def get_user?(uid_or_login : UserID)
send_now Request::GetUser.new uid_or_login send_now Request::GetUser.new uid_or_login
parse_message [Response::User], read parse_message [Response::User], read
end end
@ -84,12 +84,12 @@ module AuthD
parse_message [Response::UserValidated], read parse_message [Response::UserValidated], read
end end
def ask_password_recovery(uid_or_login : String | Int32) def ask_password_recovery(uid_or_login : UserID)
send_now Request::AskPasswordRecovery.new uid_or_login send_now Request::AskPasswordRecovery.new uid_or_login
parse_message [Response::PasswordRecoverySent], read parse_message [Response::PasswordRecoverySent], read
end end
def change_password(uid_or_login : String | Int32, new_pass : String, renew_key : String) def change_password(uid_or_login : UserID, new_pass : String, renew_key : String)
send_now Request::PasswordRecovery.new uid_or_login, renew_key, new_pass send_now Request::PasswordRecovery.new uid_or_login, renew_key, new_pass
parse_message [Response::PasswordRecovered], read parse_message [Response::PasswordRecovered], read
end end
@ -137,12 +137,12 @@ module AuthD
parse_message [Response::MatchingUsers], read parse_message [Response::MatchingUsers], read
end end
def edit_profile_content(user : Int32 | String, new_values) def edit_profile_content(user : UserID, new_values)
send_now Request::EditProfileEntries.new user, new_values send_now Request::EditProfileEntries.new user, new_values
parse_message [Response::User], read parse_message [Response::User], read
end end
def delete(user : Int32 | String) def delete(user : UserID)
send_now Request::Delete.new user send_now Request::Delete.new user
parse_message [Response::UserDeleted], read parse_message [Response::UserDeleted], read
end end

View File

@ -4,7 +4,7 @@ class AuthD::Token
include JSON::Serializable include JSON::Serializable
property login : String property login : String
property uid : Int32 property uid : UInt32
def initialize(@login, @uid) def initialize(@login, @uid)
end end
@ -23,7 +23,7 @@ class AuthD::Token
def self.from_s(key, str) def self.from_s(key, str)
payload, meta = JWT.decode str, key, JWT::Algorithm::HS256 payload, meta = JWT.decode str, key, JWT::Algorithm::HS256
self.new payload["login"].as_s, payload["uid"].as_i self.new payload["login"].as_s, payload["uid"].as_i64.to_u32
end end
end end

View File

@ -32,7 +32,7 @@ class AuthD::User
# Public. # Public.
property login : String property login : String
property uid : Int32 property uid : UInt32
property admin : Bool = false property admin : Bool = false
property profile : Hash(String, JSON::Any)? property profile : Hash(String, JSON::Any)?
@ -60,7 +60,7 @@ class AuthD::User
include JSON::Serializable include JSON::Serializable
property login : String property login : String
property uid : Int32 property uid : UInt32
property admin : Bool = false property admin : Bool = false
property profile : Hash(String, JSON::Any)? property profile : Hash(String, JSON::Any)?

View File

@ -172,7 +172,7 @@ class Actions
def user_deletion def user_deletion
args = Context.args.not_nil! args = Context.args.not_nil!
userid = args[0].to_i userid = args[0].to_u32
res = authd.delete userid res = authd.delete userid
@ -203,7 +203,7 @@ class Actions
def permission_check def permission_check
args = Context.args.not_nil! args = Context.args.not_nil!
user, application, resource = args[0..2] user, application, resource = args[0..2]
res = @authd.check_permission user.to_i, application, resource res = @authd.check_permission user.to_u32, application, resource
case res case res
when Response::PermissionCheck when Response::PermissionCheck
s = res.service s = res.service
@ -218,7 +218,7 @@ class Actions
args = Context.args.not_nil! args = Context.args.not_nil!
user, application, resource, permission = args[0..3] user, application, resource, permission = args[0..3]
perm = AuthD::User::PermissionLevel.parse(permission) perm = AuthD::User::PermissionLevel.parse(permission)
res = @authd.set_permission user.to_i, application, resource, perm res = @authd.set_permission user.to_u32, application, resource, perm
case res case res
when Response::PermissionSet when Response::PermissionSet
s = res.service s = res.service

View File

@ -1,6 +1,6 @@
class AuthD::Response class AuthD::Response
IPC::JSON.message Contacts, 12 do IPC::JSON.message Contacts, 12 do
property user : Int32 property user : UInt32
property email : String? = nil property email : String? = nil
def initialize(@user, @email) def initialize(@user, @email)
end end

View File

@ -1,6 +1,6 @@
class AuthD::Response class AuthD::Response
IPC::JSON.message Login, 1 do IPC::JSON.message Login, 1 do
property uid : Int32 property uid : UInt32
property token : String property token : String
def initialize(@token, @uid) def initialize(@token, @uid)
end end

View File

@ -1,6 +1,6 @@
class AuthD::Response class AuthD::Response
IPC::JSON.message PermissionCheck, 7 do IPC::JSON.message PermissionCheck, 7 do
property user : Int32 property user : UInt32
property service : String property service : String
property resource : String property resource : String
property permission : ::AuthD::User::PermissionLevel property permission : ::AuthD::User::PermissionLevel
@ -10,7 +10,7 @@ class AuthD::Response
AuthD.responses << PermissionCheck AuthD.responses << PermissionCheck
IPC::JSON.message PermissionSet, 8 do IPC::JSON.message PermissionSet, 8 do
property user : Int32 property user : UInt32
property service : String property service : String
property resource : String property resource : String
property permission : ::AuthD::User::PermissionLevel property permission : ::AuthD::User::PermissionLevel

View File

@ -14,7 +14,7 @@ class AuthD::Response
AuthD.responses << UserAdded AuthD.responses << UserAdded
IPC::JSON.message UserEdited, 4 do IPC::JSON.message UserEdited, 4 do
property uid : Int32 property uid : UInt32
def initialize(@uid) def initialize(@uid)
end end
end end
@ -42,7 +42,7 @@ class AuthD::Response
AuthD.responses << MatchingUsers AuthD.responses << MatchingUsers
IPC::JSON.message UserDeleted, 12 do IPC::JSON.message UserDeleted, 12 do
property uid : Int32 property uid : UInt32
def initialize(@uid) def initialize(@uid)
end end
end end

View File

@ -63,13 +63,12 @@ class AuthD::Service < IPC
# #
# WARNING: to record this new UID, new_uid_commit must be called. # WARNING: to record this new UID, new_uid_commit must be called.
# WARNING: new_uid isn't thread safe. # WARNING: new_uid isn't thread safe.
def new_uid def new_uid : UInt32
begin uid : UInt32 = begin
uid = File.read(@last_uid_file).to_i File.read(@last_uid_file).to_u32
rescue rescue
uid = 999 999.to_u32
end end
uid += 1 uid += 1
end end
@ -92,7 +91,7 @@ class AuthD::Service < IPC
end end
def user?(uid_or_login : UserID) def user?(uid_or_login : UserID)
if uid_or_login.is_a? Int32 if uid_or_login.is_a? UInt32
@users_per_uid.get? uid_or_login.to_s @users_per_uid.get? uid_or_login.to_s
else else
@users_per_login.get? uid_or_login @users_per_login.get? uid_or_login