Skip to content

Commit

Permalink
Fix review comments - Iter 3
Browse files Browse the repository at this point in the history
  • Loading branch information
rmn-boiko committed Feb 21, 2025
1 parent 2e6536d commit f539c9b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ kamu-task-system-inmem = { git = "https://github.com/kamu-data/kamu-cli", tag =
kamu-task-system-postgres = { git = "https://github.com/kamu-data/kamu-cli", tag = "v0.225.0", version = "0.225.0", default-features = false }
kamu-task-system-sqlite = { git = "https://github.com/kamu-data/kamu-cli", tag = "v0.225.0", version = "0.225.0", default-features = false }

#E2E
# E2E: kamu-cli
kamu-cli-e2e-common = { git = "https://github.com/kamu-data/kamu-cli", tag = "v0.225.0", version = "0.225.0", default-features = false }
kamu-cli-e2e-repo-tests = { git = "https://github.com/kamu-data/kamu-cli", tag = "v0.225.0", version = "0.225.0", default-features = false }

# Workspace E2E
# E2E: kamu-node
kamu-node-e2e-common = { path = "src/e2e/app/common", version = "0.54.3", default-features = false }
kamu-node-e2e-common-macros = { path = "src/e2e/app/common-macros", version = "0.54.3", default-features = false }
kamu-node-puppet = { path = "src/e2e/app/kamu-node-puppet", version = "0.54.3", default-features = false }
Expand Down
8 changes: 0 additions & 8 deletions src/app/api-server/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,6 @@ pub async fn init_dependencies(
b.add_value(kamu_accounts::PredefinedAccountsConfig::default());
}

b.add_value(kamu::domain::ServerUrlConfig::new(
kamu::domain::Protocols {
base_url_platform: config.url.base_url_platform,
base_url_rest: config.url.base_url_rest,
base_url_flightsql: config.url.base_url_flightsql,
},
));

let maybe_jwt_secret = if !config.auth.jwt_secret.is_empty() {
Some(config.auth.jwt_secret)
} else {
Expand Down
30 changes: 21 additions & 9 deletions src/app/api-server/src/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ use std::path::PathBuf;
use std::sync::Arc;

use database_common_macros::transactional_handler;
use dill::CatalogBuilder;
use http_common::ApiError;
use indoc::indoc;
use internal_error::{InternalError, ResultIntoInternal};
use kamu::domain::TenancyConfig;
use kamu::domain::{Protocols, ServerUrlConfig, TenancyConfig};
use kamu_adapter_http::DatasetAuthorizationLayer;
use tokio::sync::Notify;
use utoipa_axum::router::OpenApiRouter;
Expand Down Expand Up @@ -46,6 +47,24 @@ pub async fn build_server(
> {
let gql_schema = kamu_adapter_graphql::schema();

let addr = SocketAddr::from((address, http_port.unwrap_or(0)));
let listener = tokio::net::TcpListener::bind(addr).await.int_err()?;
let local_addr = listener.local_addr().unwrap();

let base_url_rest =
url::Url::parse(&format!("http://{local_addr}")).expect("URL failed to parse");

let default_protocols = Protocols::default();

let api_server_catalog = CatalogBuilder::new_chained(&catalog)
.add_value(ServerUrlConfig::new(Protocols {
base_url_rest: base_url_rest.clone(),
base_url_platform: default_protocols.base_url_platform,
// Note: this is not a valid endpoint in Web UI mode
base_url_flightsql: default_protocols.base_url_flightsql,
}))
.build();

let (mut router, api) = OpenApiRouter::with_openapi(
kamu_adapter_http::openapi::spec_builder(
crate::app::VERSION,
Expand Down Expand Up @@ -134,7 +153,7 @@ pub async fn build_server(
)
.merge(kamu_adapter_http::openapi::router().into())
.layer(axum::extract::Extension(gql_schema))
.layer(axum::extract::Extension(catalog))
.layer(axum::extract::Extension(api_server_catalog))
.layer(axum::extract::Extension(ui_config))
.split_for_parts();

Expand All @@ -153,13 +172,6 @@ pub async fn build_server(

let router = router.layer(axum::extract::Extension(std::sync::Arc::new(api)));

let addr = SocketAddr::from((address, http_port.unwrap_or(0)));
let listener = tokio::net::TcpListener::bind(addr).await.int_err()?;
let local_addr = listener.local_addr().unwrap();

let base_url_rest =
url::Url::parse(&format!("http://{local_addr}")).expect("URL failed to parse");

if let Some(path) = e2e_output_data_path {
std::fs::write(path, base_url_rest.to_string()).unwrap();
};
Expand Down
3 changes: 2 additions & 1 deletion src/app/api-server/tests/tests/test_di_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

use kamu::domain::TenancyConfig;
use kamu::domain::{ServerUrlConfig, TenancyConfig};
use test_utils::MinioServer;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -82,6 +82,7 @@ async fn test_di_graph_validates_remote() {
// CurrentAccountSubject is inserted by middlewares, but won't be present in
// the default dependency graph, so we have to add it manually
catalog_builder.add_value(kamu_accounts::CurrentAccountSubject::new_test());
catalog_builder.add_value(ServerUrlConfig::new_test(None));

catalog_builder.add_value(kamu_adapter_http::AccessToken::new("some-token"));

Expand Down
1 change: 1 addition & 0 deletions src/e2e/app/repo-tests/src/test_dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use kamu_cli_e2e_common::{

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// ToDo reuse this test from kamu-cli once bug in cli will be resolved
pub async fn test_datasets_by_id(mut kamu_api_server_client: KamuApiServerClient) {
let (_, nonexistent_dataset_id) = odf::DatasetID::new_generated_ed25519();

Expand Down
10 changes: 9 additions & 1 deletion src/e2e/app/repo-tests/src/test_flight_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ pub async fn test_flight_sql_self_test(mut kamu_flight_sql_client: KamuFlightSQL
}
"
)),
None,
Some(indoc!(
"
+-------+
| value |
+-------+
| 1 |
+-------+
"
)),
)
.await;
}
Expand Down
6 changes: 3 additions & 3 deletions src/e2e/app/repo-tests/src/test_odata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub async fn test_odata_service_handler(mut kamu_api_server_client: KamuApiServe
indoc::indoc!(
r#"
<?xml version="1.0" encoding="utf-8"?>
<service xml:base="http://localhost:8080/odata"
<service xml:base="<base_url>odata"
xmlns="http://www.w3.org/2007/app"
xmlns:atom="http://www.w3.org/2005/Atom">
<workspace>
Expand All @@ -40,8 +40,8 @@ pub async fn test_odata_service_handler(mut kamu_api_server_client: KamuApiServe
</service>
"#
)
.replace('\n', "") /* .replace("<base_url>",
* kamu_api_server_client.get_base_url().as_str()) */
.replace('\n', "")
.replace("<base_url>", kamu_api_server_client.get_base_url().as_str())
);
}

Expand Down

0 comments on commit f539c9b

Please sign in to comment.