This is an automated email from the ASF dual-hosted git repository.

pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 900060da57 NIFI-15105 Fixed List/FetchGoogleDrive processors fail when 
the user lacks access to the Shared Drive root
900060da57 is described below

commit 900060da577605919e2ac3d59bdcce0a1a9ac158
Author: Peter Turcsanyi <[email protected]>
AuthorDate: Fri Oct 17 10:26:08 2025 +0200

    NIFI-15105 Fixed List/FetchGoogleDrive processors fail when the user lacks 
access to the Shared Drive root
    
    Signed-off-by: Pierre Villard <[email protected]>
    
    This closes #10432.
---
 .../processors/gcp/drive/GoogleDriveTrait.java     | 26 +++++++++-----
 .../gcp/drive/ListGoogleDriveTestRunnerTest.java   | 42 +++++++++++++++++++++-
 2 files changed, 58 insertions(+), 10 deletions(-)

diff --git 
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveTrait.java
 
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveTrait.java
index 1a5f787f87..e4caf8dde9 100644
--- 
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveTrait.java
+++ 
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/drive/GoogleDriveTrait.java
@@ -18,6 +18,8 @@ package org.apache.nifi.processors.gcp.drive;
 
 import com.google.api.client.http.HttpRequest;
 import com.google.api.client.http.HttpRequestInitializer;
+import com.google.api.client.http.HttpResponseException;
+import com.google.api.client.http.HttpStatusCodes;
 import com.google.api.client.http.HttpTransport;
 import com.google.api.client.json.JsonFactory;
 import com.google.api.client.json.gson.GsonFactory;
@@ -136,16 +138,22 @@ public interface GoogleDriveTrait {
                     .execute();
 
             final String sharedDriveId = folder.getDriveId();
-            final String sharedDriveName;
+            String sharedDriveName = null;
             if (sharedDriveId != null) {
-                sharedDriveName = driveService
-                        .drives()
-                        .get(sharedDriveId)
-                        .setFields("name")
-                        .execute()
-                        .getName();
-            } else {
-                sharedDriveName = null;
+                try {
+                    sharedDriveName = driveService
+                            .drives()
+                            .get(sharedDriveId)
+                            .setFields("name")
+                            .execute()
+                            .getName();
+                } catch (HttpResponseException e) {
+                    if (e.getStatusCode() != 
HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
+                        throw e;
+                    }
+                    // if the user does not have permission to the Shared 
Drive root, the service returns HTTP 404 (Not Found)
+                    // the Shared Drive name can not be retrieved in this case 
and will not be added as a FlowFile attribute
+                }
             }
 
             final String folderName;
diff --git 
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveTestRunnerTest.java
 
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveTestRunnerTest.java
index 2629eee889..8924ab96cf 100644
--- 
a/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveTestRunnerTest.java
+++ 
b/nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/test/java/org/apache/nifi/processors/gcp/drive/ListGoogleDriveTestRunnerTest.java
@@ -41,6 +41,8 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import com.google.api.client.http.HttpHeaders;
+import com.google.api.client.http.HttpResponseException;
 import com.google.api.client.http.HttpTransport;
 import com.google.api.client.util.DateTime;
 import com.google.api.services.drive.Drive;
@@ -174,6 +176,28 @@ public class ListGoogleDriveTestRunnerTest implements 
OutputChecker {
         testOutputAsAttributes(id, filename, size, createdTime, modifiedTime, 
mimeType, owner, lastModifyingUser, webViewLink, webContentLink, modifiedTime);
     }
 
+    @Test
+    void testOutputAsAttributesWhereSharedDriveNameIsNotAvailable() throws 
Exception {
+        when(mockDriverService.drives()
+                .get(driveId)
+                .setFields("name")
+                .execute()
+        ).thenThrow(new HttpResponseException.Builder(404, "Not Found", new 
HttpHeaders()).build());
+
+        String id = "id_1";
+        String filename = "file_name_1";
+        Long size = null;
+        Long createdTime = 123456L;
+        Long modifiedTime = 123456L + 1L;
+        String mimeType = "mime_type_1";
+        String owner = "user1";
+        String lastModifyingUser = "user2";
+        String webViewLink = "http://web.view";;
+        String webContentLink = "http://web.content";;
+
+        testOutputAsAttributes(id, filename, size, createdTime, modifiedTime, 
mimeType, owner, lastModifyingUser, webViewLink, webContentLink, modifiedTime, 
folderId, folderName, driveId, null);
+    }
+
     @Test
     void testOutputAsContent() throws Exception {
         String id = "id_1";
@@ -257,9 +281,25 @@ public class ListGoogleDriveTestRunnerTest implements 
OutputChecker {
     private void testOutputAsAttributes(String id, String filename, Long size, 
Long createdTime, Long modifiedTime, String mimeType,
                                         String owner, String 
lastModifyingUser, String webViewLink, String webContentLink,
                                         Long expectedTimestamp) throws 
IOException {
+        testOutputAsAttributes(id, filename, size, createdTime, modifiedTime, 
mimeType, owner, lastModifyingUser, webViewLink, webContentLink, 
expectedTimestamp,
+                folderId, folderName, driveId, driveName);
+    }
+
+    private void testOutputAsAttributes(String id, String filename, Long size, 
Long createdTime, Long modifiedTime, String mimeType,
+                                        String owner, String 
lastModifyingUser, String webViewLink, String webContentLink,
+                                        Long expectedTimestamp, String 
folderId, String folderName, String driveId, String driveName) throws 
IOException {
         mockFetchedGoogleDriveFileList(id, filename, size, createdTime, 
modifiedTime, mimeType, owner, lastModifyingUser, webViewLink, webContentLink);
 
-        Map<String, String> inputFlowFileAttributes = new HashMap<>();
+        Map<String, String> inputFlowFileAttributes = new HashMap<>() {
+            @Override
+            public String put(String key, String value) {
+                if (value == null) {
+                    // skip null values as a FlowFile attribute is not added 
in that case
+                    return null;
+                }
+                return super.put(key, value);
+            }
+        };
         inputFlowFileAttributes.put(GoogleDriveAttributes.ID, id);
         inputFlowFileAttributes.put(GoogleDriveAttributes.FILENAME, filename);
         inputFlowFileAttributes.put(GoogleDriveAttributes.SIZE, valueOf(size 
!= null ? size : 0L));

Reply via email to