-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use extism_pdk::*; | ||
|
||
#[host_fn] | ||
extern "ExtismHost" { | ||
pub fn redirect(url: &str); | ||
} | ||
|
||
#[host_fn] | ||
extern "ExtismHost" { | ||
pub fn notarize(params: &str) -> String; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::collections::HashMap; | ||
|
||
use extism_pdk::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(FromBytes, Deserialize, PartialEq, Debug, Serialize, ToBytes)] | ||
#[serde(rename_all = "camelCase")] | ||
#[encoding(Json)] | ||
pub struct PluginConfig<'a> { | ||
pub title: &'a str, | ||
pub description: &'a str, | ||
pub icon: String, | ||
pub steps: Vec<StepConfig<'a>>, | ||
pub host_functions: Vec<&'a str>, | ||
pub cookies: Vec<&'a str>, | ||
pub headers: Vec<&'a str>, | ||
pub requests: Vec<RequestObject<'a>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub notary_urls: Option<Vec<&'a str>>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub proxy_urls: Option<Vec<&'a str>>, | ||
} | ||
|
||
#[derive(FromBytes, Deserialize, PartialEq, Debug, Serialize, ToBytes)] | ||
#[serde(rename_all = "camelCase")] | ||
#[encoding(Json)] | ||
pub struct StepConfig<'a> { | ||
pub title: &'a str, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub description: Option<&'a str>, | ||
pub cta: &'a str, | ||
pub action: &'a str, | ||
pub prover: bool, | ||
} | ||
|
||
#[derive(FromBytes, Deserialize, PartialEq, Debug, Serialize, ToBytes)] | ||
#[serde(rename_all = "camelCase")] | ||
#[encoding(Json)] | ||
pub struct RequestObject<'a> { | ||
pub url: &'a str, | ||
pub method: &'a str, | ||
} | ||
|
||
#[derive(FromBytes, Deserialize, PartialEq, Debug, Serialize, ToBytes)] | ||
#[serde(rename_all = "camelCase")] | ||
#[encoding(Json)] | ||
pub struct RequestConfig<'a> { | ||
pub url: &'a str, | ||
pub method: &'a str, | ||
pub headers: HashMap<&'a str, &'a str>, | ||
pub secret_headers: Vec<&'a str>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::collections::HashMap; | ||
|
||
use config::get; | ||
use extism_pdk::*; | ||
|
||
pub fn get_cookies_by_host(hostname: &str) -> Result<HashMap<String, String>, String> { | ||
let cookies_result = get("cookies"); | ||
|
||
// Check if the cookies were retrieved successfully | ||
let cookies_json = match cookies_result { | ||
Ok(Some(json_str)) => json_str, | ||
Ok(None) => return Err("No cookies found in the configuration.".to_string()), | ||
Err(e) => return Err(format!("Error retrieving cookies: {}", e)), | ||
}; | ||
|
||
// Parse the JSON string directly into a HashMap | ||
let cookies: HashMap<String, HashMap<String, String>> = | ||
serde_json::from_str(&cookies_json).map_err(|e| format!("Failed to parse JSON: {}", e))?; | ||
|
||
// Attempt to find the hostname in the map | ||
if let Some(host_cookies) = cookies.get(hostname) { | ||
Ok(host_cookies.clone()) | ||
} else { | ||
Err(format!("Cannot find cookies for {}", hostname)) | ||
} | ||
} |