Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add region_routing in validate_raw_configuration #39

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion rust-connector-sdk/src/connector.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_trait::async_trait;
use ndc_client::models;
use serde::Serialize;
use std::error::Error;
use std::{collections::BTreeMap, error::Error};
use thiserror::Error;
pub mod example;

Expand Down Expand Up @@ -189,6 +189,10 @@ pub trait Connector {
/// The type of unserializable state
type State;

fn get_read_regions(config: &Self::Configuration) -> Vec<String>;

fn get_write_regions(config: &Self::Configuration) -> Vec<String>;

fn make_empty_configuration() -> Self::RawConfiguration;

async fn update_configuration(
Expand All @@ -199,6 +203,7 @@ pub trait Connector {
/// returning a configuration error or a validated [`Connector::Configuration`].
async fn validate_raw_configuration(
configuration: &Self::RawConfiguration,
region_routing: &BTreeMap<String, Vec<String>>,
) -> Result<Self::Configuration, ValidateError>;

/// Initialize the connector's in-memory state.
Expand Down
9 changes: 9 additions & 0 deletions rust-connector-sdk/src/connector/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ impl Connector for Example {

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

fn get_read_regions(_config: &Self::Configuration) -> Vec<String> {
Vec::new()
}

fn get_write_regions(_config: &Self::Configuration) -> Vec<String> {
Vec::new()
}

async fn update_configuration(
_config: &Self::RawConfiguration,
) -> Result<Self::RawConfiguration, UpdateConfigurationError> {
Expand All @@ -25,6 +33,7 @@ impl Connector for Example {

async fn validate_raw_configuration(
_configuration: &Self::Configuration,
_region_routing: &BTreeMap<String, Vec<String>>,
) -> Result<Self::Configuration, ValidateError> {
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions rust-connector-sdk/src/default_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use opentelemetry_sdk::trace::Sampler;
use prometheus::Registry;
use schemars::{schema::RootSchema, JsonSchema};
use serde::{de::DeserializeOwned, Serialize};
use std::error::Error;
use std::net;
use std::{collections::BTreeMap, error::Error};
use std::{env, process::exit};
use tower_http::{
cors::CorsLayer,
Expand Down Expand Up @@ -291,7 +291,7 @@ where
let configuration_json = std::fs::read_to_string(config_file).unwrap();
let raw_configuration =
serde_json::de::from_str::<C::RawConfiguration>(configuration_json.as_str()).unwrap();
let configuration = C::validate_raw_configuration(&raw_configuration)
let configuration = C::validate_raw_configuration(&raw_configuration, &BTreeMap::default())
.await
.unwrap();

Expand Down Expand Up @@ -464,7 +464,7 @@ async fn post_validate<C: Connector>(
where
C::RawConfiguration: DeserializeOwned,
{
let configuration = C::validate_raw_configuration(&configuration)
let configuration = C::validate_raw_configuration(&configuration, &BTreeMap::default())
.await
.map_err(|e| match e {
crate::connector::ValidateError::ValidateError(ranges) => (
Expand Down Expand Up @@ -527,7 +527,7 @@ where
let configuration_json = std::fs::read_to_string(command.configuration).unwrap();
let raw_configuration =
serde_json::de::from_str::<C::RawConfiguration>(configuration_json.as_str()).unwrap();
let configuration = C::validate_raw_configuration(&raw_configuration)
let configuration = C::validate_raw_configuration(&raw_configuration, &BTreeMap::default())
.await
.unwrap();

Expand Down