Skip to content

Commit b16be24

Browse files
committed
Corrected useLocalAuth setting so that it works as expected
Corrected imports so that post version control method works as well as the cloud version
1 parent b64f29f commit b16be24

9 files changed

+33
-17
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@ To do this you will need to install Version Control For SplunkCloud on your Splu
260260
[SplunkVersionControlCloud github](https://github.com/gjanders/SplunkVersionControlCloud)
261261

262262
## Release Notes
263+
### 1.1.1
264+
Corrected useLocalAuth setting so that it works as expected
265+
266+
Corrected imports so that post version control method works as well as the cloud version
267+
263268
### 1.1.0
264269
Now tested on Windows and Splunk Cloud (note this version of the app is not installed on SplunkCloud, the VersionControl for SplunkCloud is the app to install on the SplunkCloud instance, this variation of the app includes only what is required to remotely backup/restore a SplunkCloud instance
265270

SplunkVersionControl.tgz

143 Bytes
Binary file not shown.

bin/splunkversioncontrol_backup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def validate_arguments():
173173
useLocalAuth = val_data['useLocalAuth'].lower()
174174
if useLocalAuth == "true" or useLocalAuth == "t":
175175
useLocalAuth = True
176+
logger.debug("useLocalAuth enabled")
176177
if val_data['srcURL'] != "https://localhost:8089":
177178
print_error("Expected srcURL of https://localhost:8089 since useLocalAuth=True")
178179
sys.exit(1)
@@ -186,18 +187,18 @@ def validate_arguments():
186187
if not useLocalAuth and ('srcUsername' not in val_data or 'srcPassword' not in val_data):
187188
print_error("useLocalAuth is not set to true and srcUsername/srcPassword not set, invalid config")
188189
sys.exit(3)
189-
190+
190191
appName = "SplunkVersionControl"
191192
if 'remoteAppName' in val_data:
192193
appName = val_data['remoteAppName']
193194

194195
if 'git_command' in val_data:
195-
git_command = val_data['git_command']
196+
git_command = val_data['git_command'].strip()
196197
logger.debug("Overriding git command to %s" % (git_command))
197198
else:
198199
git_command = "git"
199200
if 'ssh_command' in val_data:
200-
ssh_command = val_data['ssh_command']
201+
ssh_command = val_data['ssh_command'].strip()
201202
logger.debug("Overriding ssh command to %s" % (ssh_command))
202203
else:
203204
ssh_command = "ssh"

bin/splunkversioncontrol_backup_class.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ def run_script(self):
976976
useLocalAuth = config['useLocalAuth'].lower()
977977
if useLocalAuth == "true" or useLocalAuth=="t":
978978
useLocalAuth = True
979+
logger.debug("useLocalAuth enabled")
979980
else:
980981
useLocalAuth = False
981982

@@ -994,12 +995,12 @@ def run_script(self):
994995
self.gitRepoURL = config['gitRepoURL']
995996

996997
if 'git_command' in config:
997-
self.git_command = config['git_command']
998+
self.git_command = config['git_command'].strip()
998999
logger.debug("Overriding git command to %s" % (self.git_command))
9991000
else:
10001001
self.git_command = "git"
10011002
if 'ssh_command' in config:
1002-
self.ssh_command = config['ssh_command']
1003+
self.ssh_command = config['ssh_command'].strip()
10031004
logger.debug("Overriding ssh command to %s" % (self.ssh_command))
10041005
else:
10051006
self.ssh_command = "ssh"
@@ -1032,7 +1033,7 @@ def run_script(self):
10321033
currentEpochTime = calendar.timegm(time.gmtime())
10331034
self.session_key = config['session_key']
10341035

1035-
if self.srcPassword.find("password:") == 0:
1036+
if not useLocalAuth and self.srcPassword.find("password:") == 0:
10361037
self.srcPassword = get_password(self.srcPassword[9:], self.session_key, logger)
10371038

10381039
if 'appsList' in config and config['appsList']!="":

bin/splunkversioncontrol_rest_restore.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
import os
99
import time
1010
import calendar
11-
from splunkversioncontrol_restore_class import SplunkVersionControlRestore
1211
import sys
12+
import splunk.rest
1313

1414
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "lib"))
1515

1616
from splunklib import six
1717

