gestalt-sdk 0.0.1-alpha.26

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 remote.proto.

use crate::codec::remote::{
    from_wire_list_remotes_response, from_wire_registration_check_response, from_wire_remote,
    to_wire_create_remote_request, to_wire_delete_remote_request, to_wire_list_remotes_request,
    to_wire_registration_check_request,
};
use crate::generated::v1;
use crate::rpc_support::GestaltError;

/// Native message type for `gestalt.provider.v1.CreateRemoteRequest`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateRemoteRequest {
    /// The `tunnel` field; None when unset.
    pub tunnel: Option<TunnelEndpoint>,
    /// The `providers` field.
    pub providers: Vec<RemoteProviderDefinition>,
    /// The `expected_generation` field.
    pub expected_generation: u64,
}

/// Native message type for `gestalt.provider.v1.DeleteRemoteRequest`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DeleteRemoteRequest {
    /// The `id` field.
    pub id: String,
    /// The `expected_generation` field.
    pub expected_generation: u64,
}

/// Native message type for `gestalt.provider.v1.ListRemotesRequest`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ListRemotesRequest {}

/// Native message type for `gestalt.provider.v1.ListRemotesResponse`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ListRemotesResponse {
    /// The `remotes` field.
    pub remotes: Vec<Remote>,
    /// The `server_identity` field; None when unset.
    pub server_identity: Option<ServerIdentity>,
    /// The `tunnel` field; None when unset.
    pub tunnel: Option<TunnelBootstrap>,
    #[serde(with = "crate::serde_duration")]
    /// The `lease_duration` field; None when unset.
    pub lease_duration: Option<std::time::Duration>,
}

/// Native message type for `gestalt.provider.v1.ProviderRef`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProviderRef {
    /// The `kind` field.
    pub kind: String,
    /// The `name` field.
    pub name: String,
}

/// Native message type for `gestalt.provider.v1.RegistrationCheckRequest`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RegistrationCheckRequest {
    /// The `registration_id` field.
    pub registration_id: String,
    /// The `generation` field.
    pub generation: u64,
    /// The `providers` field.
    pub providers: Vec<ProviderRef>,
}

/// Native message type for `gestalt.provider.v1.RegistrationCheckResponse`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RegistrationCheckResponse {
    /// The `ready` field.
    pub ready: bool,
    /// The `message` field.
    pub message: String,
}

/// Native message type for `gestalt.provider.v1.Remote`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Remote {
    /// The `id` field.
    pub id: String,
    /// The `owner_subject_id` field.
    pub owner_subject_id: String,
    /// The `generation` field.
    pub generation: u64,
    /// The `providers` field.
    pub providers: Vec<RemoteProviderSummary>,
    /// The `reachability` field; None when unset.
    pub reachability: Option<RemoteReachability>,
    /// The `server_spki_sha256` field.
    pub server_spki_sha256: String,
    #[serde(with = "crate::serde_time")]
    /// The `created_at` field; None when unset.
    pub created_at: Option<std::time::SystemTime>,
    #[serde(with = "crate::serde_time")]
    /// The `updated_at` field; None when unset.
    pub updated_at: Option<std::time::SystemTime>,
    #[serde(with = "crate::serde_time")]
    /// The `last_checked_at` field; None when unset.
    pub last_checked_at: Option<std::time::SystemTime>,
    #[serde(with = "crate::serde_time")]
    /// The `last_successful_heartbeat_at` field; None when unset.
    pub last_successful_heartbeat_at: Option<std::time::SystemTime>,
    /// The `last_error` field.
    pub last_error: String,
    #[serde(with = "crate::serde_time")]
    /// The `lease_expires_at` field; None when unset.
    pub lease_expires_at: Option<std::time::SystemTime>,
}

/// Native message type for `gestalt.provider.v1.RemoteProviderDefinition`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RemoteProviderDefinition {
    /// The `kind` field.
    pub kind: String,
    /// The `name` field.
    pub name: String,
    /// The `definition` field; None when unset.
    pub definition: Option<serde_json::Map<String, serde_json::Value>>,
}

