데이터 통합사용 가능한 커넥터Google Drive

본 번역은 검증되지 않았습니다. AIP를 통해 영문원문으로부터 번역되었습니다.

Google Drive

Google Drive 커넥터는 Google Drive를 위한 Palantir 제공 드라이버입니다.

새로운 Google Drive 소스를 생성하려면 Palantir 제공 드라이버에 대한 표준 설정 흐름을 확인 해주세요. 이후 Google Drive에 특화된 구성 및 네트워킹을 위해 아래 섹션을 사용하세요. 전체 속성 출처는 공식 Google Drive 드라이버 문서 ↗를 확인 해주세요.

Google Drive 작업 선택

필요한 결과에 따라 소스와 작업을 선택하세요:

작업Foundry 경로결과
파일 레코드 탐색 또는 동기화Google Drive 커넥터, Files 표 포함ID, 이름, MIME 유형, 크기 등의 파일 메타데이터
배치 동기화에서 하나의 파일 추출Google Drive 커넥터의 DownloadFile 저장 프로시저Base64로 인코딩된 파일 내용이 결과 데이터셋에 포함
필요 시 blob 파일 읽기별도의 OAuth 지원 REST API 소스를 사용하는 Python 또는 TypeScript v2 FunctionGoogle Drive에서 파일 내용 files.get with alt=media ↗
필요 시 blob 파일 생성 또는 교체동일한 REST API 소스를 사용하는 Python 또는 TypeScript v2 Function외부 파일을 변경하는 Drive API 업로드 ↗

Files 표의 FileData 속성 ↗은 파일 내용 다운로드를 데이터셋 열로 변환하지 않습니다. 메타데이터 동기화를 사용하여 파일 ID를 확인한 후, DownloadFile 또는 필요 시 Function에 ID를 전달하세요. Function의 경우 호출 사용자가 파일에 접근할 수 있어야 하며, 아웃바운드 애플리케이션의 인증된 범위가 작업을 허용해야 합니다. Drive API 접근 경계를 확인 해주세요.

지원되는 기능

기능상태
탐색🟢 일반적으로 사용 가능
배치 동기화🟢 일반적으로 사용 가능
증분🟢 일반적으로 사용 가능
OAuth 2.0 인증🟢 일반적으로 사용 가능
표 내보내기🟢 일반적으로 사용 가능

구성

아래 속성은 필수 또는 권장됩니다.

속성필수 여부설명기본값
AuthScheme ↗권장Google Drive에 연결할 때 사용할 인증 유형OAuthJWT
InitiateOAuth ↗권장OAuth 액세스 토큰을 얻거나 갱신하는 프로세스를 지정하며, 인증된 사용자가 작업 중일 때 사용자 접근을 유지합니다GETANDREFRESH
OAuthClientId ↗권장사용자 정의 OAuth 애플리케이션이 생성될 때 할당된 클라이언트 ID를 지정합니다. (소비자 키라고도 함) 이 ID는 OAuth 인증 서버에 사용자 정의 애플리케이션을 등록합니다—
OAuthClientSecret ↗권장사용자 정의 OAuth 애플리케이션이 생성될 때 할당된 클라이언트 비밀을 지정합니다. (소비자 비밀이라고도 함) 이 비밀은 OAuth 인증 서버에 사용자 정의 애플리케이션을 등록합니다—
OAuthJWTCert ↗권장JWT 인증서 저장소—
OAuthJWTCertType ↗권장JWT 인증서를 포함하는 키 저장소 유형GOOGLEJSONBLOB
OAuthJWTSubject ↗권장애플리케이션이 위임된 접근을 요청하는 사용자 주체—

네트워킹

아래 표는 소스를 실행하기 위해 접근해야 하는 도메인을 나열합니다.

각 도메인에 대해 egress 정책을 추가하세요. 소스가 온프레미스에 호스팅되고 Foundry에서 직접 접근할 수 없는 경우, 에이전트 프록시 egress 정책을 대신 사용하세요. 에이전트 호스트 자체도 나열된 도메인에 접근할 수 있어야 합니다. 자세한 내용은 프록시로 에이전트 사용을 확인 해주세요.

