-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wapm.io integration #43
Open
jkbecker
wants to merge
17
commits into
main
Choose a base branch
from
wapm-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7840960
initial incomplete sketch of wapm.io integration
jkbecker 28bc11c
got some 'splaining to do
jkbecker 0d6e80e
significant registry module and interface cleanup
jkbecker 8c1cff4
trying to please clippy
jkbecker 37427df
c'mon, man
jkbecker d8c0b49
Merge branch 'main' of github.com:servals/serval-mesh into wapm-integ…
jkbecker 33af993
documentation and tests for identifier parsing
jkbecker c9c7345
downloading executables, error handling
jkbecker c43b2bb
once again trying to please cargo fmt
jkbecker d58d3bf
actually storing the manifest & binary
jkbecker 08589ab
omfg clippy
jkbecker ce757ca
Some cleanup - pulling, storing, running works now
jkbecker 1bfc363
yes clippy I know
jkbecker d6fc005
cleanup
jkbecker 7f4f2c3
improve hint description
jkbecker 007d98e
module names can have underscores
jkbecker 82dc7dd
better error handling
jkbecker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ pub mod errors; | |
pub mod futures; | ||
pub mod mdns; | ||
pub mod networking; | ||
pub mod registry; | ||
pub mod structs; |
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,101 @@ | ||
use std::str::FromStr; | ||
jkbecker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
use crate::errors::ServalError; | ||
|
||
/// Package registry information, used to download executables and construct the Manifest. | ||
#[derive(Debug, PartialEq)] | ||
pub struct Registry { | ||
pub namespace: String, | ||
pub baseurl_summary: &'static str, | ||
pub baseurl_download: &'static str, | ||
} | ||
|
||
impl FromStr for Registry { | ||
type Err = (); | ||
|
||
fn from_str(input: &str) -> Result<Registry, Self::Err> { | ||
if let "wapm" = input { | ||
Ok(Registry { | ||
namespace: String::from("io.wapm"), | ||
baseurl_summary: "https://wapm.io/{author}/{name}@{version}", | ||
baseurl_download: "https://registry-cdn.wapm.io/contents/{author}/{name}/{version}/target/wasm32-wasi/release/{name}.wasm", | ||
}) | ||
} else { | ||
Err(()) | ||
} | ||
} | ||
} | ||
|
||
/// Specification for a registry package | ||
#[derive(Debug, PartialEq)] | ||
pub struct RegistryPackageSpec { | ||
pub registry: Registry, | ||
pub author: String, | ||
pub package: String, | ||
pub version: String, | ||
} | ||
|
||
impl RegistryPackageSpec { | ||
|
||
/// Parses a registry package using a registry key and a package identifier | ||
pub fn parse(registry: &str, identifer: String) -> Result<RegistryPackageSpec, ServalError> { | ||
let registry_spec = Registry::from_str(registry).unwrap(); | ||
// Split the string by "/". We expect the provided identifier to be one of the following: | ||
// - author/package/version | ||
// - author/package@version | ||
jkbecker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let pkg_author_spec: Vec<&str> = identifer.split('/').collect(); | ||
match pkg_author_spec.len() { | ||
// we assume the provided format is author/package@version | ||
2 => { | ||
let author = pkg_author_spec[0].to_string(); | ||
// The string after the / should contain package@version | ||
let pkg_version_spec: Vec<&str> = pkg_author_spec[1].split('@').collect(); | ||
match pkg_version_spec.len() { | ||
// we found a package and version | ||
2 => { | ||
let (name, version) = ( | ||
pkg_version_spec[0].to_string(), | ||
pkg_version_spec[1].to_string(), | ||
); | ||
Ok(RegistryPackageSpec { | ||
registry: registry_spec, | ||
author, | ||
package: name, | ||
version, | ||
}) | ||
} | ||
_ => Err(ServalError::PackageRegistryManifestError(String::from( | ||
"could not parse version.", | ||
))), | ||
} | ||
} | ||
// we assume the provided format is author/package/version | ||
3 => { | ||
let (author, name, version) = ( | ||
pkg_author_spec[0].to_string(), | ||
pkg_author_spec[1].to_string(), | ||
pkg_author_spec[2].to_string(), | ||
); | ||
Ok(RegistryPackageSpec { | ||
registry: registry_spec, | ||
author, | ||
package: name, | ||
version, | ||
}) | ||
} | ||
// unclear format, we're erroring out | ||
_ => Err(ServalError::PackageRegistryManifestError(String::from( | ||
"could not parse package identifier.", | ||
))), | ||
} | ||
} | ||
|
||
/// The fully-qualified task name of the package, composed of the registry | ||
/// namespace, author, package name and version. | ||
pub fn fqtn(self) -> String { | ||
format!( | ||
"{}.{}.{}@{}", | ||
self.registry.namespace, self.author, self.package, self.version | ||
) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can eventually make the identifier a type more specific than a string and have clap parse it for us. Some examples here. There is no need to do that in this PR, however.