Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remoteBackup: fix invalid config file breaks Artifactory instance #349

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 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 or missing JSON config does not prevent Artifactory
// from serving and receiving artifacts.
//
cfg = parseJson(cfgfile)
if (!cfg) return

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

def parseJson(cfgfile) {
if (!cfgfile.exists()) {
log.warn("Config file missing. Please provide a config file at '$cfgfile'.")
return
}

try {
return new JsonSlurper().parse(cfgfile)
} catch (Exception e) {
log.warn("Invalid JSON config in '$cfgfile', error was: $e")
return // verbose way of saying no config loaded
}
}

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

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

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