87 lines
2.4 KiB
Rust
87 lines
2.4 KiB
Rust
|
|
// Code generated by ndpgen. DO NOT EDIT.
|
||
|
|
//
|
||
|
|
// This file contains client wrappers for the Users host service.
|
||
|
|
// It is intended for use in Navidrome plugins built with extism-pdk.
|
||
|
|
|
||
|
|
use extism_pdk::*;
|
||
|
|
use serde::{Deserialize, Serialize};
|
||
|
|
|
||
|
|
/// User represents a Navidrome user with minimal information exposed to plugins.
|
||
|
|
/// Sensitive fields like password, email, and internal IDs are intentionally excluded.
|
||
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
|
|
#[serde(rename_all = "camelCase")]
|
||
|
|
pub struct User {
|
||
|
|
pub user_name: String,
|
||
|
|
pub name: String,
|
||
|
|
pub is_admin: bool,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, Deserialize)]
|
||
|
|
#[serde(rename_all = "camelCase")]
|
||
|
|
struct UsersGetUsersResponse {
|
||
|
|
#[serde(default)]
|
||
|
|
result: Vec<User>,
|
||
|
|
#[serde(default)]
|
||
|
|
error: Option<String>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, Deserialize)]
|
||
|
|
#[serde(rename_all = "camelCase")]
|
||
|
|
struct UsersGetAdminsResponse {
|
||
|
|
#[serde(default)]
|
||
|
|
result: Vec<User>,
|
||
|
|
#[serde(default)]
|
||
|
|
error: Option<String>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[host_fn]
|
||
|
|
extern "ExtismHost" {
|
||
|
|
fn users_getusers(input: Json<serde_json::Value>) -> Json<UsersGetUsersResponse>;
|
||
|
|
fn users_getadmins(input: Json<serde_json::Value>) -> Json<UsersGetAdminsResponse>;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// GetUsers returns all users the plugin has been granted access to.
|
||
|
|
/// Only minimal user information (userName, name, isAdmin) is returned.
|
||
|
|
/// Sensitive fields like password and email are never exposed.
|
||
|
|
///
|
||
|
|
/// Returns a slice of users the plugin can access, or an empty slice if none configured.
|
||
|
|
///
|
||
|
|
/// # Returns
|
||
|
|
/// The result value.
|
||
|
|
///
|
||
|
|
/// # Errors
|
||
|
|
/// Returns an error if the host function call fails.
|
||
|
|
pub fn get_users() -> Result<Vec<User>, Error> {
|
||
|
|
let response = unsafe {
|
||
|
|
users_getusers(Json(serde_json::json!({})))?
|
||
|
|
};
|
||
|
|
|
||
|
|
if let Some(err) = response.0.error {
|
||
|
|
return Err(Error::msg(err));
|
||
|
|
}
|
||
|
|
|
||
|
|
Ok(response.0.result)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// GetAdmins returns only admin users the plugin has been granted access to.
|
||
|
|
/// This is a convenience method that filters GetUsers results to include only admins.
|
||
|
|
///
|
||
|
|
/// Returns a slice of admin users the plugin can access, or an empty slice if none.
|
||
|
|
///
|
||
|
|
/// # Returns
|
||
|
|
/// The result value.
|
||
|
|
///
|
||
|
|
/// # Errors
|
||
|
|
/// Returns an error if the host function call fails.
|
||
|
|
pub fn get_admins() -> Result<Vec<User>, Error> {
|
||
|
|
let response = unsafe {
|
||
|
|
users_getadmins(Json(serde_json::json!({})))?
|
||
|
|
};
|
||
|
|
|
||
|
|
if let Some(err) = response.0.error {
|
||
|
|
return Err(Error::msg(err));
|
||
|
|
}
|
||
|
|
|
||
|
|
Ok(response.0.result)
|
||
|
|
}
|