Skip to content

Commit

Permalink
Delete the v2 compatibility routes. (#116)
Browse files Browse the repository at this point in the history
It seems that no one is using these any more.
  • Loading branch information
SamirTalwar authored Mar 11, 2024
1 parent 4cb500e commit de1ad71
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 1,267 deletions.
2 changes: 0 additions & 2 deletions rust-connector-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ ndc-test = ["dep:ndc-test"]
default = ["ndc-test"]

[dependencies]
gdc_rust_types = { git = "https://github.com/hasura/gdc_rust_types.git", rev = "3273434" }
ndc-client = { git = "http://github.com/hasura/ndc-spec.git", tag = "v0.1.0" }
ndc-test = { git = "http://github.com/hasura/ndc-spec.git", tag = "v0.1.0", optional = true }

Expand All @@ -26,7 +25,6 @@ axum-extra = "^0.8.0"
bytes = "1.5.0"
clap = { version = "^4.4.7", features = ["derive", "env"] }
http = "^0.2"
indexmap = "2"
mime = "0.3.17"
opentelemetry = { version = "^0.20", default-features = false, features = ["rt-tokio", "trace"] }
opentelemetry-http = "0.9.0"
Expand Down
89 changes: 0 additions & 89 deletions rust-connector-sdk/src/default_main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod v2_compat;

use std::error::Error;
use std::net;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -235,13 +233,6 @@ where
serve_command.service_token_secret.clone(),
);

let router = if serve_command.enable_v2_compatibility {
let v2_router = create_v2_router(server_state, serve_command.service_token_secret.clone());
Router::new().merge(router).nest("/v2", v2_router)
} else {
router
};

let port = serve_command.port;
let address = net::SocketAddr::new(net::IpAddr::V4(net::Ipv4Addr::UNSPECIFIED), port);

Expand Down Expand Up @@ -372,86 +363,6 @@ where
))
}

pub fn create_v2_router<C>(state: ServerState<C>, service_token_secret: Option<String>) -> Router
where
C: Connector + 'static,
C::Configuration: Clone,
C::State: Clone,
{
Router::new()
.route("/schema", post(v2_compat::post_schema::<C>))
.route("/query", post(v2_compat::post_query::<C>))
// .route("/mutation", post(v2_compat::post_mutation::<C>))
// .route("/raw", post(v2_compat::post_raw::<C>))
.route("/query/explain", post(v2_compat::post_explain::<C>))
.layer(
TraceLayer::new_for_http()
.make_span_with(make_span)
.on_response(on_response),
)
.layer(ValidateRequestHeaderLayer::custom(
move |request: &mut Request<Body>| {
let provided_service_token_secret = request
.headers()
.get("x-hasura-dataconnector-config")
.and_then(|config_header| {
serde_json::from_slice::<v2_compat::SourceConfig>(config_header.as_bytes())
.ok()
})
.and_then(|config| config.service_token_secret);

if service_token_secret == provided_service_token_secret {
// if token set & config header present & values match
// or token not set & config header not set/does not have value for token key
// allow request
Ok(())
} else {
// all other cases, block request
let message = "Service Token Secret does not match.".to_string();

tracing::error!(
meta.signal_type = "log",
event.domain = "ndc",
event.name = "Authorization error",
name = "Authorization error",
body = message,
error = true,
);
Err((
StatusCode::UNAUTHORIZED,
Json(ErrorResponse {
message: "Internal error".into(),
details: serde_json::Value::Object(serde_json::Map::from_iter([(
"cause".into(),
serde_json::Value::String(message),
)])),
}),
)
.into_response())
}
},
))
// capabilities and health endpoints are exempt from auth requirements
.route("/capabilities", get(v2_compat::get_capabilities::<C>))
.route("/health", get(v2_compat::get_health))
.layer(
TraceLayer::new_for_http()
.make_span_with(make_span)
.on_response(on_response)
.on_failure(|err, _dur, _span: &_| {
tracing::error!(
meta.signal_type = "log",
event.domain = "ndc",
event.name = "Request failure",
name = "Request failure",
body = %err,
error = true,
);
}),
)
.with_state(state)
}

async fn get_metrics<C: Connector>(
State(state): State<ServerState<C>>,
) -> Result<String, (StatusCode, Json<ErrorResponse>)> {
Expand Down
Loading

0 comments on commit de1ad71

Please sign in to comment.