Skip to content

Feature/add module spec #19

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 63 additions & 2 deletions crates/plugins/hetzner/spec/base.star
Original file line number Diff line number Diff line change
@@ -1,4 +1,65 @@
"""
Hetzner infrastructure as Code

This plugin provides a way to interact with Hetzner Cloud API and manage
resources in a declarative way using starlark.

The plugin provides the following capabilities:
- Inherit process args from the host
- Inherit process stdio from the host
- Inherit process stdout from the host
- Inherit process environment from the host
- Mount files inside wasi
- Mount directory inside wasi
"""

module(
name = "hetzner",
version = "v0.1.0",
name = "hetzner",
version = "v0.1.0",
# capabilities represents a set of capabilities that the plugin gains all
# capabilities in starlark map to the capabilities of WASI and are describer here
# https://docs.rs/wasmtime-wasi/latest/wasmtime_wasi/struct.WasiCtxBuilder.html#
capabilities = capabilities(
inherits = [
# inherit process args from the host
INHERIT_ARGS,
# inherit process stdio from the host
INHERIT_STDIO,
# inherit process stdout from the host
INHERIT_STDOUT,
# inherit process environment from the host
INHERIT_ENV,
],
# mounts is a list of mounts that the plugin can use
# this gives the WASI module access to the host filesystem
mounts = [
# mount a dir inside WASI with full capabilities, read, write files,
# mutate directory.
mount(
host_path = "/var/run/",
guest_path = "/var/run/",
dir_perms = {
"read": true,
"mutate": true,
},
file_perms = {
"read": true,
"write": true,
},
),
# mount a dir inside WASI with read only capabilities
mount(
host_path = "/var/lib/hetzner",
guest_path = "/mnt/hetzner",
dir_perms = {
"read": true,
"mutate": false,
},
file_perms = {
"read": true,
"write": false,
},
),
],
),
)
12 changes: 8 additions & 4 deletions crates/plugins/hetzner/spec/network.star
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
network(
name = "network",
cidr = "10.0.0.1/16",
)
#network(
# name = "network",
# cidr = "10.0.0.1/16",
# docs = """
# The network module is responsible for managing
# the network cloud resource
# """,
#)
11 changes: 8 additions & 3 deletions crates/plugins/hetzner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use skyforge_sdk::skyforge_plugin;

struct Hetzner;
use exports::cloudflavor::skyforge::plugin_api::Error as ApiError;

#[skyforge_plugin]
impl SkyforgePlugin for Hetzner {
fn deserialize_config_impl(config: String) -> Result<Config, Error> {
println!("Hetzner config: {}", config);
Ok(Config { name: config })
fn get_version_impl() -> String {
"0.1.0".to_string()
}

fn verify_config_impl(config: Config) -> Result<(), ApiError> {
println!("Config: {:?}", config);
Ok(())
}
}
1 change: 1 addition & 0 deletions crates/plugins/hetzner/src/resources/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use std::collections::HashMap;
/// },
/// )
/// ```
///
pub fn network(
_name: &str,
_expose_routes_to_vswitch: bool,
Expand Down
13 changes: 8 additions & 5 deletions crates/sdk/skyforge-sdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ pub fn skyforge_plugin(_: TokenStream, input: TokenStream) -> TokenStream {
let trait_items = &impl_trait.items;

let expanded = quote! {
use exports::cloudflavor::skyforge::plugin_api::{Guest, Config,Error};

wit_bindgen::generate!({path: "wit", world: "skyforge-api"});

use exports::cloudflavor::skyforge::plugin_api::{Guest, Config,Error};

impl Guest for #name {
fn deserialize_config(config: String) -> Result<Config, Error> {
let config = Self::deserialize_config_impl(config).unwrap();
Ok(config)
fn get_version() -> String {
Self::get_version_impl()
}

fn verify_config(config: Config) -> Result<(), Error> {
Self::verify_config_impl(config)
}
}

Expand All @@ -37,3 +39,4 @@ pub fn skyforge_plugin(_: TokenStream, input: TokenStream) -> TokenStream {

TokenStream::from(expanded)
}

5 changes: 3 additions & 2 deletions spec/wit/skyforge.v1.wit
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ interface plugin-api {
other,
}

deserialize-config: func(config-str: string) -> result<config, error>;
verify-config: func(config: config) -> result<_, error>;
get-version: func() -> string;
}

world skyforge-api {
export plugin-api;
}
}