cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

cli: missing username in connection URL prevents username from appearing in prompt

Open knz opened this issue 10 years ago • 16 comments

If COCKROACH_URL or --url specifies no username with an insecure cluster, the connection is accepted and the underlying pq library uses the name of the user who launched the shell. However the CLI shell's prompt does not see this and the username part appears empty in the prompt.

A better behavior would be to query the database after the connection is established to determine what the current user is, much like the CLI already queries the database for syntax/txn status.

Found while investigating #10835.

knz avatar Nov 20 '16 11:11 knz

I don't think the username field will be empty. lib/pq uses the username provided by the operating system if none is provided through the URL. I tested it out and my os username is correctly used.

After #10862 (thanks for catching that btw) the only issue I see is that the username used for the connection won't be reflected in the prompt.

asubiotto avatar Nov 29 '16 16:11 asubiotto

Oh thanks for your analysis. Then the cli shell should do what is already done for other things and fetch the current user from the database. Changed the issue description accordingly.

knz avatar Nov 29 '16 16:11 knz

@knz, I want to have a try for this.

a6802739 avatar Dec 14 '16 07:12 a6802739

@a6802739 ok, thanks!

knz avatar Dec 14 '16 12:12 knz

@knz, what does the prevents username from appearing in prompt prompt mean here?

a6802739 avatar Dec 15 '16 13:12 a6802739

  1. start insecure cluster
  2. run client with ./cockroach sql --url="postgresql://localhost:26257?sslmode=disable"
  3. look at prompt:
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
@localhost:26257>

(the username is missing)

knz avatar Dec 15 '16 14:12 knz

@knz, thanks for your reference.

a6802739 avatar Dec 15 '16 14:12 a6802739

Good evening @knz may i give this is issue a go myself ?

Best regards, Panos.

pmamatsis avatar Jan 05 '17 20:01 pmamatsis

yes you can also have a look.

knz avatar Jan 05 '17 20:01 knz

@pmamatsis note we have already a PR out for this in #12408. You can help with reviewing it though.

knz avatar Jan 05 '17 20:01 knz

Good evening @knz, i have managed to perform the rebase of my PR successfully. I will start working on this issue as discussed and implement it in a way to fit the existing FSM.

I wanted to ask you a newbie question about the rebase. When i am checking into master (i have added the official repository of cockroachdb as 'main') and perform the git status command i am getting the message:

On branch master
Your branch is ahead of 'origin/master' by 796 commits.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

If i execute the command git remote -v i am getting the following results:

main	https://github.com/cockroachdb/cockroach.git (fetch)
main	https://github.com/cockroachdb/cockroach.git (push)
origin	https://github.com/pmamatsis/cockroach (fetch)
origin	https://github.com/pmamatsis/cockroach (push)

Best regards, Panos.

pmamatsis avatar Feb 11 '17 18:02 pmamatsis

Can you show me the content of your .git/config

Sent from my Android device with K-9 Mail. Please excuse my brevity.

knz avatar Feb 11 '17 22:02 knz

Good afternoon @knz, my apologies for the late reply. The contents of my .git/config are the following:

[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = https://github.com/pmamatsis/cockroach
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[submodule "vendor"]
	url = https://github.com/cockroachdb/vendored
[remote "main"]
	url = https://github.com/cockroachdb/cockroach.git
	fetch = +refs/heads/*:refs/remotes/main/*

I have checked the pkg/cli/sql.go file that i have locally against the one in the official cockroachdb repo and they are identical though.

Best regards and thank you in advance, Panos.

pmamatsis avatar Feb 12 '17 10:02 pmamatsis

Ok then, it's easy: the message merely indicates that your master branch on https://github.com/pmamatsis/cockroach is not up to date. By running git push you can bring it forward. This will synchronize your repository at https://github.com/pmamatsis/cockroach with ours.

knz avatar Feb 13 '17 10:02 knz

Good evening @knz, thank you for your prompt and quick reply. I will do this and then i will start working on the current issue.

Best regards, Panos.

pmamatsis avatar Feb 14 '17 17:02 pmamatsis

Looks like this was fixed by https://github.com/cockroachdb/cockroach/pull/12408

Closing!

dianasaur323 avatar Apr 05 '17 16:04 dianasaur323