Skip to content

Commit 77e51cb

Browse files
turcsanyippvillard31
authored andcommitted
NIFI-15210 Fixed verify method of GCS processors and other GCP fixes
Signed-off-by: Pierre Villard <[email protected]> This closes #10519.
1 parent b51bc28 commit 77e51cb

File tree

11 files changed

+1023
-1030
lines changed

11 files changed

+1023
-1030
lines changed

nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/pubsub/ConsumeGCPubSub.java

Lines changed: 450 additions & 450 deletions
Large diffs are not rendered by default.

nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/pubsub/PublishGCPubSub.java

Lines changed: 504 additions & 504 deletions
Large diffs are not rendered by default.

nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/storage/AbstractGCSProcessor.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import java.util.Map;
4444
import java.util.Set;
4545

46+
import static org.apache.nifi.processors.gcp.storage.StorageAttributes.BUCKET_DESC;
47+
4648
/**
4749
* Base class for creating processors which connect to Google Cloud Storage.
4850
*
@@ -68,6 +70,14 @@ public Set<Relationship> getRelationships() {
6870
return RELATIONSHIPS;
6971
}
7072

73+
public static final PropertyDescriptor BUCKET = new PropertyDescriptor.Builder()
74+
.name("Bucket")
75+
.description(BUCKET_DESC)
76+
.required(true)
77+
.expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
78+
.addValidator(StandardValidators.NON_EMPTY_EL_VALIDATOR)
79+
.build();
80+
7181
// https://cloud.google.com/storage/docs/request-endpoints#storage-set-client-endpoint-java
7282
public static final PropertyDescriptor STORAGE_API_URL = new PropertyDescriptor.Builder()
7383
.name("Storage API URL")
@@ -137,7 +147,7 @@ protected void customValidate(ValidationContext validationContext, Collection<Va
137147
protected abstract List<String> getRequiredPermissions();
138148

139149
protected String getBucketName(final ProcessContext context, final Map<String, String> attributes) {
140-
return context.getProperty("gcs-bucket").evaluateAttributeExpressions(attributes).getValue();
150+
return context.getProperty(BUCKET).evaluateAttributeExpressions(attributes).getValue();
141151
}
142152

143153
@Override

nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/storage/DeleteGCSObject.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.util.concurrent.TimeUnit;
3838

3939
import static org.apache.nifi.processors.gcp.storage.StorageAttributes.BUCKET_ATTR;
40-
import static org.apache.nifi.processors.gcp.storage.StorageAttributes.BUCKET_DESC;
4140
import static org.apache.nifi.processors.gcp.storage.StorageAttributes.KEY_DESC;
4241

4342

@@ -49,12 +48,9 @@
4948
@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
5049
public class DeleteGCSObject extends AbstractGCSProcessor {
5150
public static final PropertyDescriptor BUCKET = new PropertyDescriptor.Builder()
52-
.name("Bucket")
53-
.description(BUCKET_DESC)
54-
.required(true)
51+
.fromPropertyDescriptor(AbstractGCSProcessor.BUCKET)
5552
.defaultValue("${" + BUCKET_ATTR + "}")
5653
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
57-
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
5854
.build();
5955

6056
public static final PropertyDescriptor KEY = new PropertyDescriptor.Builder()

nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/storage/FetchGCSObject.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,9 @@
169169
)
170170
public class FetchGCSObject extends AbstractGCSProcessor {
171171
public static final PropertyDescriptor BUCKET = new PropertyDescriptor.Builder()
172-
.name("Bucket")
173-
.description(BUCKET_DESC)
174-
.required(true)
172+
.fromPropertyDescriptor(AbstractGCSProcessor.BUCKET)
175173
.defaultValue("${" + BUCKET_ATTR + "}")
176174
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
177-
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
178175
.build();
179176

180177
public static final PropertyDescriptor KEY = new PropertyDescriptor.Builder()

nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/storage/ListGCSBucket.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,6 @@ public class ListGCSBucket extends AbstractGCSProcessor {
221221
.required(true)
222222
.build();
223223

224-
public static final PropertyDescriptor BUCKET = new PropertyDescriptor.Builder()
225-
.name("Bucket")
226-
.description(BUCKET_DESC)
227-
.required(true)
228-
.expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
229-
.addValidator(StandardValidators.NON_EMPTY_EL_VALIDATOR)
230-
.build();
231-
232224
public static final PropertyDescriptor PREFIX = new PropertyDescriptor.Builder()
233225
.name("Prefix")
234226
.description("The prefix used to filter the object list. In most cases, it should end with a forward slash ('/').")
@@ -409,11 +401,6 @@ protected List<String> getRequiredPermissions() {
409401
return Collections.singletonList("storage.objects.list");
410402
}
411403

412-
@Override
413-
protected String getBucketName(final ProcessContext context, final Map<String, String> attributes) {
414-
return context.getProperty(BUCKET).evaluateAttributeExpressions().getValue();
415-
}
416-
417404
@Override
418405
public List<ConfigVerificationResult> verify(final ProcessContext context, final ComponentLog verificationLogger, final Map<String, String> attributes) {
419406
final List<ConfigVerificationResult> results = new ArrayList<>(super.verify(context, verificationLogger, attributes));

nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/storage/PutGCSObject.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,9 @@
148148
})
149149
public class PutGCSObject extends AbstractGCSProcessor {
150150
public static final PropertyDescriptor BUCKET = new PropertyDescriptor.Builder()
151-
.name("Bucket")
152-
.description(BUCKET_DESC)
153-
.required(true)
151+
.fromPropertyDescriptor(AbstractGCSProcessor.BUCKET)
154152
.defaultValue("${" + BUCKET_ATTR + "}")
155153
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
156-
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
157154
.build();
158155

159156
public static final PropertyDescriptor KEY = new PropertyDescriptor.Builder()

nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/AbstractGoogleDriveIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.api.services.drive.model.File;
2828
import org.apache.commons.lang3.StringUtils;
2929
import org.apache.nifi.processor.Processor;
30+
import org.apache.nifi.processors.gcp.credentials.factory.AuthenticationStrategy;
3031
import org.apache.nifi.processors.gcp.credentials.factory.CredentialPropertyDescriptors;
3132
import org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsControllerService;
3233
import org.apache.nifi.processors.gcp.util.GoogleUtils;
@@ -106,6 +107,7 @@ protected TestRunner createTestRunner() throws Exception {
106107
GCPCredentialsControllerService gcpCredentialsControllerService = new GCPCredentialsControllerService();
107108
testRunner.addControllerService("gcp_credentials_provider_service", gcpCredentialsControllerService);
108109

110+
testRunner.setProperty(gcpCredentialsControllerService, CredentialPropertyDescriptors.AUTHENTICATION_STRATEGY, AuthenticationStrategy.SERVICE_ACCOUNT_JSON_FILE);
109111
testRunner.setProperty(gcpCredentialsControllerService, CredentialPropertyDescriptors.SERVICE_ACCOUNT_JSON_FILE, CREDENTIAL_JSON_FILE_PATH);
110112
testRunner.enableControllerService(gcpCredentialsControllerService);
111113
testRunner.setProperty(GoogleUtils.GCP_CREDENTIALS_PROVIDER_SERVICE, "gcp_credentials_provider_service");
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
1-
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one or more
3-
* contributor license agreements. See the NOTICE file distributed with
4-
* this work for additional information regarding copyright ownership.
5-
* The ASF licenses this file to You under the Apache License, Version 2.0
6-
* (the "License"); you may not use this file except in compliance with
7-
* the License. You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
17-
package org.apache.nifi.processors.gcp.pubsub;
18-
19-
import org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsControllerService;
20-
import org.apache.nifi.reporting.InitializationException;
21-
import org.apache.nifi.util.TestRunner;
22-
23-
import java.util.HashMap;
24-
import java.util.Map;
25-
26-
public class AbstractGCPubSubIT {
27-
28-
protected static final String PROJECT_ID = "my-gcm-client";
29-
protected static final String CONTROLLER_SERVICE = "GCPCredentialsService";
30-
protected static TestRunner runner;
31-
32-
protected TestRunner setCredentialsCS(TestRunner runner) throws InitializationException {
33-
final String serviceAccountJsonFilePath = "path/to/credentials/json";
34-
final Map<String, String> propertiesMap = new HashMap<>();
35-
final GCPCredentialsControllerService credentialsControllerService = new GCPCredentialsControllerService();
36-
37-
propertiesMap.put("application-default-credentials", "false");
38-
propertiesMap.put("compute-engine-credentials", "false");
39-
propertiesMap.put("service-account-json-file", serviceAccountJsonFilePath);
40-
41-
runner.addControllerService(CONTROLLER_SERVICE, credentialsControllerService, propertiesMap);
42-
runner.enableControllerService(credentialsControllerService);
43-
runner.assertValid(credentialsControllerService);
44-
45-
return runner;
46-
}
47-
}
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.nifi.processors.gcp.pubsub;
18+
19+
import org.apache.nifi.processors.gcp.credentials.factory.AuthenticationStrategy;
20+
import org.apache.nifi.processors.gcp.credentials.factory.CredentialPropertyDescriptors;
21+
import org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsControllerService;
22+
import org.apache.nifi.reporting.InitializationException;
23+
import org.apache.nifi.util.TestRunner;
24+
25+
import java.util.HashMap;
26+
import java.util.Map;
27+
28+
public class AbstractGCPubSubIT {
29+
30+
protected static final String PROJECT_ID = "my-gcm-client";
31+
protected static final String CONTROLLER_SERVICE = "GCPCredentialsService";
32+
protected static TestRunner runner;
33+
34+
protected TestRunner setCredentialsCS(TestRunner runner) throws InitializationException {
35+
final String serviceAccountJsonFilePath = "path/to/credentials/json";
36+
final Map<String, String> propertiesMap = new HashMap<>();
37+
final GCPCredentialsControllerService credentialsControllerService = new GCPCredentialsControllerService();
38+
39+
propertiesMap.put(CredentialPropertyDescriptors.AUTHENTICATION_STRATEGY.getName(), AuthenticationStrategy.SERVICE_ACCOUNT_JSON_FILE.getValue());
40+
propertiesMap.put(CredentialPropertyDescriptors.SERVICE_ACCOUNT_JSON_FILE.getName(), serviceAccountJsonFilePath);
41+
42+
runner.addControllerService(CONTROLLER_SERVICE, credentialsControllerService, propertiesMap);
43+
runner.enableControllerService(credentialsControllerService);
44+
runner.assertValid(credentialsControllerService);
45+
46+
return runner;
47+
}
48+
}

nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/storage/AbstractGCSIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.google.cloud.storage.StorageException;
2525
import com.google.cloud.storage.testing.RemoteStorageHelper;
2626
import org.apache.nifi.processor.Processor;
27+
import org.apache.nifi.processors.gcp.credentials.factory.AuthenticationStrategy;
28+
import org.apache.nifi.processors.gcp.credentials.factory.CredentialPropertyDescriptors;
2729
import org.apache.nifi.processors.gcp.credentials.service.GCPCredentialsControllerService;
2830
import org.apache.nifi.util.TestRunner;
2931
import org.apache.nifi.util.TestRunners;
@@ -94,6 +96,7 @@ protected static TestRunner buildNewRunner(Processor processor) throws Exception
9496
final GCPCredentialsControllerService credentialsControllerService = new GCPCredentialsControllerService();
9597
final TestRunner runner = TestRunners.newTestRunner(processor);
9698
runner.addControllerService("gcpCredentialsControllerService", credentialsControllerService);
99+
runner.setProperty(credentialsControllerService, CredentialPropertyDescriptors.AUTHENTICATION_STRATEGY, AuthenticationStrategy.APPLICATION_DEFAULT);
97100
runner.enableControllerService(credentialsControllerService);
98101

99102
runner.setProperty(AbstractGCSProcessor.GCP_CREDENTIALS_PROVIDER_SERVICE, "gcpCredentialsControllerService");

0 commit comments

Comments
 (0)