deno/cli/ops/deploy.rs
Leo Kettmeir b59576cc0f
feat(unstable): tunnelling (#30022)
Co-authored-by: snek <snek@deno.com>
2025-07-08 02:44:50 +02:00

46 lines
1.1 KiB
Rust

// Copyright 2018-2025 the Deno authors. MIT license.
use deno_core::op2;
use deno_error::JsErrorBox;
use crate::tools::deploy::get_token_entry;
deno_core::extension!(
deno_deploy,
ops = [
op_deploy_token_get,
op_deploy_token_set,
op_deploy_token_delete,
],
);
#[op2]
#[string]
pub fn op_deploy_token_get() -> Result<Option<String>, JsErrorBox> {
match get_token_entry()
.map_err(|e| JsErrorBox::type_error(e.to_string()))?
.get_password()
{
Ok(password) => Ok(Some(password)),
Err(keyring::Error::NoEntry) => Ok(None),
Err(e) => Err(JsErrorBox::type_error(e.to_string())),
}
}
#[op2(fast)]
#[string]
pub fn op_deploy_token_set(#[string] s: &str) -> Result<(), JsErrorBox> {
get_token_entry()
.map_err(|e| JsErrorBox::type_error(e.to_string()))?
.set_password(s)
.map_err(|e| JsErrorBox::type_error(e.to_string()))
}
#[op2(fast)]
#[string]
pub fn op_deploy_token_delete() -> Result<(), JsErrorBox> {
get_token_entry()
.map_err(|e| JsErrorBox::type_error(e.to_string()))?
.delete_credential()
.map_err(|e| JsErrorBox::type_error(e.to_string()))
}