Skip to content

Commit

Permalink
Merge pull request #1865 from itowlson/templates-redirect-make-it-new…
Browse files Browse the repository at this point in the history
…able

Make `redirect` template newable
  • Loading branch information
itowlson authored Oct 9, 2023
2 parents 78e0f7f + 8269127 commit b13a23c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
11 changes: 8 additions & 3 deletions crates/templates/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,18 +1033,23 @@ mod tests {
let temp_dir = tempdir().unwrap();
let store = TemplateStore::new(temp_dir.path());
let manager = TemplateManager { store };
let source = TemplateSource::File(project_root());
let source1 = TemplateSource::File(test_data_root());
let source2 = TemplateSource::File(project_root());

manager
.install(&source, &InstallOptions::default(), &DiscardingReporter)
.install(&source1, &InstallOptions::default(), &DiscardingReporter)
.await
.unwrap();
manager
.install(&source2, &InstallOptions::default(), &DiscardingReporter)
.await
.unwrap();

let dummy_dir = temp_dir.path().join("dummy");
let manifest_path = dummy_dir.join("ignored_spin.toml");
let add_component = TemplateVariantInfo::AddComponent { manifest_path };

let redirect = manager.get("redirect").unwrap().unwrap();
let redirect = manager.get("add-only-redirect").unwrap().unwrap();
assert!(!redirect.supports_variant(&TemplateVariantInfo::NewApplication));
assert!(redirect.supports_variant(&add_component));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[[component]]
source = { url = "https://github.com/fermyon/spin-redirect/releases/download/v0.1.0/redirect.wasm", digest = "sha256:8bee959843f28fef2a02164f5840477db81d350877e1c22cb524f41363468e52" }
id = "{{ project-name | kebab_case }}"
environment = { DESTINATION = "{{ redirect-to }}" }
[component.trigger]
route = "{{ redirect-from }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
manifest_version = "1"
id = "add-only-redirect"
description = "Redirects a HTTP route"
trigger_type = "http"
tags = ["redirect"]

[new_application]
supported = false

[add_component]
[add_component.snippets]
component = "component.txt"

[parameters]
redirect-from = { type = "string", prompt = "Redirect from", pattern = "^/\\S*$" }
redirect-to = { type = "string", prompt = "Redirect to", pattern = "^/\\S*$" }
1 change: 1 addition & 0 deletions templates/redirect/content/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.spin/
13 changes: 13 additions & 0 deletions templates/redirect/content/spin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
spin_manifest_version = "1"
authors = ["{{authors}}"]
description = "{{project-description}}"
name = "{{project-name}}"
trigger = { type = "http", base = "{{http-base}}" }
version = "0.1.0"

[[component]]
source = { url = "https://github.com/fermyon/spin-redirect/releases/download/v0.1.0/redirect.wasm", digest = "sha256:8bee959843f28fef2a02164f5840477db81d350877e1c22cb524f41363468e52" }
id = "{{ project-name | kebab_case }}"
environment = { DESTINATION = "{{ redirect-to }}" }
[component.trigger]
route = "{{ redirect-from }}"
2 changes: 1 addition & 1 deletion templates/redirect/metadata/snippets/component.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[[component]]
source = { url = "https://github.com/fermyon/spin-redirect/releases/download/v0.1.0/redirect.wasm", digest = "sha256:8bee959843f28fef2a02164f5840477db81d350877e1c22cb524f41363468e52" }
id = "{{ project-name }}"
id = "{{ project-name | kebab_case }}"
environment = { DESTINATION = "{{ redirect-to }}" }
[component.trigger]
route = "{{ redirect-from }}"
9 changes: 5 additions & 4 deletions templates/redirect/metadata/spin-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ description = "Redirects a HTTP route"
trigger_type = "http"
tags = ["redirect"]

[new_application]
supported = false

[add_component]
skip_files = ["spin.toml"]
skip_parameters = ["project-description", "http-base"]
[add_component.snippets]
component = "component.txt"

[parameters]
project-description = { type = "string", prompt = "Description", default = "" }
http-base = { type = "string", prompt = "HTTP base", default = "/", pattern = "^/\\S*$" }
redirect-from = { type = "string", prompt = "Redirect from", pattern = "^/\\S*$" }
redirect-to = { type = "string", prompt = "Redirect to", pattern = "^/\\S*$" }
redirect-to = { type = "string", prompt = "Redirect to" }

0 comments on commit b13a23c

Please sign in to comment.