mirror of
https://github.com/haexhub/haex-hub.git
synced 2025-12-16 22:20:51 +01:00
extend extensions implementation
This commit is contained in:
@ -28,6 +28,72 @@ pub struct ExtensionManifest {
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ExtensionInfoResponse {
|
||||
pub key_hash: String,
|
||||
pub name: String,
|
||||
pub full_id: String,
|
||||
pub version: String,
|
||||
pub display_name: Option<String>,
|
||||
pub namespace: Option<String>,
|
||||
pub allowed_origin: String,
|
||||
}
|
||||
|
||||
impl ExtensionInfoResponse {
|
||||
pub fn from_extension(extension: &Extension) -> Self {
|
||||
// Bestimme die allowed_origin basierend auf Tauri-Konfiguration
|
||||
let allowed_origin = get_tauri_origin();
|
||||
|
||||
Self {
|
||||
key_hash: calculate_key_hash(&extension.manifest.id),
|
||||
name: extension.manifest.name.clone(),
|
||||
full_id: format!(
|
||||
"{}/{}@{}",
|
||||
calculate_key_hash(&extension.manifest.id),
|
||||
extension.manifest.name,
|
||||
extension.manifest.version
|
||||
),
|
||||
version: extension.manifest.version.clone(),
|
||||
display_name: Some(extension.manifest.name.clone()),
|
||||
namespace: extension.manifest.author.clone(),
|
||||
allowed_origin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_tauri_origin() -> String {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
"https://tauri.localhost".to_string()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
"tauri://localhost".to_string()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
"tauri://localhost".to_string()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
"tauri://localhost".to_string()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "ios")]
|
||||
{
|
||||
"tauri://localhost".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
// Dummy-Funktion für Key Hash (du implementierst das richtig mit SHA-256)
|
||||
fn calculate_key_hash(id: &str) -> String {
|
||||
// TODO: Implementiere SHA-256 Hash vom Public Key
|
||||
// Für jetzt nur Placeholder
|
||||
format!("{:0<20}", id.chars().take(20).collect::<String>())
|
||||
}
|
||||
/// Extension source type (production vs development)
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ExtensionSource {
|
||||
|
||||
@ -16,7 +16,6 @@ pub struct DbExtensionPermission {
|
||||
pub extension_id: String,
|
||||
pub resource: String,
|
||||
pub operation: String,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
/// Prüft Leseberechtigungen für eine Extension
|
||||
@ -168,7 +167,7 @@ async fn check_table_permissions(
|
||||
for table_name in table_names {
|
||||
let has_permission = permissions
|
||||
.iter()
|
||||
.any(|perm| perm.path.contains(table_name));
|
||||
.any(|perm| perm.resource.contains(table_name));
|
||||
|
||||
if !has_permission {
|
||||
return Err(ExtensionError::permission_denied(
|
||||
@ -207,7 +206,6 @@ pub async fn get_extension_permissions(
|
||||
extension_id: row.get(1)?,
|
||||
resource: row.get(2)?,
|
||||
operation: row.get(3)?,
|
||||
path: row.get(4)?,
|
||||
})
|
||||
})
|
||||
.map_err(|e| DatabaseError::QueryError {
|
||||
|
||||
@ -1,5 +1,19 @@
|
||||
use crate::extension::core::{ExtensionInfoResponse, ExtensionManager};
|
||||
use tauri::State;
|
||||
pub mod core;
|
||||
pub mod database;
|
||||
pub mod error;
|
||||
pub mod filesystem;
|
||||
pub mod permission_manager;
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_extension_info(
|
||||
extension_id: String,
|
||||
extension_manager: State<ExtensionManager>,
|
||||
) -> Result<ExtensionInfoResponse, String> {
|
||||
let extension = extension_manager
|
||||
.get_extension(&extension_id)
|
||||
.ok_or_else(|| format!("Extension nicht gefunden: {}", extension_id))?;
|
||||
|
||||
Ok(ExtensionInfoResponse::from_extension(&extension))
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ impl PermissionManager {
|
||||
|
||||
let has_permission = permissions
|
||||
.iter()
|
||||
.any(|perm| perm.path.contains(table_name));
|
||||
.any(|perm| perm.resource.contains(table_name));
|
||||
|
||||
if !has_permission {
|
||||
return Err(ExtensionError::permission_denied(
|
||||
|
||||
Reference in New Issue
Block a user