Skip to content

Commit af1ba9e

Browse files
author
Shakeel Mohamed
committed
revise storage passwords create() and docstrings
1 parent 3dce11d commit af1ba9e

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

splunklib/client.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,6 @@ def __len__(self):
16731673

16741674
class StoragePassword(Entity):
16751675
"""This class contains a storage password.
1676-
16771676
"""
16781677
def __init__(self, service, path, **kwargs):
16791678
state = kwargs.get('state', None)
@@ -1701,7 +1700,6 @@ def username(self):
17011700
class StoragePasswords(Collection):
17021701
"""This class provides access to the storage passwords from this Splunk
17031702
instance. Retrieve this collection using :meth:`Service.storage_passwords`.
1704-
17051703
"""
17061704
def __init__(self, service):
17071705
if service.namespace.owner == '-' or service.namespace.app == '-':
@@ -1711,13 +1709,12 @@ def __init__(self, service):
17111709
def create(self, password, username, realm=None):
17121710
""" Creates a storage password.
17131711
1714-
The identifier can be passed in through the username parameter as
1715-
<username> or <realm>:<username>, but the preferred way is by
1716-
passing in the username and realm parameters.
1712+
A `StoragePassword` can be identified by <username>, or by <realm>:<username> if the
1713+
optional realm parameter is also provided.
17171714
17181715
:param password: The password for the credentials - this is the only part of the credentials that will be stored securely.
17191716
:type name: ``string``
1720-
:param username: The username for the credentials, or <realm>:<username> if the realm parameter is omitted.
1717+
:param username: The username for the credentials.
17211718
:type name: ``string``
17221719
:param realm: The credential realm. (optional)
17231720
:type name: ``string``
@@ -1727,7 +1724,10 @@ def create(self, password, username, realm=None):
17271724
if not isinstance(username, basestring):
17281725
raise ValueError("Invalid name: %s" % repr(username))
17291726

1730-
response = self.post(password=password, realm=realm, name=username)
1727+
if realm is None:
1728+
response = self.post(password=password, name=username)
1729+
else:
1730+
response = self.post(password=password, realm=realm, name=username)
17311731

17321732
if response.status != 201:
17331733
raise ValueError("Unexpected status code %s returned from creating a stanza" % response.status)
@@ -1737,8 +1737,9 @@ def create(self, password, username, realm=None):
17371737
storage_password = StoragePassword(self.service, self._entity_path(state), state=state, skip_refresh=True)
17381738

17391739
return storage_password
1740-
1741-
"""Delete a storage password by username and/or realm.
1740+
1741+
def delete(self, username, realm=None):
1742+
"""Delete a storage password by username and/or realm.
17421743
17431744
The identifier can be passed in through the username parameter as
17441745
<username> or <realm>:<username>, but the preferred way is by
@@ -1748,9 +1749,9 @@ def create(self, password, username, realm=None):
17481749
:type name: ``string``
17491750
:param realm: The credential realm. (optional)
17501751
:type name: ``string``
1751-
1752-
"""
1753-
def delete(self, username, realm=None):
1752+
:return: The `StoragePassword` collection.
1753+
:rtype: ``self``
1754+
"""
17541755
if realm is None:
17551756
# This case makes the username optional, so
17561757
# the full name can be passed in as realm.

tests/test_storage_passwords.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_create_norealm(self):
4949
start_count = len(self.storage_passwords)
5050
username = testlib.tmpname()
5151

52-
p = self.storage_passwords.create("changeme", username, "")
52+
p = self.storage_passwords.create("changeme", username)
5353
self.assertEqual(start_count + 1, len(self.storage_passwords))
5454
self.assertEqual(p.realm, None)
5555
self.assertEqual(p.username, username)
@@ -106,7 +106,7 @@ def test_read(self):
106106
start_count = len(self.storage_passwords)
107107
username = testlib.tmpname()
108108

109-
p = self.storage_passwords.create("changeme", username, "")
109+
p = self.storage_passwords.create("changeme", username)
110110
self.assertEqual(start_count + 1, len(self.storage_passwords))
111111

112112
for sp in self.storage_passwords:

0 commit comments

Comments
 (0)