Component

Struct Component 

Source
pub struct Component {
Show 15 fields pub source: ComponentSource, pub description: String, pub variables: IndexMap<LowerSnakeId, String>, pub environment: IndexMap<String, String>, pub files: Vec<WasiFilesMount>, pub exclude_files: Vec<String>, pub allowed_http_hosts: Vec<String>, pub allowed_outbound_hosts: Vec<String>, pub key_value_stores: Vec<String>, pub sqlite_databases: Vec<String>, pub ai_models: Vec<String>, pub build: Option<ComponentBuildConfig>, pub tool: IndexMap<String, Table>, pub dependencies_inherit_configuration: bool, pub dependencies: ComponentDependencies,
}
Expand description

A Spin component.

Fields§

§source: ComponentSource

The file, package, or URL containing the component Wasm binary.

Example: source = "bin/cart.wasm"

Learn more: https://spinframework.dev/writing-apps#the-component-source

§description: String

A human-readable description of the component.

Example: description = "Shopping cart"

§variables: IndexMap<LowerSnakeId, String>

Configuration variables available to the component. Names must be in lower_snake_case. Values are strings, and may refer to application variables using {{ ... }} syntax.

variables = { users_endpoint = "https://{{ api_host }}/users"}

Learn more: https://spinframework.dev/variables#adding-variables-to-your-applications

§environment: IndexMap<String, String>

Environment variables to be set for the Wasm module.

environment = { DB_URL = "mysql://spin:spin@localhost/dev" }

§files: Vec<WasiFilesMount>

The files the component is allowed to read. Each list entry is either:

  • a glob pattern (e.g. “assets/**/*.jpg”); or

  • a source-destination pair indicating where a host directory should be mapped in the guest (e.g. { source = “assets”, destination = “/” })

Learn more: https://spinframework.dev/writing-apps#including-files-with-components

§exclude_files: Vec<String>

Any files or glob patterns that should not be available to the Wasm module at runtime, even though they match a `files`` entry.

Example: exclude_files = ["secrets/*"]

Learn more: https://spinframework.dev/writing-apps#including-files-with-components

§allowed_http_hosts: Vec<String>
👎Deprecated

Deprecated. Use allowed_outbound_hosts instead.

Example: allowed_http_hosts = ["example.com"]

§allowed_outbound_hosts: Vec<String>

The network destinations which the component is allowed to access. Each entry is in the form “(scheme)://(host)[:port]”. Each element allows * as a wildcard e.g. “https://*” (HTTPS on the default port to any destination) or “*://localhost:*” (any protocol to any port on localhost). The host part allows segment wildcards for subdomains e.g. “https://*.example.com”. Application variables are allowed using `{{ my_var }}`` syntax.

Example: allowed_outbound_hosts = ["redis://myredishost.com:6379"]

Learn more: https://spinframework.dev/http-outbound#granting-http-permissions-to-components

§key_value_stores: Vec<String>

The key-value stores which the component is allowed to access. Stores are identified by label e.g. “default” or “customer”. Stores other than “default” must be mapped to a backing store in the runtime config.

Example: key_value_stores = ["default", "my-store"]

Learn more: https://spinframework.dev/kv-store-api-guide#custom-key-value-stores

§sqlite_databases: Vec<String>

The SQLite databases which the component is allowed to access. Databases are identified by label e.g. “default” or “analytics”. Databases other than “default” must be mapped to a backing store in the runtime config. Use “spin up –sqlite” to run database setup scripts.

Example: sqlite_databases = ["default", "my-database"]

Learn more: https://spinframework.dev/sqlite-api-guide#preparing-an-sqlite-database

§ai_models: Vec<String>

The AI models which the component is allowed to access. For local execution, you must download all models; for hosted execution, you should check which models are available in your target environment.

Example: ai_models = ["llama2-chat"]

Learn more: https://spinframework.dev/serverless-ai-api-guide#using-serverless-ai-from-applications

§build: Option<ComponentBuildConfig>

The component build configuration.

Learn more: https://spinframework.dev/build

§tool: IndexMap<String, Table>

Settings for custom tools or plugins. Spin ignores this field.

§dependencies_inherit_configuration: bool

If true, dependencies can invoke Spin APIs with the same permissions as the main component. If false, dependencies have no permissions (e.g. network, key-value stores, SQLite databases).

Learn more: https://spinframework.dev/writing-apps#dependency-permissions

§dependencies: ComponentDependencies

Specifies how to satisfy Wasm Component Model imports of this component.

Learn more: https://spinframework.dev/writing-apps#using-component-dependencies

Implementations§

Source§

impl Component

Source

pub fn normalized_allowed_outbound_hosts(&self) -> Result<Vec<String>>

Combine allowed_outbound_hosts with the deprecated allowed_http_hosts into one array all normalized to the syntax of allowed_outbound_hosts.

Trait Implementations§

Source§

impl Clone for Component

Source§

fn clone(&self) -> Component

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Component

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Component

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for Component

Source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
Source§

impl Serialize for Component

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T