Fix NPE while generating the secret token for the GitLabPushTrigger (Fixes #447)

This commit is contained in:
Robin Müller 2016-12-05 22:14:04 +01:00
parent 799df9e8cc
commit 14879ad0a4
1 changed files with 4 additions and 9 deletions

View File

@ -250,12 +250,6 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {
noteHookTriggerHandler.handle(job, hook, ciSkip, branchFilter, mergeRequestLabelFilter);
}
private void generateSecretToken() {
byte[] random = new byte[16]; // 16x8=128bit worth of randomness, since we use md5 digest as the API token
RANDOM.nextBytes(random);
secretToken = Secret.fromString(Util.toHexString(random));
}
private void initializeTriggerHandler() {
mergeRequestHookTriggerHandler = newMergeRequestHookTriggerHandler(triggerOnMergeRequest, triggerOpenMergeRequestOnPush, skipWorkInProgressMergeRequest);
noteHookTriggerHandler = newNoteHookTriggerHandler(triggerOnNoteRequest, noteRegex);
@ -403,9 +397,10 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {
}
public void doGenerateSecretToken(@AncestorInPath final Job<?, ?> project, StaplerResponse response) {
GitLabPushTrigger trigger = getFromJob(project);
trigger.generateSecretToken();
response.setHeader("script", "document.getElementById('secretToken').value='" + trigger.getSecretToken() + "'");
byte[] random = new byte[16]; // 16x8=128bit worth of randomness, since we use md5 digest as the API token
RANDOM.nextBytes(random);
String secretToken = Util.toHexString(random);
response.setHeader("script", "document.getElementById('secretToken').value='" + secretToken + "'");
}
}
}