버킷을 관리하고 객체를 나열하기 위해 Google Cloud Storage v2 gRPC API를 호출하는 형식화된 인터페이스입니다.
Google Cloud Storage는 모든 양의 데이터를 저장하고 검색하기 위한 객체 스토리지 서비스입니다. gRPC API는 google.storage.v2.Storage 서비스를 통해 제공되며, TLS를 통해 storage.googleapis.com:443에서 접근하고, 주요 메서드는 ListBuckets, CreateBucket, DeleteBucket 및 ListObjects입니다.
요청은 TsgcGRPCStorageListBucketsRequest(Parent = projects/<id>)와 같은 형식화된 클래스로 작성되며, 응답은 TsgcGRPCStorageListBucketsResponse로 반환되고, 그 Buckets에는 버킷 Name이 포함됩니다. gRPC Storage API는 대상 리소스를 식별하는 x-goog-request-params 라우팅 메타데이터 헤더도 요구하며, 형식화된 인터페이스가 각 호출마다 이를 대신 추가합니다.
아래 예제는 서비스 계정 JWT로 인증하고, Storage 호스트에 대해 TsgcHTTP2Client 위에 TsgcGRPCClient를 연결하고, authorization Bearer 메타데이터를 설정한 후, 프로젝트에 대해 ListBuckets를 호출합니다.
TsgcHTTP2Client *oHTTP2 = new TsgcHTTP2Client();
oHTTP2->Host = "storage.googleapis.com";
oHTTP2->Port = 443;
oHTTP2->TLS = true;
TsgcGRPCClient *oGRPC = new TsgcGRPCClient();
oGRPC->Client = oHTTP2;
// service-account JWT authentication
oGRPC->GoogleCloudOptions->JWT->KeyFile = "service-account.json";
oGRPC->GoogleCloudOptions->JWT->API_Endpoint = "https://storage.googleapis.com/";
oGRPC->DefaultMetadata->AddValue("authorization", "Bearer " + oGRPC->GoogleCloudOptions->JWT->Token);
// build the typed request and call the method
TsgcGRPCStorageListBucketsRequest *oRequest = new TsgcGRPCStorageListBucketsRequest();
oRequest->Parent = "projects/my-project-id";
TsgcGRPCResponse *oResponse = oGRPC->Call("google.storage.v2.Storage", "ListBuckets", oRequest->ToBytes());
ShowMessage(oResponse->DataString);
delete oRequest;
| Name | 설명 |
|---|---|
| ListBuckets | 프로젝트에 속한 버킷을 나열합니다. |
| CreateBucket | 프로젝트에 새 버킷을 생성합니다. |
| DeleteBucket | 기존 버킷을 삭제합니다. |
| ListObjects | 버킷 내부에 저장된 객체를 나열합니다. |
작동하는 샘플은 데모 폴더 Demos/21.GRPC/15.Cloud_Storage에서 제공되며, ListBuckets 메서드로 인증하고 프로젝트의 버킷을 나열하는 방법을 보여줍니다.