Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add class RestProfile for local maintenance of users' REST parameters. #5463

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

bekadavis9
Copy link
Contributor

@bekadavis9 bekadavis9 commented Feb 19, 2025

Add class RestProfile for local maintenance of users' REST parameters.

class RestProfile is the first step toward configuration unification. This internal API stores a user's REST parameters after they invoke TileDB-Cloud-Py::login upstream. Once a user has created a RestProfile and set their desired parameters, RestProfile::save() will serialize the entire profile onto the local, on-disk file, $HOME/.tiledb/profiles.json.

Previously, the upstream API would save users' REST credentials to a different local file, $HOME/.tiledb/cloud.json. To maintain backward compatibility, RestProfile will search for that file and inherit the parameters within, saving them to the new local file, $HOME/.tiledb/profiles.json. Going forward, we expect users to interact only with the latter of the local files. The TileDB-Cloud-Py API will be updated to reflect this change.

A RestProfile default-initializes its parameter-value mapping, and is therefore complete for saving upon creation. Attempting to create multiple profiles of the same name will overwrite the local file with the latest data. Neither local file should be changed by the unit tests, so the test wrapper uses a TemporaryLocalDirectory as a pseudo-$HOME. As such, the local files are written to /tmp during the test and removed at the end of the TEST_CASE.

A followup PR will make use of this class in class Config.

[sc-62705]


TYPE: NO_HISTORY
DESC: Add class RestProfile for local maintenance of users' REST parameters.

Copy link
Member

@ypatia ypatia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments to begin with, I am reviewing actively so I'll be probably posting more

Copy link
Member

@ypatia ypatia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a concern around atomicity that we'd need to re-work. But keep me honest if I have misunderstood something.

@kounelisagis kounelisagis self-requested a review February 27, 2025 00:48
Copy link
Contributor

@davisp davisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some notes around file update semantics.


// If the file is outdated, throw an error. This behavior will evolve.
if (data["version"] < version_) {
throw RestProfileException(
"The version of your local profile.json file is out of date.");
}

// If a profile of the given name already exists, remove it.
// RestProfiles are immutable, so disallow overwrites.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why throw and not replace the profile? Immutable doesn't always mean "cannot change", it also means "you can change parts of it by replacing the whole".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a matter of UX requirement. I don't have a strong opinion, I just thought we are protecting against accidental overwrites in this way.

@ihnorton what is your "product" requirement on this: If a user is trying to set a profile with the same username as an existing one, do we just replace the existing one, or do we return an error message asking the user to delete the profile and add again?

Copy link
Member

@ypatia ypatia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some NITs on my side, otherwise looks good. I will approve once the couple of open questions to reviewers are answered.


// If the file is outdated, throw an error. This behavior will evolve.
if (data["version"] < version_) {
throw RestProfileException(
"The version of your local profile.json file is out of date.");
}

// If a profile of the given name already exists, remove it.
// RestProfiles are immutable, so disallow overwrites.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a matter of UX requirement. I don't have a strong opinion, I just thought we are protecting against accidental overwrites in this way.

@ihnorton what is your "product" requirement on this: If a user is trying to set a profile with the same username as an existing one, do we just replace the existing one, or do we return an error message asking the user to delete the profile and add again?

Copy link
Contributor

@davisp davisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. There's just the two minor tweaks to remove the rename on read and then always rename on write.

, filepath_(homedir + constants::rest_profile_filepath)
, old_filepath_(homedir + constants::cloud_profile_filepath) {
// Fstream cannot create directories. If `homedir/.tiledb/` DNE, create it.
std::filesystem::create_directories(homedir + ".tiledb");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that homedir is a string, I'm not sure how we're ensuring that it ends with a trailing path separator (i.e., / on *nix, vs \ on Windows).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants