update backend interfaces
This commit is contained in:
parent
6c984a7886
commit
69318a2dad
@ -31,7 +31,7 @@ export default async () => {
|
|||||||
* Interface for all backend types. Contains only two methods for opening and closing a session with the backend.
|
* Interface for all backend types. Contains only two methods for opening and closing a session with the backend.
|
||||||
* Users will recieve tokens from all backends when first authenticating and will delete tokens when logging out.
|
* Users will recieve tokens from all backends when first authenticating and will delete tokens when logging out.
|
||||||
*/
|
*/
|
||||||
export class BACKEND {
|
class BACKEND {
|
||||||
/**
|
/**
|
||||||
* Opens a session with the backend and creates session tokens if needed
|
* Opens a session with the backend and creates session tokens if needed
|
||||||
* @param {Object} credentials object containing username and password fields
|
* @param {Object} credentials object containing username and password fields
|
||||||
@ -59,24 +59,10 @@ export class BACKEND {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for proxmox api backends.
|
* Interface for backend types that store/interact with user & group data.
|
||||||
|
* Not all backends need to implement all interface methods.
|
||||||
*/
|
*/
|
||||||
export class PVE_BACKEND extends BACKEND {}
|
class USER_BACKEND extends BACKEND {
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for user database backends.
|
|
||||||
*/
|
|
||||||
export class DB_BACKEND extends BACKEND {
|
|
||||||
addUser (username, config = null) {}
|
|
||||||
getUser (username) {}
|
|
||||||
setUser (username, config) {}
|
|
||||||
deluser (username) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for user auth backends.
|
|
||||||
*/
|
|
||||||
export class AUTH_BACKEND extends BACKEND {
|
|
||||||
addUser (username, attributes, params = null) {}
|
addUser (username, attributes, params = null) {}
|
||||||
getUser (username, params = null) {}
|
getUser (username, params = null) {}
|
||||||
setUser (username, attributes, params = null) {}
|
setUser (username, attributes, params = null) {}
|
||||||
@ -90,3 +76,18 @@ export class AUTH_BACKEND extends BACKEND {
|
|||||||
addUserToGroup (username, groupname, params = null) {}
|
addUserToGroup (username, groupname, params = null) {}
|
||||||
delUserFromGroup (username, groupname, params = null) {}
|
delUserFromGroup (username, groupname, params = null) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for proxmox api backends.
|
||||||
|
*/
|
||||||
|
export class PVE_BACKEND extends BACKEND {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for user database backends.
|
||||||
|
*/
|
||||||
|
export class DB_BACKEND extends USER_BACKEND {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for user auth backends.
|
||||||
|
*/
|
||||||
|
export class AUTH_BACKEND extends USER_BACKEND {}
|
||||||
|
@ -35,13 +35,13 @@ export default class LocalDB extends DB_BACKEND {
|
|||||||
writeFileSync(this.#path, JSON.stringify(this.#data));
|
writeFileSync(this.#path, JSON.stringify(this.#data));
|
||||||
}
|
}
|
||||||
|
|
||||||
addUser (username, config = null) {
|
addUser (username, attributes, params = null) {
|
||||||
config = config || this.#defaultuser;
|
attributes = attributes || this.#defaultuser;
|
||||||
this.#data.users[username] = config;
|
this.#data.users[username] = attributes;
|
||||||
this.#save();
|
this.#save();
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser (username) {
|
getUser (username, params = null) {
|
||||||
if (this.#data.users[username]) {
|
if (this.#data.users[username]) {
|
||||||
return this.#data.users[username];
|
return this.#data.users[username];
|
||||||
}
|
}
|
||||||
@ -50,9 +50,9 @@ export default class LocalDB extends DB_BACKEND {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setUser (username, config) {
|
setUser (username, attributes, params = null) {
|
||||||
if (this.#data.users[username]) {
|
if (this.#data.users[username]) {
|
||||||
this.#data.users[username] = config;
|
this.#data.users[username] = attributes;
|
||||||
this.#save();
|
this.#save();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ export default class LocalDB extends DB_BACKEND {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delUser (username) {
|
delUser (username, params = null) {
|
||||||
if (this.#data.users[username]) {
|
if (this.#data.users[username]) {
|
||||||
delete this.#data.users[username];
|
delete this.#data.users[username];
|
||||||
this.#save();
|
this.#save();
|
||||||
|
Loading…
Reference in New Issue
Block a user