From ec83352a2f7098af0e59c0c9ff914e30f3b0a045 Mon Sep 17 00:00:00 2001 From: Tomas Bjerre Date: Wed, 5 Apr 2017 20:10:26 +0200 Subject: [PATCH] Adding optional schema to proxy configuration #211 --- CHANGELOG.md | 2 +- .../java/se/bjurr/prnfb/http/UrlInvoker.java | 13 +- .../PrnfbPullRequestEventListener.java | 1 + .../presentation/dto/NotificationDTO.java | 146 ++++++++++-------- .../se/bjurr/prnfb/service/PrnfbVariable.java | 1 + .../prnfb/settings/PrnfbNotification.java | 6 + .../settings/PrnfbNotificationBuilder.java | 11 ++ .../transformer/NotificationTransformer.java | 2 + src/main/resources/admin.vm | 13 ++ 9 files changed, 129 insertions(+), 66 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56a80a98..13b0f390 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Changelog of Pull Request Notifier for Bitbucket. ### No issue doc - [aaab4df796efde4](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/aaab4df796efde4) Tomas Bjerre *2017-03-25 08:01:32* + [34e16b98c5fde82](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/34e16b98c5fde82) Tomas Bjerre *2017-03-25 08:02:02* ## 2.61 ### GitHub [#208](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/208) Injection URL does not allow variables diff --git a/src/main/java/se/bjurr/prnfb/http/UrlInvoker.java b/src/main/java/se/bjurr/prnfb/http/UrlInvoker.java index 19e1621d..d2d889fa 100644 --- a/src/main/java/se/bjurr/prnfb/http/UrlInvoker.java +++ b/src/main/java/se/bjurr/prnfb/http/UrlInvoker.java @@ -88,6 +88,7 @@ public static UrlInvoker urlInvoker() { private Optional proxyHost = absent(); private Optional proxyPassword = absent(); private Optional proxyPort = absent(); + private Optional proxySchema = absent(); private Optional proxyUser = absent(); private HttpResponse response; @@ -134,6 +135,10 @@ public Optional getProxyPort() { return this.proxyPort; } + public Optional getProxySchema() { + return proxySchema; + } + public Optional getProxyUser() { return this.proxyUser; } @@ -230,6 +235,11 @@ public UrlInvoker withProxyPort(Integer proxyPort) { return this; } + public UrlInvoker withProxySchema(Optional proxySchema) { + this.proxySchema = proxySchema; + return this; + } + public UrlInvoker withProxyServer(Optional proxyHost) { this.proxyHost = proxyHost; return this; @@ -314,7 +324,8 @@ HttpClientBuilder configureProxy(HttpClientBuilder builder) { } builder.useSystemProperties(); - builder.setProxy(new HttpHost(this.proxyHost.get(), this.proxyPort.get())); + builder.setProxy( + new HttpHost(this.proxyHost.get(), this.proxyPort.get(), this.proxySchema.orNull())); builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); return builder; } diff --git a/src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java b/src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java index f0bb2c6a..9c3494c3 100644 --- a/src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java +++ b/src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java @@ -262,6 +262,7 @@ public NotificationResponse notify( urlInvoker // .withProxyServer(notification.getProxyServer()) // .withProxyPort(notification.getProxyPort()) // + .withProxySchema(notification.getProxySchema()) // .withProxyUser(notification.getProxyUser()) // .withProxyPassword(notification.getProxyPassword()) // .shouldAcceptAnyCertificate(shouldAcceptAnyCertificate)); diff --git a/src/main/java/se/bjurr/prnfb/presentation/dto/NotificationDTO.java b/src/main/java/se/bjurr/prnfb/presentation/dto/NotificationDTO.java index 37fbd137..ccc6b4e4 100644 --- a/src/main/java/se/bjurr/prnfb/presentation/dto/NotificationDTO.java +++ b/src/main/java/se/bjurr/prnfb/presentation/dto/NotificationDTO.java @@ -31,6 +31,7 @@ public class NotificationDTO implements Comparable, Restricted private String proxyPassword; private Integer proxyPort; private String proxyServer; + private String proxySchema; private String proxyUser; private String repositorySlug; private TRIGGER_IF_MERGE triggerIfCanMerge; @@ -62,143 +63,153 @@ public boolean equals(Object obj) { return false; } NotificationDTO other = (NotificationDTO) obj; - if (this.filterRegexp == null) { + if (filterRegexp == null) { if (other.filterRegexp != null) { return false; } - } else if (!this.filterRegexp.equals(other.filterRegexp)) { + } else if (!filterRegexp.equals(other.filterRegexp)) { return false; } - if (this.filterString == null) { + if (filterString == null) { if (other.filterString != null) { return false; } - } else if (!this.filterString.equals(other.filterString)) { + } else if (!filterString.equals(other.filterString)) { return false; } - if (this.headers == null) { + if (headers == null) { if (other.headers != null) { return false; } - } else if (!this.headers.equals(other.headers)) { + } else if (!headers.equals(other.headers)) { return false; } - if (this.injectionUrl == null) { + if (injectionUrl == null) { if (other.injectionUrl != null) { return false; } - } else if (!this.injectionUrl.equals(other.injectionUrl)) { + } else if (!injectionUrl.equals(other.injectionUrl)) { return false; } - if (this.injectionUrlRegexp == null) { + if (injectionUrlRegexp == null) { if (other.injectionUrlRegexp != null) { return false; } - } else if (!this.injectionUrlRegexp.equals(other.injectionUrlRegexp)) { + } else if (!injectionUrlRegexp.equals(other.injectionUrlRegexp)) { return false; } - if (this.method != other.method) { + if (method != other.method) { return false; } - if (this.name == null) { + if (name == null) { if (other.name != null) { return false; } - } else if (!this.name.equals(other.name)) { + } else if (!name.equals(other.name)) { return false; } - if (this.password == null) { + if (password == null) { if (other.password != null) { return false; } - } else if (!this.password.equals(other.password)) { + } else if (!password.equals(other.password)) { return false; } - if (this.postContent == null) { + if (postContent == null) { if (other.postContent != null) { return false; } - } else if (!this.postContent.equals(other.postContent)) { + } else if (!postContent.equals(other.postContent)) { return false; } - if (this.projectKey == null) { + if (postContentEncoding != other.postContentEncoding) { + return false; + } + if (projectKey == null) { if (other.projectKey != null) { return false; } - } else if (!this.projectKey.equals(other.projectKey)) { + } else if (!projectKey.equals(other.projectKey)) { return false; } - if (this.proxyPassword == null) { + if (proxyPassword == null) { if (other.proxyPassword != null) { return false; } - } else if (!this.proxyPassword.equals(other.proxyPassword)) { + } else if (!proxyPassword.equals(other.proxyPassword)) { return false; } - if (this.proxyPort == null) { + if (proxyPort == null) { if (other.proxyPort != null) { return false; } - } else if (!this.proxyPort.equals(other.proxyPort)) { + } else if (!proxyPort.equals(other.proxyPort)) { + return false; + } + if (proxySchema == null) { + if (other.proxySchema != null) { + return false; + } + } else if (!proxySchema.equals(other.proxySchema)) { return false; } - if (this.proxyServer == null) { + if (proxyServer == null) { if (other.proxyServer != null) { return false; } - } else if (!this.proxyServer.equals(other.proxyServer)) { + } else if (!proxyServer.equals(other.proxyServer)) { return false; } - if (this.proxyUser == null) { + if (proxyUser == null) { if (other.proxyUser != null) { return false; } - } else if (!this.proxyUser.equals(other.proxyUser)) { + } else if (!proxyUser.equals(other.proxyUser)) { return false; } - if (this.repositorySlug == null) { + if (repositorySlug == null) { if (other.repositorySlug != null) { return false; } - } else if (!this.repositorySlug.equals(other.repositorySlug)) { + } else if (!repositorySlug.equals(other.repositorySlug)) { return false; } - if (this.triggerIfCanMerge != other.triggerIfCanMerge) { + if (triggerIfCanMerge != other.triggerIfCanMerge) { return false; } - if (this.triggerIgnoreStateList == null) { + if (triggerIgnoreStateList == null) { if (other.triggerIgnoreStateList != null) { return false; } - } else if (!this.triggerIgnoreStateList.equals(other.triggerIgnoreStateList)) { + } else if (!triggerIgnoreStateList.equals(other.triggerIgnoreStateList)) { return false; } - if (this.triggers == null) { + if (triggers == null) { if (other.triggers != null) { return false; } - } else if (!this.triggers.equals(other.triggers)) { + } else if (!triggers.equals(other.triggers)) { return false; } - if (this.url == null) { + if (url == null) { if (other.url != null) { return false; } - } else if (!this.url.equals(other.url)) { + } else if (!url.equals(other.url)) { return false; } - if (this.user == null) { + if (user == null) { if (other.user != null) { return false; } - } else if (!this.user.equals(other.user)) { + } else if (!user.equals(other.user)) { return false; } - if (this.uuid == null) { + if (uuid == null) { if (other.uuid != null) { return false; } - } else if (!this.uuid.equals(other.uuid)) { + } else if (!uuid.equals(other.uuid)) { return false; } return true; @@ -294,31 +305,30 @@ public UUID getUuid() { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (this.filterRegexp == null ? 0 : this.filterRegexp.hashCode()); - result = prime * result + (this.filterString == null ? 0 : this.filterString.hashCode()); - result = prime * result + (this.headers == null ? 0 : this.headers.hashCode()); - result = prime * result + (this.injectionUrl == null ? 0 : this.injectionUrl.hashCode()); + result = prime * result + (filterRegexp == null ? 0 : filterRegexp.hashCode()); + result = prime * result + (filterString == null ? 0 : filterString.hashCode()); + result = prime * result + (headers == null ? 0 : headers.hashCode()); + result = prime * result + (injectionUrl == null ? 0 : injectionUrl.hashCode()); + result = prime * result + (injectionUrlRegexp == null ? 0 : injectionUrlRegexp.hashCode()); + result = prime * result + (method == null ? 0 : method.hashCode()); + result = prime * result + (name == null ? 0 : name.hashCode()); + result = prime * result + (password == null ? 0 : password.hashCode()); + result = prime * result + (postContent == null ? 0 : postContent.hashCode()); + result = prime * result + (postContentEncoding == null ? 0 : postContentEncoding.hashCode()); + result = prime * result + (projectKey == null ? 0 : projectKey.hashCode()); + result = prime * result + (proxyPassword == null ? 0 : proxyPassword.hashCode()); + result = prime * result + (proxyPort == null ? 0 : proxyPort.hashCode()); + result = prime * result + (proxySchema == null ? 0 : proxySchema.hashCode()); + result = prime * result + (proxyServer == null ? 0 : proxyServer.hashCode()); + result = prime * result + (proxyUser == null ? 0 : proxyUser.hashCode()); + result = prime * result + (repositorySlug == null ? 0 : repositorySlug.hashCode()); + result = prime * result + (triggerIfCanMerge == null ? 0 : triggerIfCanMerge.hashCode()); result = - prime * result + (this.injectionUrlRegexp == null ? 0 : this.injectionUrlRegexp.hashCode()); - result = prime * result + (this.method == null ? 0 : this.method.hashCode()); - result = prime * result + (this.name == null ? 0 : this.name.hashCode()); - result = prime * result + (this.password == null ? 0 : this.password.hashCode()); - result = prime * result + (this.postContent == null ? 0 : this.postContent.hashCode()); - result = prime * result + (this.projectKey == null ? 0 : this.projectKey.hashCode()); - result = prime * result + (this.proxyPassword == null ? 0 : this.proxyPassword.hashCode()); - result = prime * result + (this.proxyPort == null ? 0 : this.proxyPort.hashCode()); - result = prime * result + (this.proxyServer == null ? 0 : this.proxyServer.hashCode()); - result = prime * result + (this.proxyUser == null ? 0 : this.proxyUser.hashCode()); - result = prime * result + (this.repositorySlug == null ? 0 : this.repositorySlug.hashCode()); - result = - prime * result + (this.triggerIfCanMerge == null ? 0 : this.triggerIfCanMerge.hashCode()); - result = - prime * result - + (this.triggerIgnoreStateList == null ? 0 : this.triggerIgnoreStateList.hashCode()); - result = prime * result + (this.triggers == null ? 0 : this.triggers.hashCode()); - result = prime * result + (this.url == null ? 0 : this.url.hashCode()); - result = prime * result + (this.user == null ? 0 : this.user.hashCode()); - result = prime * result + (this.uuid == null ? 0 : this.uuid.hashCode()); + prime * result + (triggerIgnoreStateList == null ? 0 : triggerIgnoreStateList.hashCode()); + result = prime * result + (triggers == null ? 0 : triggers.hashCode()); + result = prime * result + (url == null ? 0 : url.hashCode()); + result = prime * result + (user == null ? 0 : user.hashCode()); + result = prime * result + (uuid == null ? 0 : uuid.hashCode()); return result; } @@ -409,4 +419,12 @@ public void setUuid(UUID uuid) { public ENCODE_FOR getPostContentEncoding() { return postContentEncoding; } + + public void setProxySchema(String proxySchema) { + this.proxySchema = proxySchema; + } + + public String getProxySchema() { + return proxySchema; + } } diff --git a/src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java b/src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java index 83339442..a0e7192a 100644 --- a/src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java +++ b/src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java @@ -128,6 +128,7 @@ public String resolve( .withMethod(GET) // .withProxyServer(prnfbNotification.getProxyServer()) // .withProxyPort(prnfbNotification.getProxyPort()) // + .withProxySchema(prnfbNotification.getProxySchema()) // .withProxyUser(prnfbNotification.getProxyUser()) // .withProxyPassword(prnfbNotification.getProxyPassword()) // .appendBasicAuth(prnfbNotification) // diff --git a/src/main/java/se/bjurr/prnfb/settings/PrnfbNotification.java b/src/main/java/se/bjurr/prnfb/settings/PrnfbNotification.java index f5d863ef..fe34195e 100644 --- a/src/main/java/se/bjurr/prnfb/settings/PrnfbNotification.java +++ b/src/main/java/se/bjurr/prnfb/settings/PrnfbNotification.java @@ -47,12 +47,14 @@ public class PrnfbNotification implements HasUuid, Restricted { private final String user; private final UUID uuid; private final ENCODE_FOR postContentEncoding; + private final String proxySchema; public PrnfbNotification(PrnfbNotificationBuilder builder) throws ValidationException { this.uuid = firstNonNull(builder.getUUID(), randomUUID()); this.proxyUser = emptyToNull(nullToEmpty(builder.getProxyUser()).trim()); this.proxyPassword = emptyToNull(nullToEmpty(builder.getProxyPassword()).trim()); this.proxyServer = emptyToNull(nullToEmpty(builder.getProxyServer()).trim()); + this.proxySchema = emptyToNull(nullToEmpty(builder.getProxySchema()).trim()); this.proxyPort = builder.getProxyPort(); this.headers = checkNotNull(builder.getHeaders()); this.postContent = emptyToNull(nullToEmpty(builder.getPostContent()).trim()); @@ -299,6 +301,10 @@ public Integer getProxyPort() { return this.proxyPort; } + public Optional getProxySchema() { + return fromNullable(this.proxySchema); + } + public Optional getProxyServer() { return fromNullable(this.proxyServer); } diff --git a/src/main/java/se/bjurr/prnfb/settings/PrnfbNotificationBuilder.java b/src/main/java/se/bjurr/prnfb/settings/PrnfbNotificationBuilder.java index bd99e079..1f7d9fc4 100644 --- a/src/main/java/se/bjurr/prnfb/settings/PrnfbNotificationBuilder.java +++ b/src/main/java/se/bjurr/prnfb/settings/PrnfbNotificationBuilder.java @@ -37,6 +37,7 @@ public static PrnfbNotificationBuilder prnfbNotificationBuilder(PrnfbNotificatio b.proxyUser = from.getProxyUser().orNull(); b.proxyPassword = from.getProxyPassword().orNull(); b.proxyServer = from.getProxyServer().orNull(); + b.proxySchema = from.getProxySchema().orNull(); b.proxyPort = from.getProxyPort(); b.name = from.getName(); b.injectionUrl = from.getInjectionUrl().orNull(); @@ -68,6 +69,7 @@ public static PrnfbNotificationBuilder prnfbNotificationBuilder(PrnfbNotificatio private String user; private UUID uuid; private ENCODE_FOR postContentEncoding; + private String proxySchema; private PrnfbNotificationBuilder() { this.uuid = randomUUID(); @@ -133,6 +135,10 @@ public String getProxyServer() { return this.proxyServer; } + public String getProxySchema() { + return proxySchema; + } + public String getProxyUser() { return this.proxyUser; } @@ -294,4 +300,9 @@ public PrnfbNotificationBuilder withUuid(UUID uuid) { this.uuid = uuid; return this; } + + public PrnfbNotificationBuilder withProxySchema(String proxySchema) { + this.proxySchema = proxySchema; + return this; + } } diff --git a/src/main/java/se/bjurr/prnfb/transformer/NotificationTransformer.java b/src/main/java/se/bjurr/prnfb/transformer/NotificationTransformer.java index 42bdc3d2..6168407e 100644 --- a/src/main/java/se/bjurr/prnfb/transformer/NotificationTransformer.java +++ b/src/main/java/se/bjurr/prnfb/transformer/NotificationTransformer.java @@ -34,6 +34,7 @@ public static NotificationDTO toNotificationDto(PrnfbNotification from) { to.setProxyPassword(from.getProxyPassword().orNull()); to.setProxyPort(from.getProxyPort()); to.setProxyServer(from.getProxyServer().orNull()); + to.setProxySchema(from.getProxySchema().orNull()); to.setProxyUser(from.getProxyUser().orNull()); to.setTriggerIfCanMerge(from.getTriggerIfCanMerge()); to.setTriggerIgnoreStateList(toPullRequestStateStrings(from.getTriggerIgnoreStateList())); @@ -70,6 +71,7 @@ public static PrnfbNotification toPrnfbNotification(NotificationDTO from) .withProxyPassword(from.getProxyPassword()) // .withProxyPort(from.getProxyPort()) // .withProxyServer(from.getProxyServer()) // + .withProxySchema(from.getProxySchema()) // .withProxyUser(from.getProxyUser()) // .setTriggers(toPrnfbPullRequestActions(from.getTriggers())) // .withTriggerIfCanMerge(from.getTriggerIfCanMerge()) // diff --git a/src/main/resources/admin.vm b/src/main/resources/admin.vm index dab7b538..f4fed6bc 100644 --- a/src/main/resources/admin.vm +++ b/src/main/resources/admin.vm @@ -511,6 +511,19 @@
+
+ + Schema + +
+ +
+
+ +
+

URL