Skip to content

Commit

Permalink
Fix credentials reading (#312)
Browse files Browse the repository at this point in the history
When we read database="edgedb" from crednetials.json, we now assume
that branch="__default__" and not "edgedb".

Behavior before was breaking when we linked a new instance without
specifing a database or branch. It would write just "edgedb" into crednetials.
  • Loading branch information
aljazerzen authored Apr 10, 2024
1 parent 116d8aa commit cf5043a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
19 changes: 15 additions & 4 deletions edgedb-tokio/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ impl<'a> DsnHelper<'a> {
});
self.retrieve_value("branch", v, |s| {
let s = s.strip_prefix('/').unwrap_or(&s);
dbg!("here");
validate_branch(&s)?;
Ok(s.to_owned())
}).await
Expand Down Expand Up @@ -703,7 +702,6 @@ impl Builder {

/// Set the branch name.
pub fn branch(&mut self, branch: &str) -> Result<&mut Self, Error> {
dbg!("here");
validate_branch(branch)?;
self.branch = Some(branch.into());
Ok(self)
Expand Down Expand Up @@ -1735,6 +1733,11 @@ impl Config {
&self.0.database
}

/// Database branch name
pub fn branch(&self) -> &str {
&self.0.branch
}

/// Extract credentials from the [Builder] so they can be saved as JSON.
pub fn as_credentials(&self) -> Result<Credentials, Error> {
let (host, port) = match &self.0.address {
Expand All @@ -1745,13 +1748,21 @@ impl Config {
be saved as credentials file"));
}
};

let branch = Some(&self.0.branch)
.filter(|x| x.as_str() != "__default__");

Ok(Credentials {
host: Some(host.clone()),
port: *port,
user: self.0.user.clone(),
password: self.0.password.clone(),
database: if self.0.branch == "__default__" { Some(self.0.database.clone()) } else { None },
branch: if self.0.branch == "__default__" { None } else { Some(self.0.branch.clone()) },
branch: branch.cloned(),

// this is not strictly needed (it gets overwritten when reading),
// but we want to keep backward compatibility. If you downgrade CLI,
// we want it to be able to interact with the new format of credentials.
database: branch.cloned(),
tls_ca: self.0.pem_certificates.clone(),
tls_security: self.0.tls_security,
file_outdated: false,
Expand Down
1 change: 0 additions & 1 deletion edgedb-tokio/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ impl Client {
let data = match res {
Ok(data) => data,
Err(e) => {
dbg!(&e, e.has_tag(SHOULD_RETRY));
if desc.capabilities == Capabilities::empty() &&
e.has_tag(SHOULD_RETRY)
{
Expand Down
1 change: 0 additions & 1 deletion edgedb-tokio/tests/func/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ impl ServerGuard {
.status()
.expect("cannot run edgedb-cli to create a migration")
.success());
dbg!("2");
assert!(Command::new("edgedb")
.current_dir("./tests/func")
.arg("--tls-security")
Expand Down

0 comments on commit cf5043a

Please sign in to comment.