Skip to content

Commit

Permalink
remoteBackup: fix invalid config file breaks Artifactory instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Begusch committed Dec 9, 2020
1 parent 333f82d commit c0a14a6
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions storage/remoteBackup/remoteBackup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ storage {
afterCreate { item ->
def etcdir = ctx.artifactoryHome.etcDir
def cfgfile = new File(etcdir, REMOTE_BACKUP)
def cfg = new JsonSlurper().parse(cfgfile)

// Ensure invalid json config does not prevent Artifactory
// from serving and receiving artifacts.
if (!cfgfile.exists()) return
cfg = parseJson(cfgfile)
if (!cfg) return

if (item.repoKey in cfg && !item.isFolder()) {
asSystem {
def dest = cfg[item.repoKey]
Expand All @@ -66,10 +72,24 @@ storage {
}
}

def parseJson(cfgfile) {
try {
return new JsonSlurper().parse(cfgfile)
} catch (Exception e) {
log.warn("Invalid json, error was: $e")
}
}

def runBackup(repos) {
def etcdir = ctx.artifactoryHome.etcDir
def cfgfile = new File(etcdir, REMOTE_BACKUP)
def cfg = new JsonSlurper().parse(cfgfile)

// Ensure invalid json config does not prevent Artifactory
// from serving and receiving artifacts.
if (!cfgfile.exists()) return
cfg = parseJson(cfgfile)
if (!cfg) return

if (repos) {
def cfgtmp = [:]
for (repo in repos) {
Expand Down

0 comments on commit c0a14a6

Please sign in to comment.