Skip to content

Commit a77701d

Browse files
author
Frederick Ross
committed
Fix strangely misplaced methods on Configurations and ConfigurationFile.
Configurations.delete now throws IllegalOperationException immediately. Docstrings on Configurations no longer refer to stanzas. Updated changelog saying that Confs has been renamed to Configurations and ConfFile to ConfigurationFile. Also, make Entity.__getitem__ pass no namespace if none is provided.
1 parent b3071c5 commit a77701d

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 1.0
44

5-
* Confs has been renamed to Configurations.
5+
* Confs has been renamed to Configurations, and ConfFile to ConfigurationFile.
66
* Stanza.submit now takes a dictionary of key/value pairs specifying the stanza instead of a raw string.
77
* Namespace handling has changed subtly. Code that depends on namespace handling in detail may break.
88
* Added User.role_entities to return a list of the actual entity objects for the

splunklib/client.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,14 +1152,15 @@ def __getitem__(self, key):
11521152
'mysearch',
11531153
client.namespace(sharing='user', owner='boris', app='search')]
11541154
"""
1155-
if isinstance(key, tuple) and len(key) == 2:
1156-
# x[a,b] is translated to x.__getitem__( (a,b) ), so we
1157-
# have to extract values out.
1158-
key, ns = key
1159-
else:
1160-
ns = self.service.namespace
11611155
try:
1162-
response = self.get(key, owner=ns.owner, app=ns.app)
1156+
if isinstance(key, tuple) and len(key) == 2:
1157+
# x[a,b] is translated to x.__getitem__( (a,b) ), so we
1158+
# have to extract values out.
1159+
key, ns = key
1160+
response = self.get(key, owner=ns.owner, app=ns.app)
1161+
else:
1162+
response = self.get(key)
1163+
11631164
entries = self._load_list(response)
11641165
if len(entries) > 1:
11651166
raise AmbiguousReferenceException("Found multiple entities named '%s'; please specify a namespace." % key)
@@ -1626,14 +1627,14 @@ def __contains__(self, key):
16261627
else:
16271628
raise
16281629

1629-
def create(self, name, **kwargs):
1630-
""" Creates a stanza in a given configuration file.
1630+
def create(self, name):
1631+
""" Creates a configuration file named *name*.
1632+
1633+
If there is already a configuration file with that name,
1634+
the existing file is returned.
16311635
16321636
:param name: The name of the configuration file.
16331637
:type name: ``string``
1634-
:param kwargs: An arbitrary set of key-value pairs to place in the
1635-
stanza.
1636-
:type kwargs: ``dict``
16371638
16381639
:return: The :class:`ConfigurationFile` object.
16391640
"""
@@ -1642,7 +1643,7 @@ def create(self, name, **kwargs):
16421643
# Entity.
16431644
if not isinstance(name, basestring):
16441645
raise ValueError("Invalid name: %s" % repr(name))
1645-
response = self.post(__conf=name, **kwargs)
1646+
response = self.post(__conf=name)
16461647
if response.status == 303:
16471648
return self[name]
16481649
elif response.status == 201:
@@ -1651,18 +1652,8 @@ def create(self, name, **kwargs):
16511652
raise ValueError("Unexpected status code %s returned from creating a stanza" % response.status)
16521653

16531654
def delete(self, key):
1654-
""" Deletes a stanza from a given configuration file.
1655-
1656-
:param key: The name of the stanza.
1657-
:type key: ``string``
1658-
"""
1659-
try:
1660-
super(Configurations, self).delete(key)
1661-
except HTTPError as he:
1662-
if he.status == 405:
1663-
raise IllegalOperationException("Cannot delete configuration files from the REST API.")
1664-
else:
1665-
raise
1655+
"""Raises `IllegalOperationException`."""
1656+
raise IllegalOperationException("Cannot delete configuration files from the REST API.")
16661657

16671658
def _entity_path(self, state):
16681659
# Overridden to make all the ConfigurationFile objects

0 commit comments

Comments
 (0)