-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 150-feature-imix-platform-information
- Loading branch information
Showing
20 changed files
with
272 additions
and
54 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 |
---|---|---|
|
@@ -36,3 +36,5 @@ build/** | |
# Credentials | ||
.creds/** | ||
implants/imix/imix-test-config.json | ||
|
||
implants/golem/embed_files_golem_prod/* |
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 |
---|---|---|
|
@@ -16,7 +16,7 @@ You can leverage the power of Eldritch with minimal exposure in the system proce | |
```bash | ||
git clone [email protected]:KCarretto/realm.git | ||
cd realm/implants/golem | ||
cargo run | ||
cargo run -- -i | ||
# - or - | ||
../target/debug/golem working_dir/tomes/hello_world.tome | ||
../target/debug/golem ../../tests/golem_cli_test/tomes/hello_world.tome | ||
``` |
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,70 @@ | ||
mod copy_impl; | ||
mod list_impl; | ||
|
||
use derive_more::Display; | ||
|
||
use starlark::environment::{Methods, MethodsBuilder, MethodsStatic}; | ||
use starlark::values::none::NoneType; | ||
use starlark::values::{StarlarkValue, Value, UnpackValue, ValueLike, ProvidesStaticType}; | ||
use starlark::{starlark_type, starlark_simple_value, starlark_module}; | ||
|
||
use serde::{Serialize,Serializer}; | ||
use rust_embed::RustEmbed; | ||
|
||
#[cfg(debug_assertions)] | ||
#[derive(RustEmbed)] | ||
#[folder = "../../tests/embedded_files_test"] | ||
pub struct Asset; | ||
|
||
#[cfg(not(debug_assertions))] | ||
#[derive(RustEmbed)] | ||
#[folder = "../../implants/golem/embed_files_golem_prod"] | ||
pub struct Asset; | ||
|
||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Display, ProvidesStaticType)] | ||
#[display(fmt = "AssetsLibrary")] | ||
pub struct AssetsLibrary(); | ||
starlark_simple_value!(AssetsLibrary); | ||
|
||
impl<'v> StarlarkValue<'v> for AssetsLibrary { | ||
starlark_type!("assets_library"); | ||
|
||
fn get_methods() -> Option<&'static Methods> { | ||
static RES: MethodsStatic = MethodsStatic::new(); | ||
RES.methods(methods) | ||
} | ||
} | ||
|
||
impl Serialize for AssetsLibrary { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
serializer.serialize_none() | ||
} | ||
} | ||
|
||
impl<'v> UnpackValue<'v> for AssetsLibrary { | ||
fn expected() -> String { | ||
AssetsLibrary::get_type_value_static().as_str().to_owned() | ||
} | ||
|
||
fn unpack_value(value: Value<'v>) -> Option<Self> { | ||
Some(*value.downcast_ref::<AssetsLibrary>().unwrap()) | ||
} | ||
} | ||
|
||
// This is where all of the "assets.X" impl methods are bound | ||
#[starlark_module] | ||
fn methods(builder: &mut MethodsBuilder) { | ||
fn copy(this: AssetsLibrary, src: String, dest: String) -> anyhow::Result<NoneType> { | ||
if false { println!("Ignore unused this var. _this isn't allowed by starlark. {:?}", this); } | ||
copy_impl::copy(src, dest)?; | ||
Ok(NoneType{}) | ||
} | ||
fn list(this: AssetsLibrary) -> anyhow::Result<Vec<String>> { | ||
if false { println!("Ignore unused this var. _this isn't allowed by starlark. {:?}", this); } | ||
list_impl::list() | ||
} | ||
} |
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,41 @@ | ||
use std::fs; | ||
use anyhow::Result; | ||
|
||
pub fn copy(src: String, dst: String) -> Result<()> { | ||
let src_file = match super::Asset::get(src.as_str()) { | ||
Some(local_src_file) => local_src_file.data, | ||
None => return Err(anyhow::anyhow!("Embedded file {src} not found.")), | ||
}; | ||
|
||
match fs::write(dst, src_file) { | ||
Ok(_) => Ok(()), | ||
Err(local_err) => Err(local_err.into()), | ||
} | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use std::io::prelude::*; | ||
use tempfile::NamedTempFile; | ||
|
||
#[test] | ||
fn test_embedded_copy() -> anyhow::Result<()>{ | ||
|
||
// Create files | ||
let mut tmp_file_dst = NamedTempFile::new()?; | ||
let path_dst = String::from(tmp_file_dst.path().to_str().unwrap()); | ||
|
||
// Run our code | ||
copy("exec_script/hello_word.sh".to_string(), path_dst)?; | ||
|
||
// Read | ||
let mut contents = String::new(); | ||
tmp_file_dst.read_to_string(&mut contents)?; | ||
// Compare | ||
assert!(contents.contains("hello from an embedded shell script")); | ||
|
||
Ok(()) | ||
} | ||
} |
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,25 @@ | ||
use anyhow::Result; | ||
|
||
pub fn list() -> Result<Vec<String>> { | ||
let mut res: Vec<String> = Vec::new(); | ||
for file_path in super::Asset::iter() { | ||
res.push(file_path.to_string()); | ||
} | ||
|
||
Ok(res) | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_assets_list() -> anyhow::Result<()>{ | ||
let res_all_embedded_files = list()?; | ||
|
||
assert_eq!(res_all_embedded_files, ["exec_script/hello_word.sh", "exec_script/main.eld", "print/main.eld"]); | ||
|
||
Ok(()) | ||
} | ||
} |
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
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
Oops, something went wrong.