Skip to content

Commit

Permalink
Send connection profile config as json and validate it
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeisen committed Aug 23, 2023
1 parent bee0867 commit 005953f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion arroyo-api/src/connection_profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::handle_db_error;
use crate::queries::api_queries;
use crate::queries::api_queries::DbConnectionProfile;
use crate::rest::AppState;
use crate::rest_utils::{authenticate, client, log_and_map, ApiError, BearerAuth, ErrorResp};
use crate::rest_utils::{
authenticate, bad_request, client, log_and_map, ApiError, BearerAuth, ErrorResp,
};

impl TryFrom<DbConnectionProfile> for ConnectionProfile {
type Error = String;
Expand Down Expand Up @@ -57,6 +59,11 @@ pub async fn create_connection_profile(
let client = client(&state.pool).await.unwrap();
let auth_data = authenticate(&state.pool, bearer_auth).await.unwrap();

connector_for_type(&req.connector)
.ok_or_else(|| bad_request("Unknown connector type".to_string()))?
.validate_config(&req.config)
.map_err(|e| bad_request(format!("Invalid config: {:?}", e)))?;

let pub_id = generate_id(IdTypes::ConnectionProfile);
api_queries::create_connection_profile()
.bind(
Expand Down
3 changes: 2 additions & 1 deletion arroyo-connectors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ impl<C: Connector> ErasedConnector for C {
Ok(self.config_description(self.parse_config(s)?))
}

fn validate_config(&self, _: &serde_json::Value) -> Result<(), serde_json::Error> {
fn validate_config(&self, config: &serde_json::Value) -> Result<(), serde_json::Error> {
self.parse_config(config)?;
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const ClusterEditor = ({
body: {
name: d.name,
connector: connector,
config: JSON.stringify(d),
config: d,
},
});

Expand Down

0 comments on commit 005953f

Please sign in to comment.