도메인필수 여부
accounts.google.com항상. OAuth에 필요
www.googleapis.com항상

OAuth 2.0 인증

이 커넥터는 OAuth 2.0 인증을 지원합니다. 연결을 구성하고 인증하려면 Palantir 제공 드라이버에 대한 OAuth 2.0 가이드를 확인 해주세요.

메타데이터 동기화를 위한 서비스 계정 사용

메타데이터 동기화를 위해 서비스 계정을 사용하려면 다음 소스 속성을 구성하세요:

속성값
AuthSchemeOAuthJWT
InitiateOAuthGETANDREFRESH
OAuthJWTCertTypeGOOGLEJSONBLOB ↗, JSON 문서 자체를 기대합니다. GOOGLEJSON은 파일 경로를 기대합니다.
OAuthJWTCert암호화된 필드에 입력된 전체 서비스 계정 JSON 문서
OAuthJWTSubject도메인 전체 위임을 구성하지 않은 경우 비워둡니다.
Readonly이 소스가 메타데이터만 읽는 경우 true로 설정하여 드라이버를 SELECT 쿼리로 제한합니다.

JSON 문서의 이중 따옴표 키와 개인 키의 이스케이프된 줄바꿈을 유지하세요. 이 자격 증명을 Code Repositories에서 제외하세요. 사용하지 않는 OAuthClientId 및 OAuthClientSecret 행을 소스 폼에서 제거하세요. 이들은 서비스 계정 설정의 일부가 아닙니다.

표 내보내기

이 커넥터는 표 내보내기를 지원합니다. 표 내보내기 설정 방법을 확인 해주세요.

배치 동기화로 파일 추출

하나의 파일을 추출하려면 동기화 정의에서 Google Drive DownloadFile 저장 프로시저 ↗를 실행하세요:

Copied!
1 EXECUTE DownloadFile Id = '<FILE_ID>', LocalFile = ''

LocalFile이 비어 있는 경우, 결과 데이터셋은 기본적으로 Base64로 인코딩된 FileData에 파일 내용을 포함합니다. 다운스트림 데이터 변환에서 이를 바이너리로 디코딩하세요. Readonly가 비활성화되었거나 false로 설정된 소스를 사용하세요: Readonly=true는 저장 프로시저를 거부합니다 ↗.

Drive API로 blob 파일 읽기 및 쓰기

필요 시 파일 내용 작업을 위해 OAuth 2.0 아웃바운드 애플리케이션을 지원하는 별도의 REST API 소스를 구성하세요. 내보내기 및 소스 가져오기 활성화를 확인한 후, 소스를 Python 또는 TypeScript v2 Functions 저장소에 가져오세요. 각 예제에서 <SOURCE_RID>를 가져온 REST API 소스의 RID로 대체하세요. 애플리케이션을 인증한 사용자를 대신하여 Function을 실행하세요. 이 소스는 호출 사용자의 위임된 접근을 사용하며, 메타데이터 소스의 서비스 계정 JSON을 재사용하지 않습니다. 실행 및 인증 요구 사항은 Functions에서 OAuth 2.0 사용을 확인 해주세요.

REST 소스가 API 호스트 www.googleapis.com:443 및 OAuth 호스트 accounts.google.com:443와 oauth2.googleapis.com:443에만 접근할 수 있도록 허용하세요.

각 작업에 필요한 파일에 대해 Google Drive 범위 ↗를 선택하세요:

작업범위접근 경계
애플리케이션이 접근할 수 있는 파일 읽기https://www.googleapis.com/auth/drive.file애플리케이션으로 생성되거나 열리거나, Google Picker를 통해 사용자가 애플리케이션에 선택한 파일
사용자가 접근할 수 있는 모든 파일 읽기https://www.googleapis.com/auth/drive.readonly사용자가 접근할 수 있는 모든 Drive 파일; 제한된 범위입니다.
적격 파일 생성 또는 교체https://www.googleapis.com/auth/drive.file새 파일 및 적격 기존 파일; 파일 ID만으로는 편집 접근 권한이 부여되지 않습니다.

