Skip to content

Commit 3dba01d

Browse files
committed
Merge branch 'master' into testing
2 parents 4e5440c + 12d9194 commit 3dba01d

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

bin/postversioncontrolrestore.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,28 @@
1010
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
1111

1212
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option
13+
from splunklib.searchcommands.validators import Validator, Boolean, File
1314
from splunklib.binding import HTTPError
1415

16+
class OrValidator(Validator):
17+
def __init__(self, a, b):
18+
self.a = a
19+
self.b = b
20+
def __call__(self, value):
21+
"""Returns b if a raises an exception otherwise a."""
22+
try:
23+
return self.a.__call__(value)
24+
except ValueError:
25+
return self.b.__call__(value)
26+
27+
def format(self, value):
28+
"""Returns b if a raises an exception otherwise a."""
29+
try:
30+
return self.a.format(value)
31+
except:
32+
return self.b.format(value)
33+
34+
1535
splunkLogsDir = os.environ['SPLUNK_HOME'] + "/var/log/splunk"
1636
#Setup the logging
1737
logging_config = dict(
@@ -60,7 +80,7 @@ class SVCPostRestore(GeneratingCommand):
6080
restoreAsUser = Option(require=True)
6181
scope = Option(require=True)
6282
timeout = Option(require=True)
63-
sslVerify = Option(require=False, default=False)
83+
sslVerify = Option(require=False, default=False, validate=OrValidator(File(), Boolean()))
6484

6585
def generate(self):
6686
"""

bin/splunkversioncontrol_rest_restore.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
class SVCRestore(splunk.rest.BaseRestHandler):
6161

62-
def query_back_for_user_and_permissions(self, authorization_token, remoteAddr,*, sslVerify):
62+
def query_back_for_user_and_permissions(self, authorization_token, *, sslVerify):
6363
headers = { "Authorization" : authorization_token }
6464

6565
#Run a query back against the source system to check the username/role
@@ -104,7 +104,7 @@ def handle_POST(self):
104104
url = "https://localhost:8089/servicesNS/-/-/data/inputs/splunkversioncontrol_restore/" + six.moves.urllib.parse.quote(splunk_vc_name) + "?output_mode=json"
105105
logger.debug("Now running query against url=%s to obtain config information" % (url))
106106

107-
res = self.runHttpRequest(url, headers, None, "get", "querying the inputs for splunkversioncontrol_restore with name %s" % (splunk_vc_name), sslVerify=sslVerify)
107+
res = self.runHttpRequest(url, headers, None, "get", "querying the inputs for splunkversioncontrol_restore with name %s" % (splunk_vc_name), sslVerify=False)
108108
if not res:
109109
return
110110

@@ -160,7 +160,7 @@ def handle_POST(self):
160160
else:
161161
time_wait = 600
162162

163-
username, roles = self.query_back_for_user_and_permissions(payload['Authorization'][0], remoteAddr)
163+
username, roles = self.query_back_for_user_and_permissions(payload['Authorization'][0], sslVerify=sslVerify)
164164
logger.info("username=%s roles=%s" % (username, roles))
165165

166166
app = payload['app'][0]

bin/splunkversioncontrol_utility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_password(password, session_key, logger, *, sslVerify=False):
7373

7474
url = "https://localhost:8089/servicesNS/-/-/storage/passwords?output_mode=json&f=clear_password&count=0&search=" + password
7575
logger.debug("Trying url=%s with session_key to obtain name=%s" % (url, password))
76-
res = requests.get(url, headers=headers, verify=verify)
76+
res = requests.get(url, headers=headers, verify=sslVerify)
7777
dict = json.loads(res.text)
7878
if not 'entry' in dict:
7979
logger.warn("dict=%s did not contain the entries expected on url=%s while looking for password=%s" % (dict, url, password))

0 commit comments

Comments
 (0)