Skip to content

Commit 4250b6a

Browse files
author
Gorbasch
committed
update nifi dependency to 1.27.0
1 parent 1eda083 commit 4250b6a

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ Fortunately Apache NiFi already ships with a couple of processors which provide
55
This is why we created this custom controller service which adds an alternative oauth2 access token provider besides the [StandardOauth2AccessTokenProvider](https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-oauth2-provider-nar/1.20.0/org.apache.nifi.oauth2.StandardOauth2AccessTokenProvider/index.html). It provides the access token generated by the [GCPCredentialsControllerService](https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-gcp-nar/1.19.1/org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsControllerService/index.html) service for the [InvokeHTTP](https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.17.0/org.apache.nifi.processors.standard.InvokeHTTP/index.html) processor. This way it can be used to generate requests towards any Google API with https support.
66

77
## Installation
8+
89
1. Download the latest .nar file from the [release page](https://github.com/Digital-Loop/nifi-gcp-oauth2-access-token/releases).
9-
2. Copy it to the `lib` directory of your Apache NiFi deployment.
10+
2. Copy it to the `extensions` directory of your Apache NiFi deployment.
1011

1112
## Manual Build
13+
1214
```
1315
mvn clean install
14-
cp nifi-gcp-oauth2-provider-nar/target/nifi-gcp-oauth2-provider-nar-1.0.0.nar $NIFI_HOME/lib
16+
cp nifi-gcp-oauth2-provider-nar/target/nifi-gcp-oauth2-provider-nar-1.0.0.nar $NIFI_HOME/extensions
1517
```
1618

1719
## Usage
20+
1821
1. Create and configure a [GCPCredentialsControllerService](https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-gcp-nar/1.19.1/org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsControllerService/index.html) controller service.
1922
2. Create a GCPOauth2AccessTokenProvider controller service (provided by this module).
2023
3. You can add one or multiple [scopes](https://developers.google.com/identity/protocols/oauth2/scopes) if required (the required scopes are mentioned in the corresponding Google API documentation).
@@ -23,5 +26,6 @@ cp nifi-gcp-oauth2-provider-nar/target/nifi-gcp-oauth2-provider-nar-1.0.0.nar $N
2326
6. Configure http method, http url and headers as explained by the corresponding API documentation (the flow file content is used as the request body).
2427

2528
## Examples
29+
2630
1. [Search Console API](./examples/google-search-console/README.md)
2731
2. [Business Profile API](./examples/google-business-profile/README.md)

nifi-gcp-oauth2-provider-nar/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<dependency>
4040
<groupId>org.apache.nifi</groupId>
4141
<artifactId>nifi-gcp-nar</artifactId>
42-
<version>1.20.0</version>
42+
<version>1.27.0</version>
4343
<type>nar</type>
4444
</dependency>
4545
</dependencies>

nifi-gcp-oauth2-provider/pom.xml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,43 @@
3434
<dependency>
3535
<groupId>org.apache.nifi</groupId>
3636
<artifactId>nifi-utils</artifactId>
37-
<version>1.20.0</version>
37+
<version>1.27.0</version>
3838
<scope>provided</scope>
3939
</dependency>
4040
<dependency>
4141
<groupId>org.apache.nifi</groupId>
4242
<artifactId>nifi-gcp-services-api</artifactId>
43-
<version>1.20.0</version>
43+
<version>1.27.0</version>
4444
<scope>provided</scope>
4545
</dependency>
4646
<dependency>
4747
<groupId>org.apache.nifi</groupId>
4848
<artifactId>nifi-gcp-processors</artifactId>
49-
<version>1.20.0</version>
49+
<version>1.27.0</version>
5050
<scope>provided</scope>
5151
</dependency>
5252
<dependency>
5353
<groupId>org.apache.nifi</groupId>
5454
<artifactId>nifi-oauth2-provider-api</artifactId>
55-
<version>1.20.0</version>
55+
<version>1.27.0</version>
5656
<scope>provided</scope>
5757
</dependency>
5858
<dependency>
5959
<groupId>org.apache.nifi</groupId>
6060
<artifactId>nifi-oauth2-provider-service</artifactId>
61-
<version>1.20.0</version>
61+
<version>1.27.0</version>
6262
<scope>test</scope>
6363
</dependency>
6464
<dependency>
6565
<groupId>org.apache.nifi</groupId>
6666
<artifactId>nifi-mock</artifactId>
67-
<version>1.20.0</version>
68-
<scope>test</scope>
69-
</dependency>
70-
<dependency>
71-
<groupId>org.slf4j</groupId>
72-
<artifactId>slf4j-simple</artifactId>
67+
<version>1.27.0</version>
7368
<scope>test</scope>
7469
</dependency>
7570
<dependency>
7671
<groupId>org.junit.jupiter</groupId>
7772
<artifactId>junit-jupiter-api</artifactId>
7873
<scope>test</scope>
7974
</dependency>
80-
<dependency>
81-
<groupId>org.junit.jupiter</groupId>
82-
<artifactId>junit-jupiter-engine</artifactId>
83-
<scope>test</scope>
84-
</dependency>
8575
</dependencies>
8676
</project>

nifi-gcp-oauth2-provider/src/main/java/com/dloop/nifi/gcp/oauth2/GCPOauth2AccessTokenProvider.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,17 @@
3939

4040
@Tags({ "gcp", "oauth2", "provider", "authorization", "access token", "http" })
4141
@CapabilityDescription("Provides OAuth 2.0 access tokens for Google APIs.")
42-
@SeeAlso({OAuth2AccessTokenProvider.class, GCPCredentialsService.class})
42+
@SeeAlso({ OAuth2AccessTokenProvider.class, GCPCredentialsService.class })
4343
public class GCPOauth2AccessTokenProvider extends AbstractControllerService implements OAuth2AccessTokenProvider {
44+
public static final PropertyDescriptor PROJECT_ID = new PropertyDescriptor.Builder()
45+
.name("project-id")
46+
.displayName("Project ID")
47+
.description(
48+
"Creates a credential with the provided quota project.")
49+
.required(false)
50+
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
51+
.build();
52+
4453
public static final PropertyDescriptor SCOPE = new PropertyDescriptor.Builder()
4554
.name("scope")
4655
.displayName("Scope")
@@ -54,7 +63,7 @@ public class GCPOauth2AccessTokenProvider extends AbstractControllerService impl
5463
.name("delegate")
5564
.displayName("Delegate")
5665
.description(
57-
"If the credentials support domain-wide delegation, creates a copy of the identity so that it * impersonates the specified user; otherwise, returns the same instance.")
66+
"If the credentials support domain-wide delegation, creates a copy of the identity so that it impersonates the specified user; otherwise, returns the same instance.")
5867
.required(false)
5968
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
6069
.build();
@@ -64,12 +73,14 @@ public class GCPOauth2AccessTokenProvider extends AbstractControllerService impl
6473
static {
6574
final List<PropertyDescriptor> props = new ArrayList<>();
6675
props.add(GoogleUtils.GCP_CREDENTIALS_PROVIDER_SERVICE);
76+
props.add(PROJECT_ID);
6777
props.add(SCOPE);
6878
props.add(DELEGATE);
6979
properties = Collections.unmodifiableList(props);
7080
}
7181

7282
private volatile GoogleCredentials googleCredentials;
83+
private volatile String projectId;
7384
private volatile String[] scopes;
7485
private volatile String delegate;
7586

@@ -87,20 +98,24 @@ public void onEnabled(final ConfigurationContext context) throws InitializationE
8798
// Get GCP credentials
8899
googleCredentials = gcpCredentialsService.getGoogleCredentials();
89100

101+
// Change quota project if specified
102+
projectId = context.getProperty(PROJECT_ID).getValue();
103+
if (projectId != null && !projectId.isBlank()) {
104+
googleCredentials = googleCredentials.createWithQuotaProject(projectId);
105+
}
106+
90107
// Apply required scope(s)
91108
String scope = context.getProperty(SCOPE).getValue();
92109
if (scope != null) {
93110
scopes = scope.split("\\s+");
94111
if (scopes.length > 0) {
95-
getLogger().debug("dloop-scope: " + String.join(" ", scopes));
96112
googleCredentials = googleCredentials.createScoped(scopes);
97113
}
98114
}
99115

100-
// Impersonate another account if specified
116+
// Impersonate a user account via account wide delegation if specified
101117
delegate = context.getProperty(DELEGATE).getValue();
102118
if (delegate != null && !delegate.isBlank()) {
103-
getLogger().debug("dloop-delegate: " + delegate);
104119
googleCredentials = googleCredentials.createDelegated(delegate);
105120
}
106121
}

nifi-gcp-oauth2-provider/src/test/java/com/dloop/nifi/gcp/oauth2/TestGCPOauth2AccessTokenProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package com.dloop.nifi.gcp.oauth2;
1818

19-
import org.apache.nifi.oauth2.StandardOauth2AccessTokenProvider;
2019
import org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsControllerService;
2120
import org.apache.nifi.processors.gcp.util.GoogleUtils;
2221
import org.apache.nifi.reporting.InitializationException;
@@ -45,7 +44,7 @@ public void testService() throws InitializationException {
4544
runner.addControllerService("test-gcp-oauth2-access-token-provider", tokenProviderService);
4645
runner.setProperty(tokenProviderService, GoogleUtils.GCP_CREDENTIALS_PROVIDER_SERVICE,
4746
"test-gcp-credentials-controller-service");
48-
runner.setProperty(tokenProviderService, StandardOauth2AccessTokenProvider.SCOPE, "test-value");
47+
runner.setProperty(tokenProviderService, GCPOauth2AccessTokenProvider.SCOPE, "test-value");
4948
runner.enableControllerService(tokenProviderService);
5049
runner.assertValid(tokenProviderService);
5150
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>org.apache.nifi</groupId>
2121
<artifactId>nifi-nar-bundles</artifactId>
22-
<version>1.20.0</version>
22+
<version>1.27.0</version>
2323
</parent>
2424

2525
<groupId>com.dloop</groupId>

0 commit comments

Comments
 (0)