-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-14029 - BitBucket Registry Client
- Loading branch information
1 parent
ddef74b
commit d3ccb2d
Showing
9 changed files
with
932 additions
and
1 deletion.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-atlassian-bundle</artifactId> | ||
<version>2.1.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>nifi-atlassian-extensions</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-utils</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-git-flow-registry</artifactId> | ||
<version>2.1.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-oauth2-provider-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-web-client-provider-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-web-client-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
49 changes: 49 additions & 0 deletions
49
...nsions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitBucketAuthenticationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.nifi.atlassian.bitbucket; | ||
|
||
import org.apache.nifi.components.DescribedValue; | ||
|
||
public enum BitBucketAuthenticationType implements DescribedValue { | ||
BASIC_AUTH("Basic Auth", "Username and App Password"), | ||
ACCESS_TOKEN("Access Token", "Repository, Project or Workspace Token"), | ||
OAUTH2("OAuth 2.0", "OAuth 2.0 with an OAuth Consumer"); | ||
|
||
private final String displayName; | ||
private final String description; | ||
|
||
BitBucketAuthenticationType(final String displayName, final String description) { | ||
this.displayName = displayName; | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return name(); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return displayName; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return description; | ||
} | ||
} |
163 changes: 163 additions & 0 deletions
163
...nsions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitBucketFlowRegistryClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.nifi.atlassian.bitbucket; | ||
|
||
import org.apache.nifi.annotation.documentation.CapabilityDescription; | ||
import org.apache.nifi.annotation.documentation.Tags; | ||
import org.apache.nifi.components.PropertyDescriptor; | ||
import org.apache.nifi.oauth2.OAuth2AccessTokenProvider; | ||
import org.apache.nifi.processor.util.StandardValidators; | ||
import org.apache.nifi.registry.flow.FlowRegistryClientConfigurationContext; | ||
import org.apache.nifi.registry.flow.FlowRegistryException; | ||
import org.apache.nifi.registry.flow.git.AbstractGitFlowRegistryClient; | ||
import org.apache.nifi.registry.flow.git.client.GitRepositoryClient; | ||
import org.apache.nifi.web.client.provider.api.WebClientServiceProvider; | ||
|
||
import java.util.List; | ||
|
||
@Tags({ "atlassian", "bitbucket", "registry", "flow" }) | ||
@CapabilityDescription("Flow Registry Client that uses the BitBucket REST API to version control flows in a BitBucket Repository.") | ||
public class BitBucketFlowRegistryClient extends AbstractGitFlowRegistryClient { | ||
|
||
static final PropertyDescriptor BITBUCKET_API_URL = new PropertyDescriptor.Builder() | ||
.name("BitBucket API Instance") | ||
.description("The instance of the BitBucket API") | ||
.addValidator(StandardValidators.NON_BLANK_VALIDATOR) | ||
.defaultValue("api.bitbucket.org") | ||
.required(true) | ||
.build(); | ||
|
||
static final PropertyDescriptor BITBUCKET_API_VERSION = new PropertyDescriptor.Builder() | ||
.name("BitBucket API Version") | ||
.description("The version of the BitBucket API") | ||
.defaultValue("2.0") | ||
.addValidator(StandardValidators.NON_BLANK_VALIDATOR) | ||
.required(true) | ||
.build(); | ||
|
||
static final PropertyDescriptor WORKSPACE_NAME = new PropertyDescriptor.Builder() | ||
.name("Workspace Name") | ||
.description("The name of the workspace that contains the repository to connect to") | ||
.addValidator(StandardValidators.NON_BLANK_VALIDATOR) | ||
.required(true) | ||
.build(); | ||
|
||
static final PropertyDescriptor REPOSITORY_NAME = new PropertyDescriptor.Builder() | ||
.name("Repository Name") | ||
.description("The name of the repository") | ||
.addValidator(StandardValidators.NON_BLANK_VALIDATOR) | ||
.required(true) | ||
.build(); | ||
|
||
static final PropertyDescriptor AUTHENTICATION_TYPE = new PropertyDescriptor.Builder() | ||
.name("Authentication Type") | ||
.description("The type of authentication to use for accessing BitBucket") | ||
.allowableValues(BitBucketAuthenticationType.class) | ||
.defaultValue(BitBucketAuthenticationType.ACCESS_TOKEN) | ||
.required(true) | ||
.build(); | ||
|
||
static final PropertyDescriptor ACCESS_TOKEN = new PropertyDescriptor.Builder() | ||
.name("Access Token") | ||
.description("The access token to use for authentication") | ||
.addValidator(StandardValidators.NON_BLANK_VALIDATOR) | ||
.required(true) | ||
.sensitive(true) | ||
.dependsOn(AUTHENTICATION_TYPE, BitBucketAuthenticationType.ACCESS_TOKEN) | ||
.build(); | ||
|
||
static final PropertyDescriptor USERNAME = new PropertyDescriptor.Builder() | ||
.name("Username") | ||
.description("The username to use for authentication") | ||
.addValidator(StandardValidators.NON_BLANK_VALIDATOR) | ||
.required(true) | ||
.sensitive(false) | ||
.dependsOn(AUTHENTICATION_TYPE, BitBucketAuthenticationType.BASIC_AUTH) | ||
.build(); | ||
|
||
static final PropertyDescriptor APP_PASSWORD = new PropertyDescriptor.Builder() | ||
.name("App Password") | ||
.description("The App Password to use for authentication") | ||
.addValidator(StandardValidators.NON_BLANK_VALIDATOR) | ||
.required(true) | ||
.sensitive(true) | ||
.dependsOn(AUTHENTICATION_TYPE, BitBucketAuthenticationType.BASIC_AUTH) | ||
.build(); | ||
|
||
static final PropertyDescriptor OAUTH_TOKEN_PROVIDER = new PropertyDescriptor.Builder() | ||
.name("OAuth2 Access Token Provider") | ||
.description("Service providing OAuth2 Access Tokens for authentication") | ||
.identifiesControllerService(OAuth2AccessTokenProvider.class) | ||
.required(true) | ||
.dependsOn(AUTHENTICATION_TYPE, BitBucketAuthenticationType.OAUTH2) | ||
.build(); | ||
|
||
static final PropertyDescriptor WEBCLIENT_SERVICE = new PropertyDescriptor.Builder() | ||
.name("Web Client Service") | ||
.description("The Web Client Service to use for communicating with BitBucket") | ||
.required(true) | ||
.identifiesControllerService(WebClientServiceProvider.class) | ||
.build(); | ||
|
||
static final List<PropertyDescriptor> PROPERTY_DESCRIPTORS = List.of( | ||
WEBCLIENT_SERVICE, | ||
BITBUCKET_API_URL, | ||
BITBUCKET_API_VERSION, | ||
WORKSPACE_NAME, | ||
REPOSITORY_NAME, | ||
AUTHENTICATION_TYPE, | ||
ACCESS_TOKEN, | ||
USERNAME, | ||
APP_PASSWORD, | ||
OAUTH_TOKEN_PROVIDER); | ||
|
||
@Override | ||
protected List<PropertyDescriptor> createPropertyDescriptors() { | ||
return PROPERTY_DESCRIPTORS; | ||
} | ||
|
||
@Override | ||
protected GitRepositoryClient createRepositoryClient(final FlowRegistryClientConfigurationContext context) throws FlowRegistryException { | ||
return BitBucketRepositoryClient.builder() | ||
.clientId(getIdentifier()) | ||
.apiUrl(context.getProperty(BITBUCKET_API_URL).getValue()) | ||
.apiVersion(context.getProperty(BITBUCKET_API_VERSION).getValue()) | ||
.workspace(context.getProperty(WORKSPACE_NAME).getValue()) | ||
.repoName(context.getProperty(REPOSITORY_NAME).getValue()) | ||
.repoPath(context.getProperty(REPOSITORY_PATH).getValue()) | ||
.authenticationType(context.getProperty(AUTHENTICATION_TYPE).asAllowableValue(BitBucketAuthenticationType.class)) | ||
.accessToken(context.getProperty(ACCESS_TOKEN).evaluateAttributeExpressions().getValue()) | ||
.username(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue()) | ||
.appPassword(context.getProperty(APP_PASSWORD).evaluateAttributeExpressions().getValue()) | ||
.oauthService(context.getProperty(OAUTH_TOKEN_PROVIDER).asControllerService(OAuth2AccessTokenProvider.class)) | ||
.webClient(context.getProperty(WEBCLIENT_SERVICE).asControllerService(WebClientServiceProvider.class)) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public boolean isStorageLocationApplicable(FlowRegistryClientConfigurationContext context, String location) { | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
@Override | ||
protected String getStorageLocation(GitRepositoryClient repositoryClient) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
} |
Oops, something went wrong.