harperdb
Version:
HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.
82 lines (81 loc) • 3.61 kB
TypeScript
declare const USERNAME_REQUIRED = "username is required";
declare const ALTERUSER_NOTHING_TO_UPDATE = "nothing to update, must supply active, role or password to update";
declare const EMPTY_PASSWORD = "password cannot be an empty string";
declare const EMPTY_ROLE = "If role is specified, it cannot be empty.";
declare const ACTIVE_BOOLEAN = "active must be true or false";
export { addUser, alterUser, dropUser, getSuperUser, userInfo, listUsers, listUsersExternal, setUsersWithRolesCache, findAndValidateUser, getClusterUser, getUsersWithRolesCache, USERNAME_REQUIRED, ALTERUSER_NOTHING_TO_UPDATE, EMPTY_PASSWORD, EMPTY_ROLE, ACTIVE_BOOLEAN, };
export interface User {
active?: boolean;
username: string;
role?: UserRole;
__updatedtime__?: number;
__createdtime__?: number;
[other: string]: unknown;
}
export interface UserRole {
permission: UserRoleNamedPermissions & UserRoleDatabasePermissions;
role: string;
id: string;
__updatedtime__: number;
__createdtime__: number;
}
export interface UserRoleNamedPermissions extends Partial<CRUDPermissions> {
super_user?: boolean;
cluster_user?: boolean;
structure_user?: boolean;
}
export interface UserRoleDatabasePermissions {
[databaseName: string]: UserRoleSchemaRecord;
}
export interface UserRoleSchemaRecord extends Partial<CRUDPermissions> {
tables: Record<string, UserRolePermissionTable | UserLegacyRolePermissionTable>;
}
export interface UserRolePermissionTable extends CRUDPermissions {
attribute_permissions: UserRoleAttributePermissionTable[];
}
export interface UserRoleAttributePermissionTable extends Omit<CRUDPermissions, 'delete'> {
attribute_name: string;
}
export interface UserLegacyRolePermissionTable extends CRUDPermissions {
attribute_restrictions: UserLegacyRoleAttributePermissionTable[];
}
export interface UserLegacyRoleAttributePermissionTable extends CRUDPermissions {
attribute_name: string;
}
export interface CRUDPermissions {
read: boolean;
insert: boolean;
update: boolean;
delete: boolean;
}
declare function addUser(user: User | any): Promise<string>;
declare function alterUser(jsonMessage: any): Promise<any>;
declare function dropUser(user: User | any): Promise<string>;
declare function userInfo(body: any): Promise<string | User>;
/**
* This function should be called by chooseOperation as it scrubs sensitive information before returning
* the results of list users.
*/
declare function listUsersExternal(): Promise<User[]>;
/**
* Queries system table for user records, adds role-based perms, scrubs list based on licensed role allowance and returns
* data in a Map with the username as the key for the entry
*/
declare function listUsers(): Promise<Map<string, User>>;
declare function setUsersWithRolesCache(cache?: any): Promise<void>;
declare function getUsersWithRolesCache(): Promise<any>;
/**
* iterates global.hdb_users to find and validate the username & optionally the password as well as if they are active.
* @param {string} username
* @param {string} pw
* @param {boolean} validatePassword
*/
declare function findAndValidateUser(username: string, pw?: string | null, validatePassword?: boolean): Promise<User>;
declare function getSuperUser(): Promise<User | undefined>;
/**
* Gets the cluster user provided in harperdb-config.yaml from the map of all user.
* Nats requires plain test passwords, this is why we pass decrypt_hash.
* The Nats routes require the decrypt_hash to be uri encoded.
* @returns {Promise<Object>}
*/
declare function getClusterUser(): Promise<User | undefined>;