-
Notifications
You must be signed in to change notification settings - Fork 1
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
Allow unauthenticated users to connect to an instance #19
Changes from 4 commits
d9348e6
a2ffa14
77001b8
e5a560e
9c6d957
d17960a
3c984ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#' @title UserSettings | ||
#' | ||
#' @noRd | ||
#' | ||
#' @description | ||
#' Settings for a Lamin user. These settings are retrieved from the | ||
#' Lamin Hub API and are used to connect to the user. | ||
UserSettings <- R6::R6Class( # nolint object_name_linter | ||
"UserSettings", | ||
cloneable = FALSE, | ||
public = list( | ||
#' @param settings A named list of settings for the user | ||
initialize = function(settings) { | ||
expected_columns <- c( | ||
"email", | ||
"password", | ||
"access_token", | ||
"api_key", | ||
"uid", | ||
"uuid", | ||
"handle", | ||
"name" | ||
) | ||
missing_column <- setdiff(expected_columns, names(settings)) | ||
if (length(missing_column) > 0) { | ||
cli_abort("Missing column: ", missing_column) | ||
} | ||
unexpected_columns <- setdiff(names(settings), expected_columns) | ||
if (length(unexpected_columns) > 0) { | ||
cli_abort("Unexpected column: ", unexpected_columns) | ||
} | ||
private$.settings <- settings | ||
} | ||
), | ||
private = list( | ||
.settings = NULL | ||
), | ||
active = list( | ||
# Get the email of the user. | ||
email = function() { | ||
private$.settings$email | ||
}, | ||
# Get the password of the user. | ||
password = function() { | ||
private$.settings$password | ||
}, | ||
# Get the access token of the user. | ||
access_token = function() { | ||
private$.settings$access_token | ||
}, | ||
# Get the API key of the user. | ||
api_key = function() { | ||
private$.settings$api_key | ||
}, | ||
# Get the UID of the user. | ||
uid = function() { | ||
private$.settings$uid | ||
}, | ||
# Get the UUID of the user. | ||
uuid = function() { | ||
private$.settings$uuid | ||
}, | ||
# Get the handle of the user. | ||
handle = function() { | ||
private$.settings$handle | ||
}, | ||
# Get the name of the user. | ||
name = function() { | ||
private$.settings$name | ||
} | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,20 +20,64 @@ | |
#' instance | ||
#' } | ||
connect <- function(slug = NULL) { | ||
user_settings <- .settings_load__load_or_create_user_settings() | ||
instance_settings <- | ||
if (is.null(slug)) { | ||
# if the slug is null, see if we can load the default instance | ||
instance_file <- .settings_store__current_instance_settings_file() | ||
|
||
if (is.null(slug)) { | ||
current_instance <- .settings_load__load_instance_settings() | ||
slug <- paste0(current_instance$owner, "/", current_instance$name) | ||
} | ||
if (file.exists(instance_file)) { | ||
.settings_load__load_instance_settings(instance_file) | ||
} else { | ||
cli_abort( | ||
paste0( | ||
"Could not load default instance. Either:\n", | ||
" - Provide a slug. For example: `connect(\"laminlabs/cellxgene\")`)\n", | ||
" - Set a default instance by running `lamin load <slug>`." | ||
) | ||
) | ||
} | ||
} else { | ||
# if the slug is not null, try to load the instance from the local settings | ||
owner_name <- .connect_get_owner_name_from_identifier(slug) | ||
|
||
owner_name <- .connect_get_owner_name_from_identifier(slug) | ||
instance_file <- .settings_store__instance_settings_file( | ||
name = owner_name$name, | ||
owner = owner_name$owner | ||
) | ||
|
||
instance_settings <- .connect_get_instance_settings( | ||
owner = owner_name$owner, | ||
name = owner_name$name, | ||
access_token = user_settings$access_token | ||
) | ||
if (file.exists(instance_file)) { | ||
.settings_load__load_instance_settings(instance_file) | ||
} else { | ||
# try to load the user settings from the api | ||
user_file <- .settings_store__current_user_settings_file() | ||
|
||
if (!file.exists(user_file)) { | ||
cli_abort(paste0( | ||
"No default user or instance is loaded! Either:\n", | ||
" - Call `lamin login` to set a default user.\n", | ||
" - Call `lamin load <slug>` to set a default instance.\n" | ||
)) | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be combined with the similar chunk above? Possibly the logic is easier this way though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes -- and indeed! |
||
user_settings <- .settings_load__load_user_settings(user_file) | ||
|
||
.connect_get_instance_settings( | ||
owner = owner_name$owner, | ||
name = owner_name$name, | ||
access_token = user_settings$access_token | ||
) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the instance settings file does not exist, we could try running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now I would probably leave the setup stuff to the command line, just for easiness. If Python lets you do this then maybe it would be nice to add later. |
||
} | ||
|
||
for (required_field in c("id", "api_url", "schema_id")) { | ||
if (is.null(instance_settings[[required_field]])) { | ||
cli_abort(paste0( | ||
"Invalid instance settings: missing field '", required_field, "'\n", | ||
"Your instance settings file is likely outdated. Please update lamin-cli,\n", | ||
"delete the instance settings file, and reload the instance." | ||
)) | ||
} | ||
} | ||
|
||
create_instance(instance_settings = instance_settings) | ||
} | ||
|
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.
Would it be clearer to call these "settings" or something rather than columns?
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.
good point -- done!