/// Native message type for `gestalt.provider.v1.RemoteProviderSummary`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RemoteProviderSummary {
    /// The `kind` field.
    pub kind: String,
    /// The `name` field.
    pub name: String,
}

/// Native message type for `gestalt.provider.v1.RemoteReachability`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RemoteReachability {
    /// The `reachable` field.
    pub reachable: bool,
    /// The `message` field.
    pub message: String,
}

/// Native message type for `gestalt.provider.v1.ServerIdentity`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ServerIdentity {
    /// The `client_spki_sha256` field.
    pub client_spki_sha256: String,
}

/// Native message type for `gestalt.provider.v1.TunnelBootstrap`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TunnelBootstrap {
    /// The `frps_address` field.
    pub frps_address: String,
    #[serde(with = "crate::serde_duration")]
    /// The `lease_duration` field; None when unset.
    pub lease_duration: Option<std::time::Duration>,
}

/// Native message type for `gestalt.provider.v1.TunnelEndpoint`.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TunnelEndpoint {
    /// The `host` field.
    pub host: String,
    /// The `certificate` field.
    pub certificate: Vec<u8>,
    /// The `server_spki_sha256` field.
    pub server_spki_sha256: String,
}

/// RegistrationLifecycle is served by local gestaltd over the mutually
/// authenticated tunnel only. Internal, never public: it carries no http or
/// visibility annotations so the publicrpc descriptor scan never exposes it.
///
/// Client for the `gestalt.provider.v1.RegistrationLifecycle` service.
pub struct RegistrationLifecycle {
    inner:
        v1::registration_lifecycle_client::RegistrationLifecycleClient<tonic::transport::Channel>,
    timeout: Option<std::time::Duration>,
}

impl RegistrationLifecycle {
    /// Creates a client over an established channel.
    pub fn new(channel: tonic::transport::Channel) -> Self {
        Self {
            inner: v1::registration_lifecycle_client::RegistrationLifecycleClient::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
    }

    /// Check succeeds only when the exact provider set named in the request is
    /// present and every provider is ready.
    ///
    /// Calls `gestalt.provider.v1.RegistrationLifecycle.Check`.
    pub async fn check(
        &mut self,
        request: RegistrationCheckRequest,
    ) -> Result<RegistrationCheckResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_registration_check_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.check(tonic_request).await?;
        Ok(from_wire_registration_check_response(response.into_inner()))
    }
}

/// RemoteManagement is the public management service for reverse remotes. A
/// developer running `gestaltd serve` calls CreateRemote to publish a provider
/// set to this upstream; ListRemotes and DeleteRemote read and remove it. REST
/// and gRPC dispatch through one implementation.
///
/// Client for the `gestalt.provider.v1.RemoteManagement` service.
pub struct RemoteManagement {
    inner: v1::remote_management_client::RemoteManagementClient<tonic::transport::Channel>,
    timeout: Option<std::time::Duration>,
}

impl RemoteManagement {
    /// Creates a client over an established channel.
    pub fn new(channel: tonic::transport::Channel) -> Self {
        Self {
            inner: v1::remote_management_client::RemoteManagementClient::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.RemoteManagement.CreateRemote`.
    pub async fn create_remote(
        &mut self,
        request: CreateRemoteRequest,
    ) -> Result<Remote, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_create_remote_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.create_remote(tonic_request).await?;
        Ok(from_wire_remote(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.RemoteManagement.ListRemotes`.
    pub async fn list_remotes(
        &mut self,
        request: ListRemotesRequest,
    ) -> Result<ListRemotesResponse, GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_list_remotes_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        let response = self.inner.list_remotes(tonic_request).await?;
        Ok(from_wire_list_remotes_response(response.into_inner()))
    }

    /// Calls `gestalt.provider.v1.RemoteManagement.DeleteRemote`.
    pub async fn delete_remote(
        &mut self,
        request: DeleteRemoteRequest,
    ) -> Result<(), GestaltError> {
        let mut tonic_request = tonic::Request::new(to_wire_delete_remote_request(request));
        if let Some(timeout) = self.timeout {
            tonic_request.set_timeout(timeout);
        }
        self.inner.delete_remote(tonic_request).await?;
        Ok(())
    }
}