18+
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "bin"))
19+
from splunkversioncontrol_restore_class import SplunkVersionControlRestore
20+
1821
splunkLogsDir = os.environ['SPLUNK_HOME'] + "/var/log/splunk"
1922
#Setup the logging
2023
logging_config = dict(
@@ -230,8 +233,8 @@ def handle_POST(self):
230233
self.response.write("Restore has completed successfully in app %s, object of type %s, with name %s was restored from tag %s, scope %s with restoreAsUser %s and your username of %s" % (app, type, obj_name, tag, scope, restoreAsUser, username))
231234
logger.info("Restore has completed successfully in app=%s, object of type=%s, with name=%s was restored from tag=%s, scope=%s with restoreAsUser=%s and requested by username=%s" % (app, type, obj_name, tag, scope, restoreAsUser, username))
232235
else:
233-
self.response.write("Restore has failed to complete successfully in app %s, object of type %s, with name %s was restored from tag %s, scope %s with restoreAsUser %s and your username of %s" % (app, type, obj_name, tag, scope, restoreAsUser, username))
234-
logger.warn("Restore has failed to successfully in app=%s, object of type=%s, with name=%s was restored from tag=%s, scope=%s with restoreAsUser=%s and requested by username=%s" % (app, type, obj_name, tag, scope, restoreAsUser, username))
236+
self.response.write("Restore has failed to complete successfully in app %s, object of type %s, with name %s was not restored from tag %s, scope %s with restoreAsUser %s and your username of %s" % (app, type, obj_name, tag, scope, restoreAsUser, username))
237+
logger.warn("Restore has failed to complete successfully in app=%s, object of type=%s, with name=%s was not restored from tag=%s, scope=%s with restoreAsUser=%s and requested by username=%s" % (app, type, obj_name, tag, scope, restoreAsUser, username))
235238

236239
self.runHttpRequest(url, headers, None, 'delete', 'wiping kvstore splunkversioncontrol_rest_restore_status after completed run')
237240

bin/splunkversioncontrol_restore.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def validate_arguments():
150150
useLocalAuth = val_data['useLocalAuth'].lower()
151151
if useLocalAuth == "true" or useLocalAuth == "t":
152152
useLocalAuth = True
153+
logger.debug("useLocalAuth enabled")
153154
if val_data['destURL'] != "https://localhost:8089":
154155
print_error("Expected destURL of https://localhost:8089 since useLocalAuth=True")
155156
sys.exit(1)
@@ -210,12 +211,12 @@ def validate_arguments():
210211
gitRepoURL = val_data['gitRepoURL']
211212

212213
if 'git_command' in val_data:
213-
git_command = val_data['git_command']
214+
git_command = val_data['git_command'].strip()
214215
logger.debug("Overriding git command to %s" % (git_command))
215216
else:
216217
git_command = "git"
217218
if 'ssh_command' in val_data:
218-
ssh_command = val_data['ssh_command']
219+
ssh_command = val_data['ssh_command'].strip()
219220
logger.debug("Overriding ssh command to %s" % (ssh_command))
220221
else:
221222
ssh_command = "ssh"

bin/splunkversioncontrol_restore_class.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ def run_script(self, restlist_override=None, config_override=None):
865865
useLocalAuth = config['useLocalAuth'].lower()
866866
if useLocalAuth == "true" or useLocalAuth=="t":
867867
useLocalAuth = True
868+
logger.debug("useLocalAuth enabled")
868869
else:
869870
useLocalAuth = False
870871

@@ -894,20 +895,20 @@ def run_script(self, restlist_override=None, config_override=None):
894895

895896
self.session_key = config['session_key']
896897

897-
if self.destPassword.find("password:") == 0:
898+
if not useLocalAuth and self.destPassword.find("password:") == 0:
898899
self.destPassword = get_password(self.destPassword[9:], self.session_key, logger)
899900

900901
knownAppList = []
901902
self.gitTempDir = config['gitTempDir']
902903
self.gitRootDir = config['gitTempDir']
903904

904905
if 'git_command' in config:
905-
self.git_command = config['git_command']
906+
self.git_command = config['git_command'].strip()
906907
logger.debug("Overriding git command to %s" % (self.git_command))
907908
else:
908909
self.git_command = "git"
909910
if 'ssh_command' in config:
910-
self.ssh_command = config['ssh_command']
911+
self.ssh_command = config['ssh_command'].strip()
911912
logger.debug("Overriding ssh command to %s" % (self.ssh_command))
912913
else:
913914
self.ssh_command = "ssh"
@@ -971,6 +972,7 @@ def run_script(self, restlist_override=None, config_override=None):
971972
else:
972973
resList = restlist_override
973974

975+
result = False
974976
if len(resList) == 0:
975977
logger.info("i=\"%s\" No restore required at this point in time" % (self.stanzaName))
976978
else:
@@ -994,11 +996,12 @@ def run_script(self, restlist_override=None, config_override=None):
994996
logger.info("i=\"%s\" Successfully cloned the git URL=%s into directory dir=%s" % (self.stanzaName, self.gitRepoURL, self.gitRootDir))
995997
else:
996998
logger.info("i=\"%s\" Successfully ran the git pull for URL=%s from directory dir=%s" % (self.stanzaName, self.gitRepoURL, self.gitRootDir))
999+
9971000
if stderrout.find("error:") != -1 or stderrout.find("fatal:") != -1 or stderrout.find("timeout after") != -1:
9981001
logger.warn("i=\"%s\" error/fatal messages in git stderroutput please review. stderrout=\"%s\"" % (self.stanzaName, stderrout))
9991002
gitFailure = True
1000-
logger.debug("i=\"%s\" The restore list is %s" % (self.stanzaName, resList))
10011003

1004+
logger.debug("i=\"%s\" The restore list is %s" % (self.stanzaName, resList))
10021005
#Attempt to determine all users involved in this restore so we can run a single query and determine if they are admins or not
10031006
userList = []
10041007
for aRes in resList:
@@ -1174,3 +1177,5 @@ def run_script(self, restlist_override=None, config_override=None):
11741177
shutil.rmtree(self.gitTempDir)
11751178

11761179
logger.info("i=\"%s\" Done" % (self.stanzaName))
1180+
1181+
return result

bin/splunkversioncontrol_utility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def runOSProcess(command, logger, timeout=10, shell=False):
3333
logger.debug("OS process exited with zero code, for command %s" % (command))
3434
res = True
3535

36-
return stdout, stderr, res
36+
return str(stdout), str(stderr), res
3737

3838
# use the password endpoint to obtain the clear_password passed in, start with the context of this app and then try all contexts
3939
def get_password(password, session_key, logger):

default/app.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ label = SplunkVersionControl
1212
[launcher]
1313
author = Gareth Anderson
1414
description = Version Control software for Splunk instances (backup/restore from git)
15-
version = 1.1.0
15+
version = 1.1.1
1616

1717
[package]
1818
id = SplunkVersionControl

0 commit comments

Comments
 (0)