blob: 3ba4a9cb214fb0e01f968a16e10f011f89f3eb19 [file] [log] [blame]
From 7776458f4c723b1d1b4d796cc958fdb46cf5a03f Mon Sep 17 00:00:00 2001
From: Prathmesh Prabhu <pprabhu@chromium.org>
Date: Mon, 5 Jan 2015 13:44:26 +0530
Subject: Fix dbshell to use user/password from settings file.
---
google/storage/speckle/python/django/backend/client.py | 16 ++++++++++++++--
google/storage/speckle/python/tool/google_sql.py | 7 ++++++-
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/google/storage/speckle/python/django/backend/client.py b/google/storage/speckle/python/django/backend/client.py
index 3c65897..cab320a 100644
--- a/google/storage/speckle/python/django/backend/client.py
+++ b/google/storage/speckle/python/django/backend/client.py
@@ -35,12 +35,24 @@ class DatabaseClient(backends.BaseDatabaseClient):
def runshell(self):
"""Start an interactive database shell."""
settings_dict = self.connection.settings_dict
- args = [self.executable_name]
- args = ['', settings_dict.get('INSTANCE')]
+ #args = [self.executable_name]
+ args = ['']
+
+ user = settings_dict.get('USER')
+ if user:
+ args.append('--user')
+ args.append(user)
+ password = settings_dict.get('PASSWORD')
+ if password:
+ args.append('--password')
+ args.append(password)
+
+ args.append(settings_dict.get('INSTANCE'))
database = settings_dict.get('NAME')
if database:
args.append(database)
+ print('[xckd] Args for google_sql: (%s)' % args)
diff --git a/google/storage/speckle/python/tool/google_sql.py b/google/storage/speckle/python/tool/google_sql.py
index 3aa1288..91132f4 100644
--- a/google/storage/speckle/python/tool/google_sql.py
+++ b/google/storage/speckle/python/tool/google_sql.py
@@ -210,6 +210,10 @@ def main(argv):
parser.add_option('-e', '--output_encoding', dest='output_encoding',
default=DEFAULT_ENCODING,
help='Output encoding. Defaults to %s.' % DEFAULT_ENCODING)
+ parser.add_option('--user', dest='user',
+ default=None, help=optparse.SUPPRESS_HELP)
+ parser.add_option('--password', dest='password',
+ default=None, help=optparse.SUPPRESS_HELP)
parser.add_option('--oauth_credentials_path', dest='oauth_credentials_path',
default=None, help=optparse.SUPPRESS_HELP)
@@ -223,6 +227,7 @@ def main(argv):
instance_alias = instance.replace(':', '#')
+ print(instance_alias)
database = None
if len(args) == 2:
database = args[1]
@@ -237,7 +242,7 @@ def main(argv):
db.add_driver(GoogleSqlDriver.NAME, GoogleSqlDriver)
sql_cmd_config = config.SQLCmdConfig(None)
sql_cmd_config.add('__googlesql__', instance_alias, None, None, database,
- GoogleSqlDriver.NAME, None, None)
+ GoogleSqlDriver.NAME, options.user, options.password)
sql_cmd = GoogleSqlCmd(sql_cmd_config)
sql_cmd.set_output_encoding(options.output_encoding)
sql_cmd.set_database(instance_alias)
--
2.2.0.rc0.207.ga3a616c