Skip to content

Commit

Permalink
Update SDK for new deployment spec (#97)
Browse files Browse the repository at this point in the history
- Use new environment variable names and defaults
- Remove configuration server
- Pass `PathBuf` to `validate_raw_configuration` and remove `RawConfiguration`
- Update `Dockerfile` to meet the deployment spec

Co-authored-by: Samir Talwar <[email protected]>
  • Loading branch information
paf31 and SamirTalwar authored Feb 16, 2024
1 parent ee52bae commit 660750a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 312 deletions.
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ COPY ./rust-connector-sdk .
RUN cargo build --release

FROM debian:buster-slim as connector
RUN set -ex; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
libssl-dev
COPY --from=build /app/target/release/ndc_hub_example ./ndc_hub_example
ENTRYPOINT [ "/ndc_hub_example" ]
CMD [ "serve", "--port", "8080" ]
CMD [ "serve", "--configuration", "/etc/connector" ]
24 changes: 3 additions & 21 deletions rust-connector-sdk/src/connector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::error::Error;
use std::{error::Error, path::Path};

use async_trait::async_trait;
use ndc_client::models;
Expand Down Expand Up @@ -32,16 +32,6 @@ pub enum KeyOrIndex {
Index(u32),
}

/// Errors which occur when trying to validate connector
/// configuration.
///
/// See [`Connector::update_configuration`].
#[derive(Debug, Error)]
pub enum UpdateConfigurationError {
#[error("error validating configuration: {0}")]
Other(#[from] Box<dyn Error + Send + Sync>),
}

/// Errors which occur when trying to initialize connector
/// state.
///
Expand Down Expand Up @@ -201,23 +191,15 @@ pub enum MutationError {
/// connection string would be state.
#[async_trait]
pub trait Connector {
/// The type of unvalidated, raw configuration, as provided by the user.
type RawConfiguration: Sync + Send;
/// The type of validated configuration
type Configuration: Sync + Send;
/// The type of unserializable state
type State: Sync + Send;

fn make_empty_configuration() -> Self::RawConfiguration;

async fn update_configuration(
config: Self::RawConfiguration,
) -> Result<Self::RawConfiguration, UpdateConfigurationError>;

/// Validate the raw configuration provided by the user,
/// returning a configuration error or a validated [`Connector::Configuration`].
async fn validate_raw_configuration(
configuration: Self::RawConfiguration,
async fn parse_configuration(
configuration_dir: impl AsRef<Path> + Send,
) -> Result<Self::Configuration, ValidateError>;

/// Initialize the connector's in-memory state.
Expand Down
13 changes: 2 additions & 11 deletions rust-connector-sdk/src/connector/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,11 @@ pub struct Example {}

#[async_trait]
impl Connector for Example {
type RawConfiguration = ();
type Configuration = ();
type State = ();

fn make_empty_configuration() -> Self::RawConfiguration {}

async fn update_configuration(
_config: Self::RawConfiguration,
) -> Result<Self::RawConfiguration, UpdateConfigurationError> {
Ok(())
}

async fn validate_raw_configuration(
_configuration: Self::Configuration,
async fn parse_configuration(
_configuration_dir: impl AsRef<Path> + Send,
) -> Result<Self::Configuration, ValidateError> {
Ok(())
}
Expand Down
Loading

0 comments on commit 660750a

Please sign in to comment.