Browse Source

Add verifySsl option #64

Allows to disable the ssl verification for remote repo
pull/70/head
Christian Wiedemann-Gruber 6 years ago
parent
commit
5238b0ed7e
  1. 2
      pom.xml
  2. 16
      src/main/java/com/englishtown/bitbucket/hook/MirrorBucketProcessor.java
  3. 9
      src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java
  4. 1
      src/main/java/com/englishtown/bitbucket/hook/MirrorSettings.java
  5. 1
      src/main/resources/i18n/stash-hook-mirror.properties
  6. 5
      src/main/resources/static/mirror-repository-hook.soy
  7. 2
      src/test/java/com/englishtown/bitbucket/hook/MirrorRepositoryHookTest.java

2
pom.xml

@ -4,7 +4,7 @@
<groupId>com.englishtown</groupId> <groupId>com.englishtown</groupId>
<artifactId>stash-hook-mirror</artifactId> <artifactId>stash-hook-mirror</artifactId>
<version>2.4.0-SNAPSHOT</version> <version>2.4.1-SNAPSHOT</version>
<organization> <organization>
<name>Englishtown</name> <name>Englishtown</name>

16
src/main/java/com/englishtown/bitbucket/hook/MirrorBucketProcessor.java

@ -9,6 +9,7 @@ import com.atlassian.bitbucket.scm.Command;
import com.atlassian.bitbucket.scm.ScmCommandBuilder; import com.atlassian.bitbucket.scm.ScmCommandBuilder;
import com.atlassian.bitbucket.scm.ScmService; import com.atlassian.bitbucket.scm.ScmService;
import com.atlassian.bitbucket.scm.git.command.GitCommandExitHandler; import com.atlassian.bitbucket.scm.git.command.GitCommandExitHandler;
import com.atlassian.bitbucket.scm.git.command.GitScmCommandBuilder;
import com.atlassian.bitbucket.server.ApplicationPropertiesService; import com.atlassian.bitbucket.server.ApplicationPropertiesService;
import com.atlassian.bitbucket.user.SecurityService; import com.atlassian.bitbucket.user.SecurityService;
import com.google.common.base.Strings; import com.google.common.base.Strings;
@ -88,13 +89,22 @@ public class MirrorBucketProcessor implements BucketProcessor<MirrorRequest> {
// Call push command with the prune flag and refspecs for heads and tags // Call push command with the prune flag and refspecs for heads and tags
// Do not use the mirror flag as pull-request refs are included // Do not use the mirror flag as pull-request refs are included
ScmCommandBuilder<?> builder = scmService.createBuilder(repository) ScmCommandBuilder<?> obj = scmService.createBuilder(repository)
.command("push") .command("push")
.argument("--prune") // this deletes locally deleted branches .argument("--prune") // this deletes locally deleted branches
.argument(authenticatedUrl) .argument(authenticatedUrl)
.argument("--force"); .argument("--force");
// Use an atomic transaction to have a consistent state // Use GitBuilder to allow git settings to be passed
GitScmCommandBuilder builder = (GitScmCommandBuilder) obj;
if (!settings.verifySsl) {
builder.withConfiguration("http.sslVerify", false);
}
// Use an atomicw transaction to have a consistent state
if (settings.atomic) { if (settings.atomic) {
builder.argument("--atomic"); builder.argument("--atomic");
} }
@ -116,6 +126,8 @@ public class MirrorBucketProcessor implements BucketProcessor<MirrorRequest> {
builder.argument("+refs/notes/*:refs/notes/*"); builder.argument("+refs/notes/*:refs/notes/*");
} }
PasswordHandler passwordHandler = new PasswordHandler(settings.password, PasswordHandler passwordHandler = new PasswordHandler(settings.password,
new GitCommandExitHandler(i18nService, repository)); new GitCommandExitHandler(i18nService, repository));

9
src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java

