From 0b92967d3046ce7893106fd587fc553badc12280 Mon Sep 17 00:00:00 2001 From: Carl Yeksigian Date: Fri, 15 May 2015 11:36:06 -0500 Subject: [PATCH] cqlsh: Add LOGIN command to switch users Patch by Sachin Janani and Carl Yeksigian; reviewed by Tyler Hobbs for CASSANDRA-7212 --- CHANGES.txt | 1 + bin/cqlsh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 00cc335c70..a9d04d6606 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.0.16: + * (cqlsh) Add LOGIN command to switch users (CASSANDRA-7212) * Clone SliceQueryFilter in AbstractReadCommand implementations (CASSANDRA-8940) * Push correct protocol notification for DROP INDEX (CASSANDRA-9310) * token-generator - generated tokens too long (CASSANDRA-9300) diff --git a/bin/cqlsh b/bin/cqlsh index a165dca67c..fa0de7f6c4 100755 --- a/bin/cqlsh +++ b/bin/cqlsh @@ -197,6 +197,7 @@ my_commands_ending_with_newline = ( 'show', 'source', 'capture', + 'login', 'debug', 'tracing', 'expand', @@ -222,6 +223,7 @@ cqlsh_extra_syntax_rules = r''' | | | + | | | | @@ -290,6 +292,9 @@ cqlsh_extra_syntax_rules = r''' ::= "EXPAND" ( switch=( "ON" | "OFF" ) )? ; + ::= "LOGIN" username= (password=)? + ; + ::= "exit" | "quit" ; @@ -1825,6 +1830,35 @@ class Shell(cmd.Cmd): self.cursor.consistency_level = level.upper() print 'Consistency level set to %s.' % (level.upper(),) + def do_login(self, parsed): + """ + LOGIN [cqlsh only] + + Changes login information without requiring restart. + + LOGIN () + + Login using the specified username. If password is specified, it will be used + otherwise, you will be prompted to enter. + """ + username = parsed.get_binding('username') + password = parsed.get_binding('password') + if password is None: + password = getpass.getpass() + else: + password = password[1:-1] + + transport = self.transport_factory(self.hostname, self.port, os.environ, CONFIG_FILE) + conn = cql.connect(self.hostname, self.port, keyspace=self.current_keyspace, user=username, + password=password, cql_version=self.conn.cql_version, + transport=transport) + + self.username = username + self.password = password + self.conn=conn + self.cursor = self.conn.cursor() + self.get_connection_versions() + def do_exit(self, parsed=None): """ EXIT/QUIT [cqlsh only]