Skip to content
Snippets Groups Projects
Commit 77039753 authored by sveseli's avatar sveseli
Browse files

changes to support login file

parent 308cb3d3
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
from dm.common.cli.dmRestCli import DmRestCli
from dm.common.utility.configurationManager import ConfigurationManager
class DmRestSessionCli(DmRestCli):
""" Base dm session cli class. """
......@@ -14,11 +15,14 @@ class DmRestSessionCli(DmRestCli):
self.addOptionGroup(loginGroup, None)
self.addOptionToGroup(loginGroup, '', '--login-username', dest='loginUsername', help='Login username.')
self.addOptionToGroup(loginGroup, '', '--login-password', dest='loginPassword', help='Login password.')
self.addOptionToGroup(loginGroup, '', '--login-file', dest='loginFile', help='Login file, contains "<login username>|<login password>" pair. It can be specified using DM_LOGIN_FILE environment variable. This option cannot be used with --login-username and --login-password options.')
def parseArgs(self, usage=None):
DmRestCli.parseArgs(self, usage)
self.loginUsername = self.options.loginUsername
self.loginPassword = self.options.loginPassword
self.loginFile = self.options.loginFile
self.parseLoginFile()
return (self.options, self.args)
def getLoginUsername(self):
......@@ -27,8 +31,26 @@ class DmRestSessionCli(DmRestCli):
def getLoginPassword(self):
return self.loginPassword
def getLoginFile(self):
if not self.loginFile:
configManager = ConfigurationManager.getInstance()
self.loginFile = configManager.getLoginFile()
return self.loginFile
def parseLoginFile(self):
if self.getLoginFile() and not self.getLoginUsername() and not self.getLoginPassword():
try:
# Assume form <username>|<password>
tokenList = open(self.loginFile).readline().split('|')
if len(tokenList) == 2:
self.loginUsername = tokenList[0].strip()
self.loginPassword = tokenList[1].strip()
except:
# Ignore invalid login file
pass
def hasCredentials(self):
return (self.loginUsername != None and self.loginPassword != None)
return (self.getLoginUsername() != None and self.getLoginPassword() != None)
#######################################################################
# Testing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment