Skip to content

Commit 8046d05

Browse files
refactor(example): rename blank slate to custom template
Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com> fix health topic Signed-off-by: Brooks Townsend <brooksmtownsend@gmail.com>
1 parent c5b3760 commit 8046d05

24 files changed

+36
-35
lines changed

examples/rust/providers/blank-slate/Cargo.toml examples/rust/providers/custom-template/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
2-
name = "wasmcloud-example-blank-slate"
2+
name = "wasmcloud-provider-custom-template"
33
version = "0.1.0"
44
edition = "2021"
55
description = """
6-
A blank slate capability provider built for quick implementation of custom capabilities.
6+
A capability provider template built for implementation of custom capabilities.
77
"""
88

99
[workspace]

examples/rust/providers/blank-slate/README.md examples/rust/providers/custom-template/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Blank Slate Capability Provider
1+
# Custom Capability Provider
22

3-
This capability provider is a blank slate for creating providers with custom capabilities. It uses the [wasmcloud-provider-sdk](https://crates.io/crates/wasmcloud-provider-sdk) and implements the [Provider](https://docs.rs/wasmcloud-provider-sdk/0.5.0/wasmcloud_provider_sdk/trait.Provider.html) trait with an example handler that will persist the links that target the provider (target links) and links where the provider is the source and targets a component (source links).
3+
This capability provider is a template for creating providers with custom capabilities. It uses the [wasmcloud-provider-sdk](https://crates.io/crates/wasmcloud-provider-sdk) and implements the [Provider](https://docs.rs/wasmcloud-provider-sdk/0.5.0/wasmcloud_provider_sdk/trait.Provider.html) trait with an example handler that will persist the links that target the provider (target links) and links where the provider is the source and targets a component (source links).
44

55
The purpose of this example is to provide comprehensive comments on the usage of our wasmCloud provider SDK, from serving RPC exports to invoking component imports. The code is informative to read through and provides a base for extending wasmCloud with custom capabilities.
66

@@ -25,19 +25,19 @@ You can run this capability provider as a binary by passing a simple base64 enco
2525

2626
```bash
2727
nats-server -js &
28-
echo '{"lattice_rpc_url": "0.0.0.0:4222", "lattice_rpc_prefix": "default", "provider_key": "blank-slate", "config": {"foo": "bar"}, "env_values": {}, "link_definitions": [], "otel_config": {"enable_observability": false}}' | base64 | cargo run
28+
echo '{"lattice_rpc_url": "0.0.0.0:4222", "lattice_rpc_prefix": "default", "provider_key": "custom-template", "config": {"foo": "bar"}, "env_values": {}, "link_definitions": [], "otel_config": {"enable_observability": false}}' | base64 | cargo run
2929
```
3030

3131
And in another terminal, you can request the health of the provider using the NATS CLI
3232

3333
```bash
34-
nats req "wasmbus.rpc.default.blank-slate.default.health '{}'
34+
nats req "wasmbus.rpc.default.custom-template.health" '{}'
3535
```
3636

3737
Additionally, you can invoke the provider directly which will send test data to each linked component
3838

3939
```bash
40-
wash call blank-slate wasmcloud:example/system-info.call
40+
wash call custom-template wasmcloud:example/system-info.call
4141
```
4242

4343
## Running as an application

examples/rust/providers/blank-slate/component/Cargo.toml examples/rust/providers/custom-template/component/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "blank-slate-test-component"
2+
name = "custom-template-test-component"
33
edition = "2021"
44
version = "0.1.0"
55

examples/rust/providers/blank-slate/component/README.md examples/rust/providers/custom-template/component/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Blank slate test component
1+
# Custom template test component
22

3-
This component is meant to test the [blank slate capability provider](../) by an implementation of the interface on the component.
3+
This component is meant to test the [custom template capability provider](../) by an implementation of the interface on the component.
44

55
## Build
66

examples/rust/providers/blank-slate/component/src/lib.rs examples/rust/providers/custom-template/component/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use crate::exports::wasmcloud::example::process_data::Guest;
55
use crate::wasi::logging::logging::*;
66
use crate::wasmcloud::example::system_info::Kind;
77

8-
struct BlankSlateComponent;
8+
struct CustomTemplateComponent;
99

10-
impl Guest for BlankSlateComponent {
10+
impl Guest for CustomTemplateComponent {
1111
fn process(data: Data) -> String {
1212
log(Level::Info, "", &format!("Data received: {:?}", data));
1313
// Request OS and architecture information
@@ -17,4 +17,4 @@ impl Guest for BlankSlateComponent {
1717
}
1818
}
1919

20-
export!(BlankSlateComponent);
20+
export!(CustomTemplateComponent);

examples/rust/providers/blank-slate/component/wasmcloud.toml examples/rust/providers/custom-template/component/wasmcloud.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "Blank slate test component"
1+
name = "Custom template test component"
22
language = "rust"
33
type = "component"
44

examples/rust/providers/blank-slate/component/wit/deps.lock examples/rust/providers/custom-template/component/wit/deps.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[blankslate]
1+
[custom]
22
path = "../../wit"
33
sha256 = "3af8ebbb348273a8a541440c4fbad2c739d03257903ab172d6722c68a694f86c"
44
sha512 = "2d83b11fd3ac592c4ed87a05feefae1d26803b626f5a425a109202196b6d951bfb407cb4f97c6209891ef70aeb3b86b8b8338c880d46fc1976fa7a9b5ca7201b"
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
blankslate = "../../wit"
1+
custom = "../../wit"
22
logging = "https://github.com/WebAssembly/wasi-logging/archive/main.tar.gz"

examples/rust/providers/blank-slate/component/wit/world.wit examples/rust/providers/custom-template/component/wit/world.wit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package wasmcloud:blankslate;
1+
package wasmcloud:custom;
22

33
world component {
44
// Import logging for processing data
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
//! A blank slate provider that's meant to inform developers how to build a capability provider.
1+
//! This provider is a template that's meant to inform developers how to build a custom capability provider.
2+
//!
23
//! The implementation in `./provider.rs` uses the `wasmcloud-provider-sdk` to provide a scaffold
34
//! for building a capability provider with a custom interface. Take note of the documentation
45
//! comments in the code to understand how to build a capability provider.
56
67
mod config;
78
mod provider;
89

9-
use provider::BlankSlateProvider;
10+
use provider::CustomTemplateProvider;
1011

1112
/// Capability providers are native executables, so the entrypoint is the same as any other Rust
1213
/// binary, `main()`. Typically the `main` function is kept simple and the provider logic is
1314
/// implemented in a separate module. Head to the `provider.rs` file to see the implementation of
1415
/// the `BlankSlateProvider`.
1516
#[tokio::main]
1617
async fn main() -> anyhow::Result<()> {
17-
BlankSlateProvider::run().await?;
18-
eprintln!("Blank slate provider exiting");
18+
CustomTemplateProvider::run().await?;
19+
eprintln!("Custom template provider exiting");
1920
Ok(())
2021
}

examples/rust/providers/blank-slate/src/provider.rs examples/rust/providers/custom-template/src/provider.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ wit_bindgen_wrpc::generate!();
1313

1414
#[derive(Default, Clone)]
1515
/// Your provider struct is where you can store any state or configuration that your provider needs to keep track of.
16-
pub struct BlankSlateProvider {
16+
pub struct CustomTemplateProvider {
1717
config: Arc<RwLock<ProviderConfig>>,
1818
/// All components linked to this provider and their config.
1919
linked_from: Arc<RwLock<HashMap<String, HashMap<String, String>>>>,
@@ -23,16 +23,16 @@ pub struct BlankSlateProvider {
2323

2424
/// This `impl` block is where you can implement additional methods for your provider. We've provided two examples
2525
/// to run and load [`HostData`], and when you have custom logic to implement, you can add it here.
26-
impl BlankSlateProvider {
26+
impl CustomTemplateProvider {
2727
/// Execute the provider, loading [`HostData`] from the host which includes the provider's configuration and
28-
/// information about the host. Once you use the passed configuration to construct a [`BlankSlateProvider`],
28+
/// information about the host. Once you use the passed configuration to construct a [`CustomTemplateProvider`],
2929
/// you can run the provider by calling `run_provider` and then serving the provider's exports on the proper
3030
/// RPC topics via `wrpc::serve`.
3131
///
3232
/// This step is essentially the same for every provider, and you shouldn't need to modify this function.
3333
pub async fn run() -> anyhow::Result<()> {
3434
let provider = Self::default();
35-
let shutdown = run_provider(provider.clone(), "blank-slate-provider")
35+
let shutdown = run_provider(provider.clone(), "custom-template-provider")
3636
.await
3737
.context("failed to run provider")?;
3838

@@ -66,7 +66,7 @@ use crate::provider::wasmcloud::example::process_data::Data;
6666
/// When a provider specifies an `export` in its `wit/world.wit` file, the `wit-bindgen-wrpc` tool generates
6767
/// a trait that the provider must implement. This trait is used to handle invocations from components that
6868
/// link to the provider. The `Handler` trait is generated for each export in the WIT world.
69-
impl Handler<Option<Context>> for BlankSlateProvider {
69+
impl Handler<Option<Context>> for CustomTemplateProvider {
7070
/// Request information about the system the provider is running on
7171
async fn request_info(&self, ctx: Option<Context>, kind: Kind) -> anyhow::Result<String> {
7272
// The `ctx` contains information about the component that invoked the request. You can use
@@ -137,7 +137,7 @@ impl Handler<Option<Context>> for BlankSlateProvider {
137137
/// Implementing the [`Provider`] trait is optional. Implementing the methods in the trait allow you to set up
138138
/// custom logic for handling links, deletions, and shutdowns. This is useful to set up any connections, state,
139139
/// resources, or cleanup that your provider needs to do when it is linked to or unlinked from a component.
140-
impl Provider for BlankSlateProvider {
140+
impl Provider for CustomTemplateProvider {
141141
/// Initialize your provider with the given configuration. This is a good place to set up any state or
142142
/// resources your provider needs to run.
143143
async fn init(&self, config: impl ProviderInitConfig) -> anyhow::Result<()> {

examples/rust/providers/blank-slate/wadm.yaml examples/rust/providers/custom-template/wadm.yaml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
apiVersion: core.oam.dev/v1beta1
22
kind: Application
33
metadata:
4-
name: blank-slate-provider
4+
name: custom-template-provider
55
annotations:
66
version: v0.0.1
7-
description: 'A blank slate application with provider and component built for extending wasmCloud with custom capabilities'
7+
description: 'An application with a provider and component built for extending wasmCloud with custom capabilities'
88
spec:
99
components:
1010
- name: test-component
1111
type: component
1212
properties:
13-
image: file://./component/build/blank_slate_test_component.wasm
13+
image: file://./component/build/custom_template_test_component.wasm
1414
traits:
1515
- type: spreadscaler
1616
properties:
1717
replicas: 1
1818
# Link the component to the provider on wasmcloud:example/system-info
1919
- type: link
2020
properties:
21-
target: blank-slate
21+
target: custom-template
2222
namespace: wasmcloud
2323
package: example
2424
interfaces: [system-info]
2525

26-
- name: blank-slate
26+
- name: custom-template
2727
type: capability
2828
properties:
29-
image: file://./build/wasmcloud-example-blank-slate.par.gz
30-
id: blank-slate
29+
image: file://./build/wasmcloud-example-custom-template.par.gz
30+
id: custom-template
3131
config:
3232
- name: provider-config
3333
properties:

examples/rust/providers/blank-slate/wasmcloud.toml examples/rust/providers/custom-template/wasmcloud.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "BlankSlate"
1+
name = "Custom Provider"
22
language = "rust"
33
type = "provider"
44

0 commit comments

Comments
 (0)