Skip to content

Commit

Permalink
Merge pull request #2104 from itowlson/manifest-tool-settings
Browse files Browse the repository at this point in the history
Add manifest field for plugin settings
  • Loading branch information
itowlson authored Nov 16, 2023
2 parents 8337a35 + bc9aa87 commit 1d662e3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/manifest/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn v1_to_v2_app(manifest: v1::AppManifestV1) -> Result<v2::AppManifest, Erro
description: manifest.description,
authors: manifest.authors,
trigger_global_configs,
tool: Default::default(),
};

let app_variables = manifest
Expand Down Expand Up @@ -82,6 +83,7 @@ pub fn v1_to_v2_app(manifest: v1::AppManifestV1) -> Result<v2::AppManifest, Erro
sqlite_databases,
ai_models,
build: component.build,
tool: Default::default(),
allowed_outbound_hosts,
allowed_http_hosts: Vec::new(),
},
Expand Down
41 changes: 41 additions & 0 deletions crates/manifest/src/schema/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct AppDetails {
/// `[application.triggers.<type>]`
#[serde(rename = "trigger", default, skip_serializing_if = "Map::is_empty")]
pub trigger_global_configs: Map<String, toml::Table>,
/// Settings for custom tools or plugins. Spin ignores this field.
#[serde(default, skip_serializing_if = "Map::is_empty")]
pub tool: Map<String, toml::Table>,
}

/// Trigger configuration
Expand Down Expand Up @@ -131,6 +134,9 @@ pub struct Component {
/// Build configuration
#[serde(default, skip_serializing_if = "Option::is_none")]
pub build: Option<ComponentBuildConfig>,
/// Settings for custom tools or plugins. Spin ignores this field.
#[serde(default, skip_serializing_if = "Map::is_empty")]
pub tool: Map<String, toml::Table>,
}

impl Component {
Expand Down Expand Up @@ -224,6 +230,41 @@ mod tests {
FakeTriggerConfig::deserialize(manifest.triggers["fake"][0].config.clone()).unwrap();
}

#[derive(Deserialize)]
#[allow(dead_code)]
struct FakeGlobalToolConfig {
lint_level: String,
}

#[derive(Deserialize)]
#[allow(dead_code)]
struct FakeComponentToolConfig {
command: String,
}

#[test]
fn deserialising_custom_tool_settings() {
let manifest = AppManifest::deserialize(toml! {
spin_manifest_version = 2
[application]
name = "trigger-configs"
[application.tool.lint]
lint_level = "savage"
[[trigger.fake]]
something = "something else"
[component.fake]
source = "dummy"
[component.fake.tool.clean]
command = "cargo clean"
})
.unwrap();

FakeGlobalToolConfig::deserialize(manifest.application.tool["lint"].clone()).unwrap();
let fake_id: KebabId = "fake".to_owned().try_into().unwrap();
FakeComponentToolConfig::deserialize(manifest.components[&fake_id].tool["clean"].clone())
.unwrap();
}

#[test]
fn test_valid_snake_ids() {
for valid in ["default", "mixed_CASE_words", "letters1_then2_numbers345"] {
Expand Down
10 changes: 10 additions & 0 deletions crates/manifest/tests/ui/maximal.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"fake": {
"global_option": true
}
},
"tool": {
"lint": {
"lint_level": "savage"
}
}
},
"variables": {
Expand Down Expand Up @@ -77,6 +82,11 @@
"watch": [
"src/**/*.rs"
]
},
"tool": {
"clean": {
"command": "cargo clean"
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/manifest/tests/ui/maximal.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ authors = ["[email protected]", "[email protected]"]
[application.trigger.fake]
global_option = true

[application.tool.lint]
lint_level = "savage"

[variables]
var_one = { default = "Default" }
var_TWO = { required = true, secret = true }
Expand Down Expand Up @@ -38,3 +41,6 @@ ai_models = ["llama2-chat"]
command = "cargo build"
workdir = "my-component"
watch = ["src/**/*.rs"]

[component.maximal-component.tool.clean]
command = "cargo clean"

0 comments on commit 1d662e3

Please sign in to comment.