drive.readonly를 요청하는 공개 애플리케이션은 Google의 제한된 범위 인증 요구 사항 ↗을 충족해야 합니다.

Workshop에서 직접 Function 호출은 대화형 인증을 시작할 수 없습니다. 처음 인증을 제공하려면 별도의 Function 기반 액션을 사용하세요. 그렇지 않으면 사용자가 이러한 Functions를 호출하기 전에 동일한 아웃바운드 애플리케이션을 인증해야 합니다. 서버리스 모드를 사용하여 사용자의 OAuth 자격 증명이 갱신될 수 있도록 하세요.

하나의 blob 파일 읽기

Google Drive files.get with alt=media ↗를 사용하여 blob 바이트를 읽습니다. 임의의 파일 ID를 사용하기 전에 파일의 메타데이터와 다운로드 가능성을 확인하세요. 네이티브 Google Workspace 문서는 지원되는 형식으로 files.export ↗가 필요합니다. 이 예제는 blob 바이트를 Base64 스트링으로 반환합니다.

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 import base64 import requests from functions.api import function from functions.sources import get_source SOURCE_RID = "<SOURCE_RID>" @function(sources=[SOURCE_RID]) def read_google_drive_blob(file_id: str) -> str: source = get_source(rid=SOURCE_RID) session = requests.Session() proxy = source.get_https_proxy_uri() if proxy: session.proxies.update({"http": proxy, "https": proxy}) session.headers["Authorization"] = ( f"Bearer {source.get_session_credentials().get().access_token}" ) response = session.get( f"https://www.googleapis.com/drive/v3/files/{file_id}", params={"alt": "media", "supportsAllDrives": "true"}, allow_redirects=False, ) if not 200 <= response.status_code < 300: raise RuntimeError(f"Google Drive returned {response.status_code}") return base64.b64encode(response.content).decode("ascii")
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import { getFetch, getSource } from "@palantir/functions-sources"; const SOURCE_RID = "<SOURCE_RID>"; export const config = { sources: [SOURCE_RID] }; export default async function readGoogleDriveBlob(fileId: string): Promise<string> { const source = await getSource({ rid: SOURCE_RID }); const credentials = await source.sessionCredentials?.get(); if (credentials?.type !== "oauth") throw new Error("Authorize the source first"); const sourceFetch = await getFetch(source); const response = await sourceFetch( `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media&supportsAllDrives=true`, { headers: { Authorization: `Bearer ${credentials.accessToken}` }, redirect: "error", }, ); if (!response.ok) throw new Error(`Google Drive returned ${response.status}`); return Buffer.from(await response.arrayBuffer()).toString("base64"); }

blob 파일 생성

WRITE 예제는 간단한 미디어 업로드 ↗를 사용하여 5MB 이하의 콘텐츠를 업로드합니다. 업로드가 중단되었을 때 재시도하거나 최종 바이트를 읽지 않습니다. 복구하기 어려운 파일을 쓰기 전에 이러한 제어를 추가하세요.