@ -35,6 +35,7 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
static final String SETTING_TAGS = "tags"; static final String SETTING_TAGS = "tags";
static final String SETTING_NOTES = "notes"; static final String SETTING_NOTES = "notes";
static final String SETTING_ATOMIC = "atomic"; static final String SETTING_ATOMIC = "atomic";
static final String SETTING_VERIFY_SSL = "verifySsl";
/** /**
* Trigger types that don't cause a mirror to happen * Trigger types that don't cause a mirror to happen
@ -125,7 +126,7 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
boolean ok = true; boolean ok = true;
logger.debug("MirrorRepositoryHook: validate started."); logger.debug("MirrorRepositoryHook: validate started.");
List<MirrorSettings> mirrorSettings = getMirrorSettings(settings, false, false, false); List<MirrorSettings> mirrorSettings = getMirrorSettings(settings, false, false, false, false);
for (MirrorSettings ms : mirrorSettings) { for (MirrorSettings ms : mirrorSettings) {
if (!validate(ms, errors)) { if (!validate(ms, errors)) {
ok = false; ok = false;
@ -144,10 +145,10 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
} }
private List<MirrorSettings> getMirrorSettings(Settings settings) { private List<MirrorSettings> getMirrorSettings(Settings settings) {
return getMirrorSettings(settings, true, true, true); return getMirrorSettings(settings, true, true, true, true);
} }
private List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTags, boolean defNotes, boolean defAtomic) { private List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTags, boolean defNotes, boolean defAtomic, boolean defVerifySsl) {
Map<String, Object> allSettings = settings.asMap(); Map<String, Object> allSettings = settings.asMap();
int count = 0; int count = 0;
@ -164,6 +165,7 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
ms.tags = (settings.getBoolean(SETTING_TAGS + suffix, defTags)); ms.tags = (settings.getBoolean(SETTING_TAGS + suffix, defTags));
ms.notes = (settings.getBoolean(SETTING_NOTES + suffix, defNotes)); ms.notes = (settings.getBoolean(SETTING_NOTES + suffix, defNotes));
ms.atomic = (settings.getBoolean(SETTING_ATOMIC + suffix, defAtomic)); ms.atomic = (settings.getBoolean(SETTING_ATOMIC + suffix, defAtomic));
ms.verifySsl = (settings.getBoolean(SETTING_VERIFY_SSL + suffix, defVerifySsl));
ms.suffix = String.valueOf(count++); ms.suffix = String.valueOf(count++);
results.add(ms); results.add(ms);
@ -239,6 +241,7 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
values.put(SETTING_TAGS + ms.suffix, ms.tags); values.put(SETTING_TAGS + ms.suffix, ms.tags);
values.put(SETTING_NOTES + ms.suffix, ms.notes); values.put(SETTING_NOTES + ms.suffix, ms.notes);
values.put(SETTING_ATOMIC + ms.suffix, ms.atomic); values.put(SETTING_ATOMIC + ms.suffix, ms.atomic);
values.put(SETTING_VERIFY_SSL + ms.suffix, ms.verifySsl);
} }
// Unfortunately the settings are stored in an immutable map, so need to cheat with reflection // Unfortunately the settings are stored in an immutable map, so need to cheat with reflection

1
src/main/java/com/englishtown/bitbucket/hook/MirrorSettings.java

@ -12,4 +12,5 @@ class MirrorSettings implements Serializable {
boolean tags; boolean tags;
boolean notes; boolean notes;
boolean atomic; boolean atomic;
boolean verifySsl;
} }

1
src/main/resources/i18n/stash-hook-mirror.properties

@ -17,3 +17,4 @@ mirror-repository-hook.refspec.description=The git refspec(s) to mirror (default
mirror-repository-hook.tags.label=Tags (ie. +refs/tags/*:refs/tags/*) mirror-repository-hook.tags.label=Tags (ie. +refs/tags/*:refs/tags/*)
mirror-repository-hook.notes.label=Notes (ie. +refs/notes/*:refs/notes/*) mirror-repository-hook.notes.label=Notes (ie. +refs/notes/*:refs/notes/*)
mirror-repository-hook.atomic.label=Atomic mirror-repository-hook.atomic.label=Atomic
mirror-repository-hook.verifySsl.label=Verify SSL

5
src/main/resources/static/mirror-repository-hook.soy

@ -98,6 +98,11 @@
'id' : 'atomic' + $index, 'id' : 'atomic' + $index,
'labelText': getText('mirror-repository-hook.atomic.label'), 'labelText': getText('mirror-repository-hook.atomic.label'),
'isChecked' : $config['atomic' + $index] != false 'isChecked' : $config['atomic' + $index] != false
],
[
'id' : 'verifySsl' + $index,
'labelText': getText('mirror-repository-hook.verifySsl.label'),
'isChecked' : $config['verifySsl' + $index] != false
] ]
] /} ] /}
{/call} {/call}

2
src/test/java/com/englishtown/bitbucket/hook/MirrorRepositoryHookTest.java

@ -237,6 +237,7 @@ public class MirrorRepositoryHookTest {
verifyZeroInteractions(bucketedExecutor, errors, settings); verifyZeroInteractions(bucketedExecutor, errors, settings);
} }
private PostRepositoryHookContext buildContext() { private PostRepositoryHookContext buildContext() {
Settings settings = defaultSettings(); Settings settings = defaultSettings();
@ -266,6 +267,7 @@ public class MirrorRepositoryHookTest {
when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_TAGS), eq(true))).thenReturn(true); when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_TAGS), eq(true))).thenReturn(true);
when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_NOTES), eq(true))).thenReturn(true); when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_NOTES), eq(true))).thenReturn(true);
when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_ATOMIC), eq(true))).thenReturn(true); when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_ATOMIC), eq(true))).thenReturn(true);
when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_VERIFY_SSL), eq(true))).thenReturn(true);
return settings; return settings;
} }

Loading…
Cancel
Save