Skip to content
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
17 changes: 9 additions & 8 deletions st2client/st2client/commands/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from six.moves.configparser import ConfigParser
import getpass
import json
import logging

from six.moves.configparser import ConfigParser

from st2client.base import BaseCLIApp
from st2client import config_parser
from st2client import models
Expand Down Expand Up @@ -123,17 +124,17 @@ def run(self, args, **kwargs):
config.read(config_file)

# Modify config (and optionally populate with password)
if 'credentials' not in config:
if not config.has_section('credentials'):
config.add_section('credentials')
config['credentials'] = {}
config['credentials']['username'] = args.username

config.set('credentials', 'username', args.username)
if args.write_password:
config['credentials']['password'] = args.password
config.set('credentials', 'password', args.password)
else:
# Remove any existing password from config
config['credentials'].pop('password', None)
config.remove_option('credentials', 'password')

with open(config_file, "w") as cfg_file_out:
with open(config_file, 'w') as cfg_file_out:
config.write(cfg_file_out)

return manager
Expand Down Expand Up @@ -175,7 +176,7 @@ def run(self, args, **kwargs):
config = ConfigParser()
config.read(config_file)

return config['credentials']['username']
return config.get('credentials', 'username')

def run_and_print(self, args, **kwargs):
try:
Expand Down
4 changes: 4 additions & 0 deletions st2client/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def setUp(self):
os.environ['ST2_CLI_SKIP_CONFIG'] = '1'

if self.capture_output:
# Make sure we reset it for each test class instance
self.stdout = six.moves.StringIO()
self.stderr = six.moves.StringIO()

sys.stdout = self.stdout
sys.stderr = self.stderr

Expand Down
Loading