이 예제는 선택한 폴더에 메타데이터를 생성한 후 바이트를 업로드합니다. 업로드 실패 시 새 파일은 비어 있을 수 있습니다. 새 파일 ID만 반환됩니다.

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 import base64 import requests from functions.api import function from functions.sources import get_source SOURCE_RID = "<SOURCE_RID>" @function(sources=[SOURCE_RID]) def create_google_drive_blob( parent_folder_id: str, file_name: str, mime_type: str, content_base64: str ) -> str: source = get_source(rid=SOURCE_RID) session = requests.Session() proxy = source.get_https_proxy_uri() if proxy: session.proxies.update({"http": proxy, "https": proxy}) session.headers["Authorization"] = ( f"Bearer {source.get_session_credentials().get().access_token}" ) created = session.post( "https://www.googleapis.com/drive/v3/files", json={"name": file_name, "mimeType": mime_type, "parents": [parent_folder_id]}, params={"fields": "id", "supportsAllDrives": "true"}, allow_redirects=False, ) if not 200 <= created.status_code < 300: raise RuntimeError(f"Google Drive returned {created.status_code}") file_id = created.json()["id"] uploaded = session.patch( f"https://www.googleapis.com/upload/drive/v3/files/{file_id}", params={"uploadType": "media", "supportsAllDrives": "true"}, data=base64.b64decode(content_base64), headers={"Content-Type": mime_type}, allow_redirects=False, ) if not 200 <= uploaded.status_code < 300: raise RuntimeError(f"Google Drive returned {uploaded.status_code}") return file_id
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 import { getFetch, getSource } from "@palantir/functions-sources"; const SOURCE_RID = "<SOURCE_RID>"; export const config = { sources: [SOURCE_RID] }; export default async function createGoogleDriveBlob( parentFolderId: string, fileName: string, mimeType: string, contentBase64: string, ): Promise<string> { const source = await getSource({ rid: SOURCE_RID }); const credentials = await source.sessionCredentials?.get(); if (credentials?.type !== "oauth") throw new Error("Authorize the source first"); const sourceFetch = await getFetch(source); const created = await sourceFetch( "https://www.googleapis.com/drive/v3/files?fields=id&supportsAllDrives=true", { method: "POST", headers: { Authorization: `Bearer ${credentials.accessToken}`, "Content-Type": "application/json" }, body: JSON.stringify({ name: fileName, mimeType, parents: [parentFolderId] }), redirect: "error", }, ); if (!created.ok) throw new Error(`Google Drive returned ${created.status}`); const { id } = (await created.json()) as { id: string }; const uploaded = await sourceFetch( `https://www.googleapis.com/upload/drive/v3/files/${id}?uploadType=media&supportsAllDrives=true`, { method: "PATCH", headers: { Authorization: `Bearer ${credentials.accessToken}`, "Content-Type": mimeType }, body: Buffer.from(contentBase64, "base64"), redirect: "error", }, ); if (!uploaded.ok) throw new Error(`Google Drive returned ${uploaded.status}`); return id; }

편집 가능한 blob 파일 교체

이 예제는 애플리케이션이 편집할 수 있는 경우 제공된 파일 ID를 덮어씁니다. 교체하려는 파일만 제공하세요: 확인, 충돌 검사, 또는 다시 읽기가 없습니다.

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 import base64 import requests from functions.api import function from functions.sources import get_source SOURCE_RID = "<SOURCE_RID>" @function(sources=[SOURCE_RID]) def replace_google_drive_blob( file_id: str, mime_type: str, content_base64: str ) -> str: source = get_source(rid=SOURCE_RID) session = requests.Session() proxy = source.get_https_proxy_uri() if proxy: session.proxies.update({"http": proxy, "https": proxy}) session.headers["Authorization"] = ( f"Bearer {source.get_session_credentials().get().access_token}" ) response = session.patch( f"https://www.googleapis.com/upload/drive/v3/files/{file_id}", params={"uploadType": "media", "supportsAllDrives": "true"}, data=base64.b64decode(content_base64), headers={"Content-Type": mime_type}, allow_redirects=False, ) if not 200 <= response.status_code < 300: raise RuntimeError(f"Google Drive returned {response.status_code}") return file_id
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import { getFetch, getSource } from "@palantir/functions-sources"; const SOURCE_RID = "<SOURCE_RID>"; export const config = { sources: [SOURCE_RID] }; export default async function replaceGoogleDriveBlob( fileId: string, mimeType: string, contentBase64: string, ): Promise<string> { const source = await getSource({ rid: SOURCE_RID }); const credentials = await source.sessionCredentials?.get(); if (credentials?.type !== "oauth") throw new Error("Authorize the source first"); const sourceFetch = await getFetch(source); const response = await sourceFetch( `https://www.googleapis.com/upload/drive/v3/files/${fileId}?uploadType=media&supportsAllDrives=true`, { method: "PATCH", headers: { Authorization: `Bearer ${credentials.accessToken}`, "Content-Type": mimeType, }, body: Buffer.from(contentBase64, "base64"), redirect: "error", }, ); if (!response.ok) throw new Error(`Google Drive returned ${response.status}`); return fileId; }