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

Fix "admin" role issue with different servers #1423

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/branding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ pub const CONFIG_FILE_DISPLAY_NAME: &str = if cfg!(feature = "gel") {
/// The default query tag for server statistics.
pub const QUERY_TAG: &str = "gel/cli";
pub const REPL_QUERY_TAG: &str = "gel/repl";

/// The default name of the database user bootstrapped in a new instance.
pub const BRANDING_DEFAULT_USERNAME: &str = "admin";
pub const BRANDING_DEFAULT_USERNAME_LEGACY: &str = "edgedb";
20 changes: 13 additions & 7 deletions src/portable/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use fn_error_context::context;

use color_print::cformat;

use crate::branding::{BRANDING, BRANDING_CLI_CMD, BRANDING_CLOUD};
use crate::branding::{
BRANDING, BRANDING_CLI_CMD, BRANDING_CLOUD, BRANDING_DEFAULT_USERNAME,
BRANDING_DEFAULT_USERNAME_LEGACY,
};
use crate::cloud;
use crate::commands::ExitCode;
use crate::credentials;
Expand All @@ -22,13 +25,13 @@ use crate::portable::options::{Create, InstanceName, Start};
use crate::portable::platform::optional_docker_check;
use crate::portable::repository::{Query, QueryOptions};
use crate::portable::reset_password::{generate_password, password_hash};
use crate::portable::ver::Build;
use crate::portable::ver::Specific;
use crate::portable::{linux, macos, windows};
use crate::print::{self, err_marker, msg, Highlight};
use crate::process;
use crate::question;

use crate::portable::project::get_default_branch_name;
use crate::portable::project::{get_default_branch_name, get_default_user_name};
use edgedb_tokio::credentials::Credentials;

fn ask_name(cloud_client: &mut cloud::client::CloudClient) -> anyhow::Result<InstanceName> {
Expand Down Expand Up @@ -171,7 +174,9 @@ pub fn create(cmd: &Create, opts: &crate::options::Options) -> anyhow::Result<()
bootstrap(
&paths,
&info,
&cmd.default_user,
cmd.default_user
.as_deref()
.unwrap_or_else(|| get_default_user_name(specific_version)),
&cmd.default_branch
.clone()
.unwrap_or_else(|| get_default_branch_name(specific_version)),
Expand Down Expand Up @@ -445,10 +450,11 @@ pub fn bootstrap(
let script = bootstrap_script(
user,
&password,
if info.get_version()? >= &Build::from_str("6.0-dev.9024+4b89273").unwrap() {
"admin"
// This is the user included in the server. It changed since 6.0-alpha.2.
if info.get_version()?.specific() >= Specific::from_str("6.0-alpha.2").unwrap() {
BRANDING_DEFAULT_USERNAME
} else {
"edgedb"
BRANDING_DEFAULT_USERNAME_LEGACY
},
);

Expand Down
7 changes: 4 additions & 3 deletions src/portable/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,10 @@ pub struct Create {
pub start_conf: Option<StartConf>,

/// Default user name (created during initialization and saved in
/// credentials file).
#[arg(long, default_value = "admin")]
pub default_user: String,
/// credentials file). This defaults to 'admin' on EdgeDB >=6.x; otherwise
/// 'edgedb' is used.
#[arg(long)]
pub default_user: Option<String>,

/// The default branch name. This defaults to 'main' on EdgeDB >=5.x; otherwise
/// 'edgedb' is used.
Expand Down
14 changes: 12 additions & 2 deletions src/portable/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::branding::QUERY_TAG;
use crate::branding::{
BRANDING, BRANDING_CLI_CMD, BRANDING_SCHEMA_FILE_EXT, CONFIG_FILE_DISPLAY_NAME,
};
use crate::branding::{BRANDING_DEFAULT_USERNAME, BRANDING_DEFAULT_USERNAME_LEGACY};
use crate::cloud;
use crate::cloud::client::CloudClient;
use crate::commands::ExitCode;
Expand Down Expand Up @@ -410,6 +411,14 @@ pub fn get_default_branch_name(version: &Specific) -> String {
String::from("edgedb")
}

pub fn get_default_user_name(version: &Specific) -> &'static str {
if version.major >= 6 {
BRANDING_DEFAULT_USERNAME
} else {
BRANDING_DEFAULT_USERNAME_LEGACY
}
}

pub fn get_default_branch_or_database(version: &Specific, project_dir: &Path) -> String {
if version.major >= 5 {
return String::from("main");
Expand Down Expand Up @@ -818,7 +827,7 @@ fn do_init(
},
port: Some(port),
start_conf: None,
default_user: "edgedb".into(),
default_user: None,
non_interactive: true,
cloud_opts: options.cloud_opts.clone(),
default_branch: Some(database.to_string()),
Expand All @@ -835,12 +844,13 @@ fn do_init(
InstanceKind::Wsl(WslInfo {})
} else {
let inst = install::package(pkg).context(concatcp!("error installing ", BRANDING))?;
let version = inst.version.specific();
let info = InstanceInfo {
name: name.into(),
installation: Some(inst),
port,
};
create::bootstrap(&paths, &info, "admin", database)?;
create::bootstrap(&paths, &info, get_default_user_name(&version), database)?;
match create::create_service(&info) {
Ok(()) => {}
Err(e) => {
Expand Down
Loading