Add comments
This commit is contained in:
parent
86dead5266
commit
23ba0d2c82
2 changed files with 11 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
use log::info;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app_state::{AppState, database::models::VaultId},
|
app_state::{AppState, database::models::VaultId},
|
||||||
config::user_config::{AllowListedVaults, User, VaultAccess},
|
config::user_config::{AllowListedVaults, User, VaultAccess},
|
||||||
|
|
@ -13,10 +15,16 @@ pub fn auth(app_state: &AppState, token: &str, vault: &VaultId) -> Result<User,
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or_else(|| unauthenticated_error(anyhow::anyhow!("Invalid token")))?;
|
.ok_or_else(|| unauthenticated_error(anyhow::anyhow!("Invalid token")))?;
|
||||||
|
|
||||||
|
info!("User `{}` authenticated", user.name);
|
||||||
|
|
||||||
if match user.vault_access {
|
if match user.vault_access {
|
||||||
VaultAccess::AllowAccessToAll => true,
|
VaultAccess::AllowAccessToAll => true,
|
||||||
VaultAccess::AllowList(AllowListedVaults { ref allowed }) => allowed.contains(vault),
|
VaultAccess::AllowList(AllowListedVaults { ref allowed }) => allowed.contains(vault),
|
||||||
} {
|
} {
|
||||||
|
info!(
|
||||||
|
"User `{}` is authorised to access to vault `{}`",
|
||||||
|
user.name, vault
|
||||||
|
);
|
||||||
Ok(user)
|
Ok(user)
|
||||||
} else {
|
} else {
|
||||||
Err(permission_denied_error(anyhow::anyhow!(
|
Err(permission_denied_error(anyhow::anyhow!(
|
||||||
|
|
|
||||||
|
|
@ -266,6 +266,8 @@ export class Syncer {
|
||||||
wsUri.protocol = wsUri.protocol === "https" ? "wss" : "ws";
|
wsUri.protocol = wsUri.protocol === "https" ? "wss" : "ws";
|
||||||
wsUri.pathname = `/vaults/${settings.vaultName}/ws`;
|
wsUri.pathname = `/vaults/${settings.vaultName}/ws`;
|
||||||
|
|
||||||
|
this.logger.info(`Connecting to WebSocket at ${wsUri.toString()}`);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof globalThis !== "undefined" &&
|
typeof globalThis !== "undefined" &&
|
||||||
typeof globalThis.WebSocket === "undefined"
|
typeof globalThis.WebSocket === "undefined"
|
||||||
|
|
@ -288,6 +290,7 @@ export class Syncer {
|
||||||
|
|
||||||
// The JS WebSocket API doesn't support setting headers, so we have to send the token as a message
|
// The JS WebSocket API doesn't support setting headers, so we have to send the token as a message
|
||||||
this.applyRemoteChangesWebSocket.onopen = (): void => {
|
this.applyRemoteChangesWebSocket.onopen = (): void => {
|
||||||
|
this.logger.info("WebSocket connection opened");
|
||||||
this.applyRemoteChangesWebSocket?.send(settings.token);
|
this.applyRemoteChangesWebSocket?.send(settings.token);
|
||||||
this.webSocketStatusChangeListeners.forEach((listener) => {
|
this.webSocketStatusChangeListeners.forEach((listener) => {
|
||||||
listener();
|
listener();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue