gestalt-sdk 0.0.1-alpha.19

Rust SDK scaffolding and generated protocol bindings for Gestalt executable providers
Documentation
// Code generated by sdkgen. DO NOT EDIT.

//! Generated native types and clients for runtime.proto.

use crate::codec::runtime::{
    from_wire_configure_provider_response, from_wire_health_check_response,
    from_wire_provider_identity, from_wire_start_runtime_provider_response,
    to_wire_configure_provider_request,
};
use crate::generated::v1;
use crate::rpc_support::GestaltError;

/// Open enum for `gestalt.provider.v1.ProviderKind`; unknown numeric values are preserved.
pub type ProviderKind = i32;

/// Named values of `ProviderKind`.
pub mod provider_kind {
    /// PROVIDER_KIND_UNSPECIFIED.
    pub const PROVIDER_KIND_UNSPECIFIED: i32 = 0;
    /// PROVIDER_KIND_APP.
    pub const PROVIDER_KIND_APP: i32 = 1;
    /// PROVIDER_KIND_AUTHENTICATION.
    pub const PROVIDER_KIND_AUTHENTICATION: i32 = 2;
    /// PROVIDER_KIND_INDEXEDDB.
    pub const PROVIDER_KIND_INDEXEDDB: i32 = 3;
    /// PROVIDER_KIND_SECRETS.
    pub const PROVIDER_KIND_SECRETS: i32 = 4;
    /// PROVIDER_KIND_TELEMETRY.
    pub const PROVIDER_KIND_TELEMETRY: i32 = 5;
    /// PROVIDER_KIND_CACHE.
    pub const PROVIDER_KIND_CACHE: i32 = 6;
    /// PROVIDER_KIND_S3.
    pub const PROVIDER_KIND_S3: i32 = 7;
    /// PROVIDER_KIND_WORKFLOW.
    pub const PROVIDER_KIND_WORKFLOW: i32 = 8;
    /// PROVIDER_KIND_AUTHORIZATION.
    pub const PROVIDER_KIND_AUTHORIZATION: i32 = 9;
    /// PROVIDER_KIND_RUNTIME.
    pub const PROVIDER_KIND_RUNTIME: i32 = 10;
    /// PROVIDER_KIND_AGENT.
    pub const PROVIDER_KIND_AGENT: i32 = 11;
    /// PROVIDER_KIND_EXTERNAL_CREDENTIAL.
    pub const PROVIDER_KIND_EXTERNAL_CREDENTIAL: i32 = 12;
    /// PROVIDER_KIND_TEST.
    pub const PROVIDER_KIND_TEST: i32 = 13;
}

/// ConfigureProviderRequest configures a non-integration provider for one
/// runtime session.
///
/// Native message type for `gestalt.provider.v1.ConfigureProviderRequest`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ConfigureProviderRequest {
    /// The `name` field.
    pub name: String,
    /// The `config` field; None when unset.
    pub config: Option<serde_json::Map<String, serde_json::Value>>,
    /// The `protocol_version` field.
    pub protocol_version: i32,
}

/// ConfigureProviderResponse confirms the protocol version the provider is
/// serving.
///
/// Native message type for `gestalt.provider.v1.ConfigureProviderResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ConfigureProviderResponse {
    /// The `protocol_version` field.
    pub protocol_version: i32,
}

/// HealthCheckResponse reports runtime readiness for a provider surface.
///
/// Native message type for `gestalt.provider.v1.HealthCheckResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct HealthCheckResponse {
    /// The `ready` field.
    pub ready: bool,
    /// The `message` field.
    pub message: String,
}

/// ProviderIdentity describes a provider surface and the protocol versions it
/// supports.
///
/// Native message type for `gestalt.provider.v1.ProviderIdentity`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ProviderIdentity {
    /// The `kind` field.
    pub kind: ProviderKind,
    /// The `name` field.
    pub name: String,
    /// The `display_name` field.
    pub display_name: String,
    /// The `description` field.
    pub description: String,
    /// The `version` field.
    pub version: String,
    /// The `warnings` field.
    pub warnings: Vec<String>,
    /// The `min_protocol_version` field.
    pub min_protocol_version: i32,
    /// The `max_protocol_version` field.
    pub max_protocol_version: i32,
}

/// StartRuntimeProviderResponse confirms the protocol version the provider is
/// serving after the optional runtime start phase.
///
/// Native message type for `gestalt.provider.v1.StartRuntimeProviderResponse`.
#[derive(Clone, Debug, Default, PartialEq)]
pub struct StartRuntimeProviderResponse {
    /// The `protocol_version` field.
    pub protocol_version: i32,
}

/// ProviderLifecycle is the common lifecycle protocol shared by every provider
/// kind.
///
/// Client for the `gestalt.provider.v1.ProviderLifecycle` service.
pub struct ProviderLifecycle {
    inner: v1::provider_lifecycle_client::ProviderLifecycleClient<tonic::transport::Channel>,
    timeout: Option<std::time::Duration>,
}

impl ProviderLifecycle {
    /// Creates a client over an established channel.
    pub fn new(channel: tonic::transport::Channel) -> Self {
        Self {
            inner: v1::provider_lifecycle_client::ProviderLifecycleClient::new(channel),
            timeout: None,
        }
    }

    /// Sets a deadline applied to every unary call; calls that run past it
    /// fail with DEADLINE_EXCEEDED. Streaming calls are unaffected.
    pub fn with_timeout(mut self, timeout: std::time::Duration) -> Self {
        self.timeout = Some(timeout);
        self
    }

    /// Calls `gestalt.provider.v1.ProviderLifecycle.GetProviderIdentity`.
    pub async fn get_provider_identity(&mut self) -> Result<ProviderIdentity, GestaltError> {
        let mut tonic_request = tonic::Request::new(());
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.get_provider_identity(tonic_request).await?;
        Ok(from_wire_provider_identity(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.ProviderLifecycle.ConfigureProvider`.
    pub async fn configure_provider(
        &mut self,
        name: String,
        protocol_version: i32,
        config: Option<serde_json::Map<String, serde_json::Value>>,
    ) -> Result<i32, GestaltError> {
        let request = ConfigureProviderRequest {
            name,
            protocol_version,
            config,
        };
        let mut tonic_request = tonic::Request::new(to_wire_configure_provider_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = from_wire_configure_provider_response(
            self.inner
                .configure_provider(tonic_request)
                .await?
                .into_inner(),
        );
        Ok(response.protocol_version)
    }

    /// Calls `gestalt.provider.v1.ProviderLifecycle.ConfigureProvider` with the full request and response messages.
    pub async fn configure_provider_raw(
        &mut self,
        request: ConfigureProviderRequest,
    ) -> Result<ConfigureProviderResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_configure_provider_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.configure_provider(tonic_request).await?;
        Ok(from_wire_configure_provider_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.ProviderLifecycle.HealthCheck`.
    pub async fn health_check(&mut self) -> Result<HealthCheckResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(());
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.health_check(tonic_request).await?;
        Ok(from_wire_health_check_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.ProviderLifecycle.StartProvider`.
    pub async fn start_provider(&mut self) -> Result<i32, GestaltError> {
        let mut tonic_request = tonic::Request::new(());
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = from_wire_start_runtime_provider_response(
            self.inner.start_provider(tonic_request).await?.into_inner(),
        );
        Ok(response.protocol_version)
    }

    /// Calls `gestalt.provider.v1.ProviderLifecycle.StartProvider` with the full request and response messages.
    pub async fn start_provider_raw(
        &mut self,
    ) -> Result<StartRuntimeProviderResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(());
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.start_provider(tonic_request).await?;
        Ok(from_wire_start_runtime_provider_response(
            response.into_inner(),
        ))
    }
}