NAME
WWW::Suffit::AuthDB::Role::CRUD - Suffit AuthDB methods for CRUD
SYNOPSIS
use WWW::Suffit::AuthDB;
my $authdb = WWW::Suffit::AuthDB->with_roles('+CRUD')->new( ... );
DESCRIPTION
Suffit AuthDB methods for CRUD
METHODS
This class extends WWW::Suffit::AuthDB and implements the following new ones methods
export_data
$authdb->export_data->save; # to `sourcefile`
$authdb->export_data("/tmp/authdb.json");
Export all data to JSON file
group_del
$authdb->group_del( "wheel" ) or die $authdb->error;
Delete group by groupname
group_enroll
$authdb->group_enroll(
groupname => "wheel",
username => "alice",
) or die $authdb->error;
Add user to group members
group_get
my %data = $authdb->group_get( "wheel" );
my @groups = $authdb->group_get;
This method returns group's data or returns all groups as array of hashes
group_members
my @members = $authdb->group_members( "wheel" );
This method returns group's members
group_pset
$authdb->group_pset(
groupname => "wheel",
description => "Admin group",
) or die $authdb->error;
This method adds new group or doing update data of existing group in pure mode
group_pure_set
This method is deprecated! See "group_pset"
group_set
$authdb->group_set(
groupname => "wheel",
description => "Admin group",
) or die $authdb->error;
This method adds new group or doing update data of existing group
import_data
$authdb->load->import_data; # from `sourcefile` preloaded data
$authdb->import_data("/tmp/authdb.json");
Import all data from JSON file
meta
$authdb->meta("my.key", "my value") or die $authdb->error;
Sets meta-value by key
my $val = $authdb->meta("my.key"); # my value
die $authdb->error if $authdb->error;
Gets meta-value by key
$authdb->meta("my.key", undef) or die $authdb->error;
Deletes meta-value by key
realm_del
$authdb->realm_del( "default" ) or die $authdb->error;
Delete realm by realmname
realm_get
my %data = $authdb->realm_get( "default" );
my @realms = $authdb->realm_get;
This method returns realm's data or returns all realms as array of hashes
realm_pset
$authdb->realm_pset(
realmname => "default",
realm => "Strict Zone",
description => "Default realm",
) or die $authdb->error;
This method adds new realm or doing update data of existing realm in pure mode
realm_pure_set
This method is deprecated! See "realm_pset"
realm_requirements
my @requirements = $authdb->realm_requirements( "default" );
This method returns list of realm's requirements
realm_routes
my @routes = $authdb->realm_routes( "default" );
This method returns list of realm's routes
realm_set
$authdb->realm_set(
realmname => "default",
realm => "Strict Zone",
description => "Default realm",
) or die $authdb->error;
This method adds new realm or doing update data of existing realm
route_del
$authdb->route_del( "root" ) or die $authdb->error;
Delete route by routename
route_get
my %data = $authdb->route_get( "root" );
my @routes = $authdb->route_get;
This method returns route's data or returns all routes as array of hashes
route_pset
$authdb->route_pset(
realmname => "default",
routename => "root",
method => "GET",
url => "https://localhost:8695/",
base => "https://localhost:8695/",
path => "/",
) or die $authdb->error;
This method adds new route or doing update data of existing route in pure mode
route_pure_set
This method is deprecated! See "route_pset"
route_search
my @routes = $authdb->route_search( $text );
This method performs search route by name fragment
route_set
$authdb->route_set(
realmname => "default",
routename => "root",
method => "GET",
url => "https://localhost:8695/",
base => "https://localhost:8695/",
path => "/",
) or die $authdb->error;
This method adds new route or doing update data of existing route
token_check
$authdb->token_check($username, $jti)
or die "The token is revoked";
This method checks status of the token in database
token_del
$authdb->token_del($username, $jti)
or die $authdb->error;
This method deletes token from database by username and token ID (jti)
token_get
my @tokens = $authdb->token_get();
my %data = $authdb->token_get( 123 );
my %issued = $authdb->token_get($username, $jti);
Returns the token's metadata by id or pair - username and jti By default (without specified arguments) this method returns list of all tokens
token_set
$authdb->token_set(
type => 'api',
jti => $jti,
username => $username,
clientid => 'qwertyuiqwertyui',
iat => time,
exp => time + 3600,
address => '127.0.0.1',
) or die($authdb->error);
Adds new token to database
$authdb->token_set(
id => 123,
type => 'api',
jti => $jti,
username => $username,
clientid => 'qwertyuiqwertyui',
iat => time,
exp => time + 3600,
address => '127.0.0.1',
) or die($authdb->error);
Updates token's data by id
user_del
$authdb->user_del( "admin" ) or die $authdb->error;
Delete user by username
user_edit
$authdb->user_edit(
username => $username,
comment => $comment,
email => $email,
name => $name,
role => $role,
) or die($authdb->error);
Edit general user data only
user_get
my %data = $authdb->user_get( "admin" );
my @users = $authdb->user_get;
This method returns user's data or returns all users as array of hashes
user_groups
my @groups = $authdb->user_groups( "admin" );
This method returns all groups of the user
user_passwd
$authdb->user_passwd(
username => "admin",
password => "password",
) or die $authdb->error;
This method sets password for user
user_pset
$authdb->user_pset(
username => "foo",
name => "Test User",
email => 'test@localhost',
password => "098f6bcd4621d373cade4e832627b4f6",
algorithm => "MD5",
role => "Test user",
flags => 0,
not_before => time(),
not_after => undef,
public_key => "",
private_key => "",
attributes => qq/{"disabled": 0}/,
comment => "This user added for test",
) or die $authdb->error;
This method adds new user or doing update data of existing user in pure mode
user_pure_set
This method is deprecated! See "user_pset"
user_search
my @users = $authdb->user_search( $text );
This method performs search user by name fragment
user_set
$authdb->user_set(
username => "foo",
name => "Test User",
email => 'test@localhost',
password => "MyPassword", # Unsafe password
algorithm => "SHA256",
role => "Test user",
flags => 0,
not_before => time(),
not_after => undef,
public_key => "",
private_key => "",
attributes => qq/{"disabled": 0}/,
comment => "This user added for test",
) or die $authdb->error;
This method adds new user or doing update data of existing user
user_setkeys
$authdb->user_setkeys(
username => "foo",
public_key => $public_key,
private_key => $private_key,
) or die $authdb->error;
This method sets keys for user
user_tokens
my @tokens = $authdb->user_tokens( $username );
This method returns all tokens of specified user
ERROR CODES
List of error codes describes in WWW::Suffit::AuthDB
HISTORY
See Changes
file
TO DO
See TODO
file
SEE ALSO
WWW::Suffit::AuthDB, Mojolicious, Role::Tiny
AUTHOR
Serż Minus (Sergey Lepenkov) https://www.serzik.com <abalama@cpan.org>
COPYRIGHT
Copyright (C) 1998-2025 D&D Corporation. All Rights Reserved
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See LICENSE
file and https://dev.perl.org/licenses/