Skip to content

Commit 212a10e

Browse files
committed
[JENKINS-75857] Add method to set web hook credentials to BitbucketEndpoints
Add method to enable or disable hook management when register a new bitbucket endpoint. Set hook signature verification as Beta since they could be moved to different interface or provider with the develop of JENKINS-74913
1 parent 914c46d commit 212a10e

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@
216216
</dependency>
217217
</dependencies>
218218
</plugin>
219+
<plugin>
220+
<artifactId>maven-javadoc-plugin</artifactId>
221+
<version>${maven-javadoc-plugin.version}</version>
222+
<configuration>
223+
<tags>
224+
<tag>
225+
<name>apiNote</name>
226+
<placement>a</placement>
227+
<head>API Note:</head>
228+
</tag>
229+
</tags>
230+
</configuration>
231+
</plugin>
219232
</plugins>
220233
</pluginManagement>
221234
<plugins>

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/endpoint/BitbucketEndpoint.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import jenkins.model.Jenkins;
3535
import org.apache.commons.lang3.StringUtils;
3636
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
37+
import org.kohsuke.accmod.Restricted;
38+
import org.kohsuke.accmod.restrictions.Beta;
3739

3840
/**
3941
* The implementation represents an endpoint configuration to be used in
@@ -86,6 +88,15 @@ public interface BitbucketEndpoint extends Describable<BitbucketEndpoint> {
8688
*/
8789
boolean isManageHooks();
8890

91+
/**
92+
* Sets if Jenkins is supposed to auto-manage hooks for this end-point.
93+
*
94+
* @param manageHooks if Jenkins must auto-manage hooks registration.
95+
* @param credentialsId credentialsId to use with rights to create or update web
96+
* hook for Bitbucket repositories.
97+
*/
98+
void setManageHooks(boolean manageHooks, @CheckForNull String credentialsId);
99+
89100
/**
90101
* Returns the {@link StandardUsernamePasswordCredentials#getId()} of the
91102
* credentials to use for auto-management of hooks.
@@ -106,14 +117,30 @@ public interface BitbucketEndpoint extends Describable<BitbucketEndpoint> {
106117
@NonNull
107118
String getEndpointJenkinsRootURL();
108119

120+
/**
121+
* Returns if the should or not verify incoming web hook payload from this
122+
* endpoint.
123+
*
124+
* @apiNote This method is under development so could be moved to an interface
125+
* dedicated to webhooks implementation
126+
*
127+
* @return the {@code true} if the web hook implementation configured for this
128+
* endpoint should or not verify web hook payload that could be signed
129+
* or crypted.
130+
*/
131+
@Restricted(Beta.class)
109132
boolean isEnableHookSignature();
110133

111134
/**
112-
* The {@link StringCredentials#getId()} of the credentials to use to verify
113-
* the signature of hooks.
135+
* The {@link StringCredentials#getId()} of the credentials to use to verify the
136+
* signature of hooks.
137+
*
138+
* @apiNote This method is under development so could be moved to an interface
139+
* dedicated to webhooks implementation
114140
*
115141
* @return the configured credentials identifier to use
116142
*/
143+
@Restricted(Beta.class)
117144
@CheckForNull
118145
String getHookSignatureCredentialsId();
119146

@@ -133,10 +160,15 @@ default StandardCredentials credentials() {
133160
}
134161

135162
/**
136-
* Looks up the {@link StringCredentials} to use to verify the signature of hooks.
163+
* Looks up the {@link StringCredentials} to use to verify the signature of
164+
* hooks.
165+
*
166+
* @apiNote This method is under development so could be moved to an interface
167+
* dedicated to webhook provider
137168
*
138169
* @return the credentials or {@code null}.
139170
*/
171+
@Restricted(Beta.class)
140172
@CheckForNull
141173
default StringCredentials hookSignatureCredentials() {
142174
String credentialsId = Util.fixEmptyAndTrim(getHookSignatureCredentialsId());

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/endpoint/AbstractBitbucketEndpoint.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public abstract class AbstractBitbucketEndpoint implements BitbucketEndpoint {
5252
/**
5353
* {@code true} if and only if Jenkins is supposed to auto-manage hooks for this end-point.
5454
*/
55-
private final boolean manageHooks;
55+
private boolean manageHooks;
5656

5757
/**
5858
* The {@link StandardCredentials#getId()} of the credentials to use for auto-management of hooks.
5959
*/
6060
@CheckForNull
61-
private final String credentialsId;
61+
private String credentialsId;
6262

6363
/**
6464
* {@code true} if and only if Jenkins have to verify the signature of all incoming hooks.
@@ -95,6 +95,12 @@ public abstract class AbstractBitbucketEndpoint implements BitbucketEndpoint {
9595
this.hookSignatureCredentialsId = enableHookSignature ? fixEmptyAndTrim(hookSignatureCredentialsId) : null;
9696
}
9797

98+
@Override
99+
public void setManageHooks(boolean manageHooks, String credentialsId) {
100+
this.manageHooks = manageHooks && StringUtils.isNotBlank(credentialsId);
101+
this.credentialsId = manageHooks ? fixEmptyAndTrim(credentialsId) : null;
102+
}
103+
98104
/**
99105
* The URL of this endpoint.
100106
*
@@ -235,7 +241,7 @@ public final String getCredentialsId() {
235241
@Override
236242
@CheckForNull
237243
public StandardCredentials credentials() {
238-
return BitbucketCredentialsUtils.lookupCredentials(Jenkins.get(), getServerUrl(), credentialsId, StandardCredentials.class);
244+
return BitbucketCredentialsUtils.lookupCredentials(Jenkins.get(), getServerURL(), credentialsId, StandardCredentials.class);
239245
}
240246

241247
/**
@@ -246,7 +252,7 @@ public StandardCredentials credentials() {
246252
@Override
247253
@CheckForNull
248254
public StringCredentials hookSignatureCredentials() {
249-
return BitbucketCredentialsUtils.lookupCredentials(Jenkins.get(), getServerUrl(), hookSignatureCredentialsId, StringCredentials.class);
255+
return BitbucketCredentialsUtils.lookupCredentials(Jenkins.get(), getServerURL(), hookSignatureCredentialsId, StringCredentials.class);
250256
}
251257

252258
/**

0 commit comments

Comments
 (0)