Skip to content

Commit

Permalink
Prefer security file over username/password (#21)
Browse files Browse the repository at this point in the history
Use security file option if it is not empty.
  • Loading branch information
thotypous authored and Tianqi-Tang committed Oct 18, 2016
1 parent 3316053 commit b2e2df8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ StorOps: The Python Library for VNX & Unity
.. image:: https://img.shields.io/pypi/v/storops.svg
:target: https://pypi.python.org/pypi/storops

VERSION: 0.2.18
VERSION: 0.2.19

A minimalist Python library to manage VNX/Unity systems.
This document lies in the source code and go with the release.
Expand Down Expand Up @@ -312,6 +312,8 @@ EMC Contributors
Community Contributors
``````````````````````
- Paulo Matias <matias@ufscar.br>
Patches and Suggestions
```````````````````````
Expand Down
9 changes: 4 additions & 5 deletions storops/vnx/navi_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ def is_credential_valid(self):
return self._is_credential_valid

def get_credentials(self):
if self._username is None and self._password is None:
if self._sec_file is not None:
# use security file
if self._sec_file is not None:
ret = text_var('-secfilepath', self._sec_file)
else:
ret = []
ret = text_var('-secfilepath', self._sec_file)
elif self._username is None and self._password is None:
ret = []
elif self._username is None or self._password is None:
self._is_credential_valid = False
raise ex.VNXCredentialError('username or password missing.')
Expand Down
7 changes: 7 additions & 0 deletions test/vnx/test_navi_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def test_security_file(self):
assert_that(' '.join(cmd.get_credentials()),
equal_to('-secfilepath /a/b/c.key'))

@patch_cli
def test_security_file_precedence(self):
cmd = NaviCommand(sec_file=r'/a/b/c.key',
username='admin', password='')
assert_that(' '.join(cmd.get_credentials()),
equal_to('-secfilepath /a/b/c.key'))

@patch_cli
def test_username_password_timeout(self):
cmd = NaviCommand('a', 'a', 1, timeout=20)
Expand Down

0 comments on commit b2e2df8

Please sign in to comment.