Skip to content
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
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.englishtown</groupId>
Expand Down Expand Up @@ -31,7 +32,7 @@

<bitbucket.version>5.5.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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand Down Expand Up @@ -51,9 +52,7 @@ protected byte[] runCipher(byte[] data, boolean encrypt) {
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);
}
}
Expand All @@ -68,11 +67,7 @@ private Cipher getCipher(int mode) {
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);
}

Expand All @@ -91,26 +86,18 @@ public String encrypt(String password) {
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
public String decrypt(String password) {
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ public void set(Map<String, Object> values, Settings settings) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public MirrorRepositoryHook(ConcurrencyService concurrencyService,
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)
Expand Down Expand Up @@ -120,18 +120,15 @@ public Repository visit(@Nonnull RepositoryScope scope) {
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;
}
}

// If no errors, run the mirror command
if (ok) {
updateSettings(mirrorSettings, settings);
Expand All @@ -155,7 +152,6 @@ private List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTag
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, "");
Expand All @@ -173,7 +169,7 @@ private List<MirrorSettings> getMirrorSettings(Settings settings, boolean defTag
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));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/mirror-repository-hook.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String getString(@Nonnull String key) {
return (String) values.get(key);
}

@Nonnull
@Nullable
@Override
public String getString(@Nonnull String key, @Nonnull String defaultValue) {
return null;
Expand Down