Browse Source

Compatibility with 6

pull/73/head
Gonchik Tsymzhitov 5 years ago
parent
commit
478ea9df78
  1. 6
      pom.xml
  2. 29
      src/main/java/com/englishtown/bitbucket/hook/DefaultPasswordEncryptor.java
  3. 5
      src/main/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelper.java
  4. 13
      src/main/java/com/englishtown/bitbucket/hook/MirrorRepositoryHook.java
  5. 2
      src/main/resources/static/mirror-repository-hook.js
  6. 2
      src/test/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelperTest.java

6
pom.xml

@ -4,7 +4,7 @@
<groupId>com.englishtown</groupId>
<artifactId>stash-hook-mirror</artifactId>
<version>3.1.0-SNAPSHOT</version>
<version>3.1.1</version>
<organization>
<name>EF Learning Labs</name>
@ -29,9 +29,9 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<bitbucket.version>5.5.0</bitbucket.version>
<bitbucket.version>6.0.0</bitbucket.version>
<bitbucket.test.version>${bitbucket.version}</bitbucket.test.version>
<amps.version>6.3.17</amps.version>
<amps.version>6.3.21</amps.version>
</properties>
<dependencyManagement>

29
src/main/java/com/englishtown/bitbucket/hook/DefaultPasswordEncryptor.java

@ -6,6 +6,7 @@ import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
@ -51,9 +52,7 @@ public class DefaultPasswordEncryptor implements PasswordEncryptor {
Cipher cipher = getCipher(mode);
return cipher.doFinal(data);
} catch (IllegalBlockSizeException e) {
throw new RuntimeException(e);
} catch (BadPaddingException e) {
} catch (IllegalBlockSizeException | BadPaddingException e) {
throw new RuntimeException(e);
}
}
@ -68,11 +67,7 @@ public class DefaultPasswordEncryptor implements PasswordEncryptor {
cipher.init(mode, secretKey);
return cipher;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (NoSuchPaddingException e) {
throw new RuntimeException(e);
} catch (InvalidKeyException e) {
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException e) {
throw new RuntimeException(e);
}
@ -91,12 +86,8 @@ public class DefaultPasswordEncryptor implements PasswordEncryptor {
if (isEncrypted(password)) {
return password;
}
try {
byte[] encryptedData = runCipher(password.getBytes("UTF-8"), true);
return ENCRYPTED_PREFIX + Base64.getEncoder().encodeToString(encryptedData);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
byte[] encryptedData = runCipher(password.getBytes(StandardCharsets.UTF_8), true);
return ENCRYPTED_PREFIX + Base64.getEncoder().encodeToString(encryptedData);
}
@Override
@ -104,13 +95,9 @@ public class DefaultPasswordEncryptor implements PasswordEncryptor {
if (!isEncrypted(password)) {
return password;
}
try {
byte[] encryptedData = Base64.getDecoder().decode(password.substring(ENCRYPTED_PREFIX.length()));
byte[] clearData = runCipher(encryptedData, false);
return new String(clearData, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
byte[] encryptedData = Base64.getDecoder().decode(password.substring(ENCRYPTED_PREFIX.length()));
byte[] clearData = runCipher(encryptedData, false);
return new String(clearData, StandardCharsets.UTF_8);
}
}

5
src/main/java/com/englishtown/bitbucket/hook/DefaultSettingsReflectionHelper.java

@ -24,10 +24,7 @@ public class DefaultSettingsReflectionHelper implements SettingsReflectionHelper
field.setAccessible(true);
field.set(settings, values);
} catch (NoSuchFieldException e) {
throw new RuntimeException("Unable to encrypt the password. Check for an updated version of the mirror " +
"hook.", e);
} catch (IllegalAccessException e) {
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException("Unable to encrypt the password. Check for an updated version of the mirror " +
"hook.", e);
}

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

@ -63,7 +63,7 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
int attempts = propertiesService.getPluginProperty(PROP_ATTEMPTS, 5);
int threads = propertiesService.getPluginProperty(PROP_THREADS, 3);
pushExecutor = concurrencyService.getBucketedExecutor(getClass().getSimpleName(),
pushExecutor = concurrencyService.getBucketedExecutor(getClass().getCanonicalName(),
new BucketedExecutorSettings.Builder<>(MirrorRequest::toString, pushProcessor)
.batchSize(Integer.MAX_VALUE) // Coalesce all requests into a single push
.maxAttempts(attempts)
@ -120,18 +120,16 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
if (repository == null) {
return;
}
boolean ok = true;
logger.debug("MirrorRepositoryHook: validate started.");
try {
boolean ok = true;
logger.debug("MirrorRepositoryHook: validate started.");
List<MirrorSettings> mirrorSettings = getMirrorSettings(settings, false, false, false);
for (MirrorSettings ms : mirrorSettings) {
if (!validate(ms, errors)) {
ok = false;
}
}
logger.info("First step of validating is done.");
// If no errors, run the mirror command
if (ok) {
updateSettings(mirrorSettings, settings);
@ -155,7 +153,6 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
for (String key : allSettings.keySet()) {
if (key.startsWith(SETTING_MIRROR_REPO_URL)) {
String suffix = key.substring(SETTING_MIRROR_REPO_URL.length());
MirrorSettings ms = new MirrorSettings();
ms.mirrorRepoUrl = settings.getString(SETTING_MIRROR_REPO_URL + suffix, "");
ms.username = settings.getString(SETTING_USERNAME + suffix, "");
@ -173,7 +170,7 @@ public class MirrorRepositoryHook implements PostRepositoryHook<RepositoryHookRe
return results;
}
private void schedulePushes(Repository repository, List<MirrorSettings> list) {
private void schedulePushes(final Repository repository, List<MirrorSettings> list) {
list.forEach(settings -> pushExecutor.schedule(new MirrorRequest(repository, settings), 5L, TimeUnit.SECONDS));
}

2
src/main/resources/static/mirror-repository-hook.js

@ -1,7 +1,7 @@
define('et/hook/mirror', ['jquery', 'exports'], function ($, exports) {
exports.init = function (createSubView, createButton) {
$('#et-add-button').click(function () {
$('#et-add-button').click(function() {
try {
var currIndex, index = 0, name, html;

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

@ -48,7 +48,7 @@ public class DefaultSettingsReflectionHelperTest {
return (String) values.get(key);
}
@Nonnull
@Nullable
@Override
public String getString(@Nonnull String key, @Nonnull String defaultValue) {
return null;

Loading…
Cancel
Save