From 7740eb8d189cbca1e4737b7e8645700070d48439 Mon Sep 17 00:00:00 2001 From: Andrii Demus Date: Mon, 23 Dec 2024 20:51:31 +0100 Subject: [PATCH] Prefix dataset alias with account name --- CHANGELOG.md | 4 + .../app/cli/inmem/tests/tests/rest_api/mod.rs | 1 + .../tests/tests/rest_api/test_gql_query.rs | 29 ++++ .../cli/postgres/tests/tests/rest_api/mod.rs | 1 + .../tests/tests/rest_api/test_gql_query.rs | 29 ++++ .../app/cli/repo-tests/src/rest_api/mod.rs | 2 + .../repo-tests/src/rest_api/test_gql_query.rs | 131 ++++++++++++++++++ .../cli/sqlite/tests/tests/rest_api/mod.rs | 1 + .../tests/tests/rest_api/test_gql_query.rs | 29 ++++ .../src/repos/dataset_repository_local_fs.rs | 12 +- 10 files changed, 233 insertions(+), 6 deletions(-) create mode 100644 src/e2e/app/cli/inmem/tests/tests/rest_api/test_gql_query.rs create mode 100644 src/e2e/app/cli/postgres/tests/tests/rest_api/test_gql_query.rs create mode 100644 src/e2e/app/cli/repo-tests/src/rest_api/test_gql_query.rs create mode 100644 src/e2e/app/cli/sqlite/tests/tests/rest_api/test_gql_query.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index ec57261bed..c44457300f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ Recommendation: for ease of reading, use the following order: - Fixed --> +## [Unreleased] +### Fixed +- GQL: datasets/createEmpty returns alias prefixed with account name + ## [0.214.0] - 2024-12-23 ### Added - New `kamu system decode` command that can decode an arbitrary block file for debugging diff --git a/src/e2e/app/cli/inmem/tests/tests/rest_api/mod.rs b/src/e2e/app/cli/inmem/tests/tests/rest_api/mod.rs index 873b5847d0..b38aa29ae3 100644 --- a/src/e2e/app/cli/inmem/tests/tests/rest_api/mod.rs +++ b/src/e2e/app/cli/inmem/tests/tests/rest_api/mod.rs @@ -10,6 +10,7 @@ mod test_accounts; mod test_auth; mod test_dataset; +mod test_gql_query; mod test_odf_core; mod test_odf_query; mod test_openapi; diff --git a/src/e2e/app/cli/inmem/tests/tests/rest_api/test_gql_query.rs b/src/e2e/app/cli/inmem/tests/tests/rest_api/test_gql_query.rs new file mode 100644 index 0000000000..915075d4e3 --- /dev/null +++ b/src/e2e/app/cli/inmem/tests/tests/rest_api/test_gql_query.rs @@ -0,0 +1,29 @@ +// Copyright Kamu Data, Inc. and contributors. All rights reserved. +// +// Use of this software is governed by the Business Source License +// included in the LICENSE file. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0. + +use kamu_cli_e2e_common::prelude::*; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +kamu_cli_run_api_server_e2e_test!( + storage = inmem, + fixture = + kamu_cli_e2e_repo_tests::rest_api::test_gql_query_mut_create_empty_returns_correct_alias_mt, + options = Options::default().with_multi_tenant() +); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +kamu_cli_run_api_server_e2e_test!( + storage = inmem, + fixture = + kamu_cli_e2e_repo_tests::rest_api::test_gql_query_mut_create_empty_returns_correct_alias_st +); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/e2e/app/cli/postgres/tests/tests/rest_api/mod.rs b/src/e2e/app/cli/postgres/tests/tests/rest_api/mod.rs index a213d83e83..6fc9185215 100644 --- a/src/e2e/app/cli/postgres/tests/tests/rest_api/mod.rs +++ b/src/e2e/app/cli/postgres/tests/tests/rest_api/mod.rs @@ -10,6 +10,7 @@ mod test_accounts; mod test_auth; mod test_dataset; +mod test_gql_query; mod test_odf_core; mod test_odf_query; mod test_upload; diff --git a/src/e2e/app/cli/postgres/tests/tests/rest_api/test_gql_query.rs b/src/e2e/app/cli/postgres/tests/tests/rest_api/test_gql_query.rs new file mode 100644 index 0000000000..493a118c0c --- /dev/null +++ b/src/e2e/app/cli/postgres/tests/tests/rest_api/test_gql_query.rs @@ -0,0 +1,29 @@ +// Copyright Kamu Data, Inc. and contributors. All rights reserved. +// +// Use of this software is governed by the Business Source License +// included in the LICENSE file. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0. + +use kamu_cli_e2e_common::prelude::*; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +kamu_cli_run_api_server_e2e_test!( + storage = postgres, + fixture = + kamu_cli_e2e_repo_tests::rest_api::test_gql_query_mut_create_empty_returns_correct_alias_mt, + options = Options::default().with_multi_tenant() +); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +kamu_cli_run_api_server_e2e_test!( + storage = postgres, + fixture = + kamu_cli_e2e_repo_tests::rest_api::test_gql_query_mut_create_empty_returns_correct_alias_st +); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/e2e/app/cli/repo-tests/src/rest_api/mod.rs b/src/e2e/app/cli/repo-tests/src/rest_api/mod.rs index 3eb867d407..08bd890a09 100644 --- a/src/e2e/app/cli/repo-tests/src/rest_api/mod.rs +++ b/src/e2e/app/cli/repo-tests/src/rest_api/mod.rs @@ -10,6 +10,7 @@ mod test_accounts; mod test_auth; mod test_dataset; +mod test_gql_query; mod test_odf_core; mod test_odf_query; mod test_openapi; @@ -19,6 +20,7 @@ mod test_upload; pub use test_accounts::*; pub use test_auth::*; pub use test_dataset::*; +pub use test_gql_query::*; pub use test_odf_core::*; pub use test_odf_query::*; pub use test_openapi::*; diff --git a/src/e2e/app/cli/repo-tests/src/rest_api/test_gql_query.rs b/src/e2e/app/cli/repo-tests/src/rest_api/test_gql_query.rs new file mode 100644 index 0000000000..7073ee9351 --- /dev/null +++ b/src/e2e/app/cli/repo-tests/src/rest_api/test_gql_query.rs @@ -0,0 +1,131 @@ +// Copyright Kamu Data, Inc. and contributors. All rights reserved. +// +// Use of this software is governed by the Business Source License +// included in the LICENSE file. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0. + +use kamu_cli_e2e_common::{KamuApiServerClient, KamuApiServerClientExt}; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +pub async fn test_gql_query_mut_create_empty_returns_correct_alias_mt( + mut kamu_api_server_client: KamuApiServerClient, +) { + let token = kamu_api_server_client.auth().login_as_e2e_user().await; + kamu_api_server_client.set_token(Some(token)); + + kamu_api_server_client + .graphql_api_call_assert( + indoc::indoc!( + r#" + mutation { + datasets { + createEmpty(datasetKind: ROOT, datasetAlias: "empty-root-dataset") { + message + ... on CreateDatasetResultSuccess { + dataset { + alias + owner { + accountName + } + } + } + } + } + } + "#, + ), + Ok(indoc::indoc!( + r#" + { + "datasets": { + "createEmpty": { + "dataset": { + "alias": "e2e-user/empty-root-dataset", + "owner": { + "accountName": "e2e-user" + } + }, + "message": "Success" + } + } + } + "#, + )), + ) + .await; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +pub async fn test_gql_query_mut_create_empty_returns_correct_alias_st( + mut kamu_api_server_client: KamuApiServerClient, +) { + let login_response = kamu_api_server_client + .graphql_api_call(indoc::indoc!( + r#" + mutation { + auth { + login(loginMethod: "password", loginCredentialsJson: "{\"login\":\"kamu\",\"password\":\"kamu\"}") { + accessToken, + account { + id + } + } + } + } + "#, + )) + .await; + let token = login_response["auth"]["login"]["accessToken"] + .as_str() + .map(ToOwned::to_owned) + .unwrap(); + kamu_api_server_client.set_token(Some(token)); + + kamu_api_server_client + .graphql_api_call_assert( + indoc::indoc!( + r#" + mutation { + datasets { + createEmpty(datasetKind: ROOT, datasetAlias: "empty-root-dataset") { + message + ... on CreateDatasetResultSuccess { + dataset { + alias + owner { + accountName + } + } + } + } + } + } + "#, + ), + Ok(indoc::indoc!( + r#" + { + "datasets": { + "createEmpty": { + "dataset": { + "alias": "empty-root-dataset", + "owner": { + "accountName": "kamu" + } + }, + "message": "Success" + } + } + } + "#, + )), + ) + .await; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/e2e/app/cli/sqlite/tests/tests/rest_api/mod.rs b/src/e2e/app/cli/sqlite/tests/tests/rest_api/mod.rs index a213d83e83..6fc9185215 100644 --- a/src/e2e/app/cli/sqlite/tests/tests/rest_api/mod.rs +++ b/src/e2e/app/cli/sqlite/tests/tests/rest_api/mod.rs @@ -10,6 +10,7 @@ mod test_accounts; mod test_auth; mod test_dataset; +mod test_gql_query; mod test_odf_core; mod test_odf_query; mod test_upload; diff --git a/src/e2e/app/cli/sqlite/tests/tests/rest_api/test_gql_query.rs b/src/e2e/app/cli/sqlite/tests/tests/rest_api/test_gql_query.rs new file mode 100644 index 0000000000..083bd1ecef --- /dev/null +++ b/src/e2e/app/cli/sqlite/tests/tests/rest_api/test_gql_query.rs @@ -0,0 +1,29 @@ +// Copyright Kamu Data, Inc. and contributors. All rights reserved. +// +// Use of this software is governed by the Business Source License +// included in the LICENSE file. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0. + +use kamu_cli_e2e_common::prelude::*; + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +kamu_cli_run_api_server_e2e_test!( + storage = sqlite, + fixture = + kamu_cli_e2e_repo_tests::rest_api::test_gql_query_mut_create_empty_returns_correct_alias_mt, + options = Options::default().with_multi_tenant() +); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +kamu_cli_run_api_server_e2e_test!( + storage = sqlite, + fixture = + kamu_cli_e2e_repo_tests::rest_api::test_gql_query_mut_create_empty_returns_correct_alias_st +); + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/infra/core/src/repos/dataset_repository_local_fs.rs b/src/infra/core/src/repos/dataset_repository_local_fs.rs index 7ac5f0489a..3bac99d54b 100644 --- a/src/infra/core/src/repos/dataset_repository_local_fs.rs +++ b/src/infra/core/src/repos/dataset_repository_local_fs.rs @@ -904,12 +904,12 @@ impl DatasetStorageStrategy for DatasetMultiTenantStorageStrategy { &self, raw_alias: &DatasetAlias, ) -> Result { - Ok(if let Some(account_name) = &raw_alias.account_name { - let (_, canonical_account_name) = self.resolve_account_dir(account_name).int_err()?; - DatasetAlias::new(Some(canonical_account_name), raw_alias.dataset_name.clone()) - } else { - raw_alias.clone() - }) + let account_name = self.effective_account_name(raw_alias); + let (_, canonical_account_name) = self.resolve_account_dir(account_name).int_err()?; + Ok(DatasetAlias::new( + Some(canonical_account_name), + raw_alias.dataset_name.clone(), + )) } }