From dd09414294832d4bdd0c593c7711906548ebafe0 Mon Sep 17 00:00:00 2001 From: Brooks Townsend Date: Thu, 1 Aug 2024 16:18:25 -0400 Subject: [PATCH 1/2] fix(wit): update bindings to types 0.2.0 Signed-off-by: Brooks Townsend --- crates/wadm-types/src/bindings.rs | 151 +++++++++++++++++---- crates/wadm-types/src/lib.rs | 1 + crates/wadm-types/wit/deps.lock | 4 +- crates/wadm-types/wit/deps/wadm/client.wit | 4 +- crates/wadm-types/wit/deps/wadm/types.wit | 55 ++++++-- crates/wadm-types/wit/interfaces.wit | 8 +- wit/wadm/client.wit | 4 +- wit/wadm/types.wit | 55 ++++++-- 8 files changed, 223 insertions(+), 59 deletions(-) diff --git a/crates/wadm-types/src/bindings.rs b/crates/wadm-types/src/bindings.rs index 92f5e390..698badc9 100644 --- a/crates/wadm-types/src/bindings.rs +++ b/crates/wadm-types/src/bindings.rs @@ -3,8 +3,9 @@ use crate::{ ComponentStatus, DeleteResult, GetResult, ModelSummary, PutResult, Status, StatusInfo, StatusResult, StatusType, TraitStatus, VersionInfo, }, - CapabilityProperties, Component, ComponentProperties, ConfigProperty, LinkProperty, Manifest, - Metadata, Properties, Specification, Spread, SpreadScalerProperty, Trait, TraitProperty, + CapabilityProperties, Component, ComponentProperties, ConfigDefinition, ConfigProperty, + LinkProperty, Manifest, Metadata, Policy, Properties, SecretProperty, SecretSourceProperty, + Specification, Spread, SpreadScalerProperty, TargetConfig, Trait, TraitProperty, }; use wasmcloud::wadm; @@ -16,6 +17,8 @@ wit_bindgen_wrpc::generate!({ ], }); +// Trait implementations for converting types in the API module to the generated types + impl From for wadm::types::OamManifest { fn from(manifest: Manifest) -> Self { wadm::types::OamManifest { @@ -41,6 +44,7 @@ impl From for wadm::types::Specification { fn from(spec: Specification) -> Self { wadm::types::Specification { components: spec.components.into_iter().map(|c| c.into()).collect(), + policies: spec.policies.into_iter().map(|c| c.into()).collect(), } } } @@ -52,10 +56,17 @@ impl From for wadm::types::Component { properties: component.properties.into(), traits: component .traits - .unwrap_or_default() - .into_iter() - .map(|t| t.into()) - .collect(), + .map(|traits| traits.into_iter().map(|t| t.into()).collect()), + } + } +} + +impl From for wadm::types::Policy { + fn from(policy: Policy) -> Self { + wadm::types::Policy { + name: policy.name, + properties: policy.properties.into_iter().map(|p| p.into()).collect(), + type_: policy.policy_type, } } } @@ -79,6 +90,7 @@ impl From for wadm::types::ComponentProperties { image: properties.image, id: properties.id, config: properties.config.into_iter().map(|c| c.into()).collect(), + secrets: properties.secrets.into_iter().map(|c| c.into()).collect(), } } } @@ -89,6 +101,7 @@ impl From for wadm::types::CapabilityProperties { image: properties.image, id: properties.id, config: properties.config.into_iter().map(|c| c.into()).collect(), + secrets: properties.secrets.into_iter().map(|c| c.into()).collect(), } } } @@ -102,6 +115,26 @@ impl From for wadm::types::ConfigProperty { } } +impl From for wadm::types::SecretProperty { + fn from(property: SecretProperty) -> Self { + wadm::types::SecretProperty { + name: property.name, + properties: property.properties.into(), + } + } +} + +impl From for wadm::types::SecretSourceProperty { + fn from(property: SecretSourceProperty) -> Self { + wadm::types::SecretSourceProperty { + policy: property.policy, + key: property.key, + field: property.field, + version: property.version, + } + } +} + impl From for wadm::types::Trait { fn from(trait_: Trait) -> Self { wadm::types::Trait { @@ -126,25 +159,35 @@ impl From for wadm::types::TraitProperty { impl From for wadm::types::LinkProperty { fn from(property: LinkProperty) -> Self { wadm::types::LinkProperty { - target: property.target, + source: property.source.map(|c| c.into()), + target: property.target.into(), namespace: property.namespace, package: property.package, interfaces: property.interfaces, - source_config: property - .source_config - .into_iter() - .map(|c| c.into()) - .collect(), - target_config: property - .target_config - .into_iter() - .map(|c| c.into()) - .collect(), name: property.name, } } } +impl From for wadm::types::ConfigDefinition { + fn from(definition: ConfigDefinition) -> Self { + wadm::types::ConfigDefinition { + config: definition.config.into_iter().map(|c| c.into()).collect(), + secrets: definition.secrets.into_iter().map(|s| s.into()).collect(), + } + } +} + +impl From for wadm::types::TargetConfig { + fn from(config: TargetConfig) -> Self { + wadm::types::TargetConfig { + name: config.name, + config: config.config.into_iter().map(|c| c.into()).collect(), + secrets: config.secrets.into_iter().map(|s| s.into()).collect(), + } + } +} + impl From for wadm::types::SpreadscalerProperty { fn from(property: SpreadScalerProperty) -> Self { wadm::types::SpreadscalerProperty { @@ -218,6 +261,8 @@ impl From for wadm::types::StatusType { } } +// Trait implementations for converting generated types to the types in the API module + impl From for StatusType { fn from(status: wadm::types::StatusType) -> Self { match status { @@ -300,6 +345,7 @@ impl From for Specification { fn from(spec: wadm::types::Specification) -> Self { Specification { components: spec.components.into_iter().map(|c| c.into()).collect(), + policies: spec.policies.into_iter().map(|c| c.into()).collect(), } } } @@ -309,7 +355,19 @@ impl From for Component { Component { name: component.name, properties: component.properties.into(), - traits: Some(component.traits.into_iter().map(|t| t.into()).collect()), // Always wrap in Some + traits: component + .traits + .map(|traits| traits.into_iter().map(|t| t.into()).collect()), + } + } +} + +impl From for Policy { + fn from(policy: wadm::types::Policy) -> Self { + Policy { + name: policy.name, + properties: policy.properties.into_iter().map(|p| p.into()).collect(), + policy_type: policy.type_, } } } @@ -333,6 +391,7 @@ impl From for ComponentProperties { image: properties.image, id: properties.id, config: properties.config.into_iter().map(|c| c.into()).collect(), + secrets: properties.secrets.into_iter().map(|c| c.into()).collect(), } } } @@ -343,6 +402,7 @@ impl From for CapabilityProperties { image: properties.image, id: properties.id, config: properties.config.into_iter().map(|c| c.into()).collect(), + secrets: properties.secrets.into_iter().map(|c| c.into()).collect(), } } } @@ -356,6 +416,26 @@ impl From for ConfigProperty { } } +impl From for SecretProperty { + fn from(property: wadm::types::SecretProperty) -> Self { + SecretProperty { + name: property.name, + properties: property.properties.into(), + } + } +} + +impl From for SecretSourceProperty { + fn from(property: wadm::types::SecretSourceProperty) -> Self { + SecretSourceProperty { + policy: property.policy, + key: property.key, + field: property.field, + version: property.version, + } + } +} + impl From for Trait { fn from(trait_: wadm::types::Trait) -> Self { Trait { @@ -381,22 +461,35 @@ impl From for TraitProperty { impl From for LinkProperty { fn from(property: wadm::types::LinkProperty) -> Self { + #[allow(deprecated)] LinkProperty { - target: property.target, + source: property.source.map(|c| c.into()), + target: property.target.into(), namespace: property.namespace, package: property.package, interfaces: property.interfaces, - source_config: property - .source_config - .into_iter() - .map(|c| c.into()) - .collect(), - target_config: property - .target_config - .into_iter() - .map(|c| c.into()) - .collect(), name: property.name, + source_config: None, + target_config: None, + } + } +} + +impl From for ConfigDefinition { + fn from(definition: wadm::types::ConfigDefinition) -> Self { + ConfigDefinition { + config: definition.config.into_iter().map(|c| c.into()).collect(), + secrets: definition.secrets.into_iter().map(|s| s.into()).collect(), + } + } +} + +impl From for TargetConfig { + fn from(config: wadm::types::TargetConfig) -> Self { + TargetConfig { + name: config.name, + config: config.config.into_iter().map(|c| c.into()).collect(), + secrets: config.secrets.into_iter().map(|s| s.into()).collect(), } } } diff --git a/crates/wadm-types/src/lib.rs b/crates/wadm-types/src/lib.rs index dc9ddf72..5458719c 100644 --- a/crates/wadm-types/src/lib.rs +++ b/crates/wadm-types/src/lib.rs @@ -326,6 +326,7 @@ impl Trait { /// Properties for defining traits #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema)] #[serde(untagged)] +#[allow(clippy::large_enum_variant)] pub enum TraitProperty { Link(LinkProperty), SpreadScaler(SpreadScalerProperty), diff --git a/crates/wadm-types/wit/deps.lock b/crates/wadm-types/wit/deps.lock index d55f9626..7cb83cf4 100644 --- a/crates/wadm-types/wit/deps.lock +++ b/crates/wadm-types/wit/deps.lock @@ -1,4 +1,4 @@ [wadm] path = "../../../wit/wadm" -sha256 = "3a7cd5d4f4bff4279330c3dfbb5dc282ee84fa03fd12b16d7a14c11feae8e7b0" -sha512 = "b80e5c44367398b40e85d418a9ce6f14db66f6c64b70eaa8029960b923e73bc023d423b884cfeb797122a29b195c2a4d67d1896a80d3d271246f0b379ddaaf2a" +sha256 = "554eedbde75c59b750d2dd0c6fe374e3d70f4c1ef4205da784691deeceeb3942" +sha512 = "056155b17c7b20455a9db9a63b7b114433c4755baccbebe566d1be88ea10b38dfeebb32090bf60057afa8e7a8a27ae51e5a5a837e68ab33d40e7a187d8853b52" diff --git a/crates/wadm-types/wit/deps/wadm/client.wit b/crates/wadm-types/wit/deps/wadm/client.wit index a6b53a04..0eab835d 100644 --- a/crates/wadm-types/wit/deps/wadm/client.wit +++ b/crates/wadm-types/wit/deps/wadm/client.wit @@ -1,4 +1,4 @@ -package wasmcloud:wadm@0.1.0; +package wasmcloud:wadm@0.2.0; /// A Wadm client which interacts with the wadm api interface client { @@ -11,7 +11,7 @@ interface client { // Deploys a model to the WADM system. // If no lattice is provided, the default lattice name 'default' is used. - deploy-model: func(model-name: string, version: option, lattice: option) -> result<_, string>; + deploy-model: func(model-name: string, version: option, lattice: option) -> result; // Undeploys a model from the WADM system. undeploy-model: func(model-name: string, lattice: option, non-destructive: bool) -> result<_, string>; diff --git a/crates/wadm-types/wit/deps/wadm/types.wit b/crates/wadm-types/wit/deps/wadm/types.wit index 2125e012..17157d10 100644 --- a/crates/wadm-types/wit/deps/wadm/types.wit +++ b/crates/wadm-types/wit/deps/wadm/types.wit @@ -1,7 +1,6 @@ -package wasmcloud:wadm@0.1.0; +package wasmcloud:wadm@0.2.0; interface types { - record model-summary { name: string, version: string, @@ -99,13 +98,14 @@ interface types { // The specification for this manifest record specification { components: list, + policies: list } // A component definition record component { name: string, properties: properties, - traits: list, + traits: option>, } // Properties that can be defined for a component @@ -119,6 +119,7 @@ interface types { image: string, id: option, config: list, + secrets: list, } // Properties for a capability @@ -126,12 +127,14 @@ interface types { image: string, id: option, config: list, + secrets: list, } - // Properties for the config list associated with components, providers, and links - record config-property { + // A policy definition + record policy { name: string, - properties: option>>, + properties: list>, + %type: string, } // A trait definition @@ -149,15 +152,47 @@ interface types { // Properties for links record link-property { - target: string, namespace: string, %package: string, interfaces: list, - source-config: list, - target-config: list, + source: option, + target: target-config, name: option, } + // Configuration definition + record config-definition { + config: list, + secrets: list, + } + + // Configuration properties + record config-property { + name: string, + properties: option>>, + } + + // Secret properties + record secret-property { + name: string, + properties: secret-source-property, + } + + // Secret source properties + record secret-source-property { + policy: string, + key: string, + field: option, + version: option, + } + + // Target configuration + record target-config { + name: string, + config: list, + secrets: list, + } + // Properties for spread scalers record spreadscaler-property { instances: u32, @@ -170,4 +205,4 @@ interface types { requirements: list>, weight: option, } -} +} \ No newline at end of file diff --git a/crates/wadm-types/wit/interfaces.wit b/crates/wadm-types/wit/interfaces.wit index 21bf6e22..6f6236df 100644 --- a/crates/wadm-types/wit/interfaces.wit +++ b/crates/wadm-types/wit/interfaces.wit @@ -1,7 +1,7 @@ -package wasmcloud:wadm-types@0.1.0; +package wasmcloud:wadm-types@0.2.0; world interfaces { - import wasmcloud:wadm/types@0.1.0; - import wasmcloud:wadm/client@0.1.0; - import wasmcloud:wadm/handler@0.1.0; + import wasmcloud:wadm/types@0.2.0; + import wasmcloud:wadm/client@0.2.0; + import wasmcloud:wadm/handler@0.2.0; } diff --git a/wit/wadm/client.wit b/wit/wadm/client.wit index a6b53a04..0eab835d 100644 --- a/wit/wadm/client.wit +++ b/wit/wadm/client.wit @@ -1,4 +1,4 @@ -package wasmcloud:wadm@0.1.0; +package wasmcloud:wadm@0.2.0; /// A Wadm client which interacts with the wadm api interface client { @@ -11,7 +11,7 @@ interface client { // Deploys a model to the WADM system. // If no lattice is provided, the default lattice name 'default' is used. - deploy-model: func(model-name: string, version: option, lattice: option) -> result<_, string>; + deploy-model: func(model-name: string, version: option, lattice: option) -> result; // Undeploys a model from the WADM system. undeploy-model: func(model-name: string, lattice: option, non-destructive: bool) -> result<_, string>; diff --git a/wit/wadm/types.wit b/wit/wadm/types.wit index 2125e012..17157d10 100644 --- a/wit/wadm/types.wit +++ b/wit/wadm/types.wit @@ -1,7 +1,6 @@ -package wasmcloud:wadm@0.1.0; +package wasmcloud:wadm@0.2.0; interface types { - record model-summary { name: string, version: string, @@ -99,13 +98,14 @@ interface types { // The specification for this manifest record specification { components: list, + policies: list } // A component definition record component { name: string, properties: properties, - traits: list, + traits: option>, } // Properties that can be defined for a component @@ -119,6 +119,7 @@ interface types { image: string, id: option, config: list, + secrets: list, } // Properties for a capability @@ -126,12 +127,14 @@ interface types { image: string, id: option, config: list, + secrets: list, } - // Properties for the config list associated with components, providers, and links - record config-property { + // A policy definition + record policy { name: string, - properties: option>>, + properties: list>, + %type: string, } // A trait definition @@ -149,15 +152,47 @@ interface types { // Properties for links record link-property { - target: string, namespace: string, %package: string, interfaces: list, - source-config: list, - target-config: list, + source: option, + target: target-config, name: option, } + // Configuration definition + record config-definition { + config: list, + secrets: list, + } + + // Configuration properties + record config-property { + name: string, + properties: option>>, + } + + // Secret properties + record secret-property { + name: string, + properties: secret-source-property, + } + + // Secret source properties + record secret-source-property { + policy: string, + key: string, + field: option, + version: option, + } + + // Target configuration + record target-config { + name: string, + config: list, + secrets: list, + } + // Properties for spread scalers record spreadscaler-property { instances: u32, @@ -170,4 +205,4 @@ interface types { requirements: list>, weight: option, } -} +} \ No newline at end of file From 8efa1c9500a0a69dd860f5b121bc0736860ceb70 Mon Sep 17 00:00:00 2001 From: Brooks Townsend Date: Fri, 2 Aug 2024 10:21:06 -0400 Subject: [PATCH 2/2] ci(test): ensure entire workspace builds Signed-off-by: Brooks Townsend --- .github/workflows/test.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b72a6dc5..5694b4e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,13 +21,12 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: stable - default: true components: clippy, rustfmt # Cache: rust - uses: Swatinem/rust-cache@v2 with: - key: "${{ matrix.os }}-rust-cache" + key: '${{ matrix.os }}-rust-cache' - name: Check that Wadm JSON Schema is up-to-date shell: bash @@ -45,6 +44,10 @@ jobs: - name: Start NATS run: docker run --rm -d --name wadm-test -p 127.0.0.1:4222:4222 nats:${{ matrix.nats_version }} -js + - name: Build + run: | + cargo build --all-features --all-targets --workspace + # Run all tests - name: Run tests run: |