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

Add verifySsl option #64 #70

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.englishtown</groupId>
<artifactId>stash-hook-mirror</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.4.1-SNAPSHOT</version>

<organization>
<name>Englishtown</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.atlassian.bitbucket.scm.ScmCommandBuilder;
import com.atlassian.bitbucket.scm.ScmService;
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.user.SecurityService;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -88,13 +89,22 @@ private void runMirrorCommand(MirrorSettings settings, Repository repository) {

// 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
ScmCommandBuilder<?> builder = scmService.createBuilder(repository)
ScmCommandBuilder<?> obj = scmService.createBuilder(repository)
.command("push")
.argument("--prune") // this deletes locally deleted branches
.argument(authenticatedUrl)
.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) {
builder.argument("--atomic");
}
Expand All @@ -116,6 +126,8 @@ private void runMirrorCommand(MirrorSettings settings, Repository repository) {
builder.argument("+refs/notes/*:refs/notes/*");
}



PasswordHandler passwordHandler = new PasswordHandler(settings.password,
new GitCommandExitHandler(i18nService, repository));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
static final String SETTING_TAGS = "tags";
static final String SETTING_NOTES = "notes";
static final String SETTING_ATOMIC = "atomic";
static final String SETTING_VERIFY_SSL = "verifySsl";

/**
* Trigger types that don't cause a mirror to happen
Expand Down Expand Up @@ -125,7 +126,7 @@ public Repository visit(@Nonnull RepositoryScope scope) {
boolean ok = true;
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) {
if (!validate(ms, errors)) {
ok = false;
Expand All @@ -144,10 +145,10 @@ public Repository visit(@Nonnull RepositoryScope scope) {
}

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();
int count = 0;

Expand All @@ -164,6 +165,7 @@ private List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTag
ms.tags = (settings.getBoolean(SETTING_TAGS + suffix, defTags));
ms.notes = (settings.getBoolean(SETTING_NOTES + suffix, defNotes));
ms.atomic = (settings.getBoolean(SETTING_ATOMIC + suffix, defAtomic));
ms.verifySsl = (settings.getBoolean(SETTING_VERIFY_SSL + suffix, defVerifySsl));
ms.suffix = String.valueOf(count++);

results.add(ms);
Expand Down Expand Up @@ -239,6 +241,7 @@ private void updateSettings(List<MirrorSettings> mirrorSettings, Settings settin
values.put(SETTING_TAGS + ms.suffix, ms.tags);
values.put(SETTING_NOTES + ms.suffix, ms.notes);
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class MirrorSettings implements Serializable {
boolean tags;
boolean notes;
boolean atomic;
boolean verifySsl;
}
1 change: 1 addition & 0 deletions src/main/resources/i18n/stash-hook-mirror.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.notes.label=Notes (ie. +refs/notes/*:refs/notes/*)
mirror-repository-hook.atomic.label=Atomic
mirror-repository-hook.verifySsl.label=Verify SSL
5 changes: 5 additions & 0 deletions src/main/resources/static/mirror-repository-hook.soy
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
'id' : 'atomic' + $index,
'labelText': getText('mirror-repository-hook.atomic.label'),
'isChecked' : $config['atomic' + $index] != false
],
[
'id' : 'verifySsl' + $index,
'labelText': getText('mirror-repository-hook.verifySsl.label'),
'isChecked' : $config['verifySsl' + $index] != false
]
] /}
{/call}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public void testValidateForProject() {
verifyZeroInteractions(bucketedExecutor, errors, settings);
}


private PostRepositoryHookContext buildContext() {
Settings settings = defaultSettings();

Expand Down Expand Up @@ -266,6 +267,7 @@ private Settings defaultSettings() {
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_ATOMIC), eq(true))).thenReturn(true);
when(settings.getBoolean(eq(MirrorRepositoryHook.SETTING_VERIFY_SSL), eq(true))).thenReturn(true);

return settings;
}
Expand Down