-
Notifications
You must be signed in to change notification settings - Fork 190
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
base: main
Are you sure you want to change the base?
Conversation
22adc16
to
d285baa
Compare
There was a problem hiding this 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
There was a problem hiding this 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.
There was a problem hiding this 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. |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #5463 (comment)
There was a problem hiding this comment.
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?
There was a problem hiding this 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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).
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'sREST
parameters after they invokeTileDB-Cloud-Py::login
upstream. Once a user has created aRestProfile
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. TheTileDB-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 aTemporaryLocalDirectory
as a pseudo-$HOME
. As such, the local files are written to/tmp
during the test and removed at the end of theTEST_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.