Skip to content

Commit

Permalink
Prefix dataset alias with account name
Browse files Browse the repository at this point in the history
  • Loading branch information
demusdev committed Dec 23, 2024
1 parent 741548d commit c22d5b5
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/e2e/app/cli/inmem/tests/tests/rest_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions src/e2e/app/cli/inmem/tests/tests/rest_api/test_gql_query.rs
Original file line number Diff line number Diff line change
@@ -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
);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1 change: 1 addition & 0 deletions src/e2e/app/cli/postgres/tests/tests/rest_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
29 changes: 29 additions & 0 deletions src/e2e/app/cli/postgres/tests/tests/rest_api/test_gql_query.rs
Original file line number Diff line number Diff line change
@@ -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
);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 changes: 2 additions & 0 deletions src/e2e/app/cli/repo-tests/src/rest_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::*;
Expand Down
131 changes: 131 additions & 0 deletions src/e2e/app/cli/repo-tests/src/rest_api/test_gql_query.rs
Original file line number Diff line number Diff line change
@@ -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;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1 change: 1 addition & 0 deletions src/e2e/app/cli/sqlite/tests/tests/rest_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
29 changes: 29 additions & 0 deletions src/e2e/app/cli/sqlite/tests/tests/rest_api/test_gql_query.rs
Original file line number Diff line number Diff line change
@@ -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
);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
12 changes: 6 additions & 6 deletions src/infra/core/src/repos/dataset_repository_local_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,12 @@ impl DatasetStorageStrategy for DatasetMultiTenantStorageStrategy {
&self,
raw_alias: &DatasetAlias,
) -> Result<DatasetAlias, ResolveDatasetError> {
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);

Check failure on line 907 in src/infra/core/src/repos/dataset_repository_local_fs.rs

View workflow job for this annotation

GitHub Actions / Lint / Code

this expression creates a reference which is immediately dereferenced by the compiler
let (_, canonical_account_name) = self.resolve_account_dir(account_name).int_err()?;
Ok(DatasetAlias::new(
Some(canonical_account_name),
raw_alias.dataset_name.clone(),
))
}
}

Expand Down

0 comments on commit c22d5b5

Please sign in to comment.