이 페이지에서는 Google Security Operations API의 Cloud 클라이언트 라이브러리를 시작하는 방법을 보여줍니다. 클라이언트 라이브러리를 사용하면 지원되는 언어로 Google Cloud API에 쉽게 액세스할 수 있습니다. 원시 요청을 서버에 보내Google Cloud API를 직접 사용할 수 있지만 클라이언트 라이브러리는 작성해야 하는 코드 양을 크게 줄여 주는 간소화 기능을 제공합니다.
클라이언트 라이브러리 설명에서 Cloud 클라이언트 라이브러리 및 이전 Google API 클라이언트 라이브러리에 대해 자세히 알아보세요.
클라이언트 라이브러리 설치
C++
Quickstart를 따릅니다.
C#
NuGet의 Google.Cloud.Chronicle.V1 패키지를 설치합니다.
자세한 내용은 C# 개발 환경 설정을 참조하세요.
Go
go get cloud.google.com/go/chronicle/apiv1
자세한 내용은 Go 개발 환경 설정을 참조하세요.
Java
Maven을 사용하는 경우
다음 내용을 pom.xml 파일에 추가합니다. BOM에 대한 자세한 내용은
Google Cloud Platform 라이브러리 BOM을 참조하세요.
자세한 내용은 자바 개발 환경 설정을 참조하세요.
Node.js
npm install @google-cloud/chronicle
자세한 내용은 Node.js 개발 환경 설정을 참조하세요.
PHP
composer require google/cloud-chronicle
자세한 내용은 Google Cloud에서 PHP 사용을 참조하세요.
Python
pip install --upgrade google-cloud-chronicle
자세한 내용은 Python 개발 환경 설정을 참조하세요.
Ruby
gem install google-cloud-chronicle-v1
자세한 내용은 Ruby 개발 환경 설정을 참조하세요.
인증 설정
Google Cloud API 호출을 인증하기 위해 클라이언트 라이브러리는 애플리케이션 기본 사용자 인증 정보(ADC)를 지원합니다. 라이브러리는 정의된 위치 집합에서 사용자 인증 정보를 찾고 이러한 사용자 인증 정보를 사용해서 API에 대한 요청을 인증합니다. ADC를 사용하면 애플리케이션 코드를 수정할 필요 없이 로컬 개발 또는 프로덕션과 같은 다양한 환경에서 애플리케이션에 사용자 인증 정보를 제공할 수 있습니다.프로덕션 환경에서 ADC를 설정하는 방법은 서비스와 컨텍스트에 따라 다릅니다. 자세한 내용은 애플리케이션 기본 사용자 인증 정보 설정을 참조하세요.
로컬 개발 환경의 경우 Google 계정과 연결된 사용자 인증 정보를 사용하여 ADC를 설정할 수 있습니다.
-
Google Cloud CLI를 설치합니다. 설치 후 Google Cloud CLI를 초기화하려면 다음 명령어를 실행합니다.
gcloud init외부 ID 공급업체 (IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.
-
로컬 셸을 사용하는 경우 사용자 계정에 대한 로컬 인증 사용자 인증 정보를 만듭니다.
gcloud auth application-default login
Cloud Shell을 사용하는 경우 이 작업을 수행할 필요는 없습니다.
인증 오류가 반환되고 외부 ID 공급업체(IdP)를 사용하는 경우 제휴 ID로 gcloud CLI에 로그인했는지 확인합니다.
로그인 화면이 표시됩니다. 로그인하면 사용자 인증 정보는 ADC에서 사용하는 로컬 사용자 인증 정보 파일에 저장됩니다.
클라이언트 라이브러리 사용
다음 예시에서는 클라이언트 라이브러리를 사용하여 참조 목록을 나열하는 방법을 보여줍니다.
C++
#include "google/cloud/chronicle/v1/chronicle_client.h"
#include "google/cloud/common_options.h"
#include <iostream>
#include <string>
int main(int argc, char* argv[]) {
// TODO(developer): Replace these variables before running the sample.
std::string const project_id = "";
std::string const instance_id = "";
std::string const location = "us";
std::string const endpoint = "us-chronicle.googleapis.com";
namespace chronicle = ::google::cloud::chronicle_v1;
auto options = google::cloud::Options{}.set<google::cloud::EndpointOption>(endpoint);
auto client = chronicle::ChronicleClient(chronicle::MakeChronicleConnection(options));
// Construct the parent resource name
// Format: projects/{project}/locations/{location}/instances/{instance}
std::string parent = "projects/" + project_id + "/locations/" + location + "/instances/" + instance_id;
google::cloud::chronicle::v1::ListReferenceListsRequest request;
request.set_parent(parent);
std::cout << "Listing reference lists for parent: " << parent << std::endl;
for (auto const& reference_list : client.ListReferenceLists(request)) {
if (!reference_list) {
std::cerr << "Error listing reference lists: " << reference_list.status().message() << std::endl;
return 1;
}
std::cout << "Name: " << reference_list->name() <<std::endl;
std::cout << "Display Name: " << reference_list->display_name() << std::endl;
}
return 0;
}C#
using Google.Cloud.Chronicle.V1;
// TODO(developer): Replace these variables before running the sample.
const string project = "";
const string location = "us";
const string instance = "";
const string endpoint = "us-chronicle.googleapis.com";
ReferenceListServiceClient client = new ReferenceListServiceClientBuilder
{
Endpoint = endpoint,
}.Build();
string parent = InstanceName.FromProjectLocationInstance(project, location, instance).ToString();
foreach (ReferenceList referenceList in client.ListReferenceLists(parent))
{
Console.WriteLine($"Name: {referenceList.Name}");
Console.WriteLine($"Description: {referenceList.Description}");
}Go
package main
import (
"context"
"fmt"
"log"
chronicle "cloud.google.com/go/chronicle/apiv1"
chroniclepb "cloud.google.com/go/chronicle/apiv1/chroniclepb"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
)
// TODO(developer): Replace these variables before running the sample.
const (
project = ""
location = "us"
instance = ""
apiEndpoint = "us-chronicle.googleapis.com:443"
)
func main() {
ctx := context.Background()
client, err := chronicle.NewReferenceListClient(ctx, option.WithEndpoint(apiEndpoint),)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
defer client.Close()
parent := fmt.Sprintf("projects/%s/locations/%s/instances/%s", project, location, instance)
req := &chroniclepb.ListReferenceListsRequest{
Parent: parent,
}
it := client.ListReferenceLists(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
log.Fatalf("error listing reference lists: %v", err)
}
fmt.Printf("Name: %s\n", resp.GetName())
fmt.Printf("Description: %s\n", resp.GetDescription())
fmt.Printf("---\n")
}
}Java
package com.example;
import com.google.cloud.chronicle.v1.InstanceName;
import com.google.cloud.chronicle.v1.ReferenceList;
import com.google.cloud.chronicle.v1.ReferenceListServiceClient;
import com.google.cloud.chronicle.v1.ReferenceListServiceSettings;
public class ListReferenceLists {
// TODO(developer): Replace these variables before running the sample.
private static final String PROJECT = "";
private static final String LOCATION = "us";
private static final String INSTANCE = "";
private static final String ENDPOINT = "us-chronicle.googleapis.com:443";
public static void main(String[] args) throws Exception {
ReferenceListServiceSettings settings = ReferenceListServiceSettings.newBuilder().setEndpoint(ENDPOINT).build();
try (ReferenceListServiceClient client = ReferenceListServiceClient.create(settings)) {
String parent = InstanceName.of(PROJECT, LOCATION, INSTANCE).toString();
for (ReferenceList referenceList : client.listReferenceLists(parent).iterateAll()) {
System.out.println("Name: " + referenceList.getName());
System.out.println("Description: " + referenceList.getDescription());
System.out.println("---");
}
}
}
}Node.js
'use strict';
function main(parent) {
const {ReferenceListServiceClient} = require('@google-cloud/chronicle').v1;
const chronicleClient = new ReferenceListServiceClient({
apiEndpoint: 'us-chronicle.googleapis.com',
});
async function callListReferenceLists() {
// TODO(developer): Replace these variables before running the sample.
const request = {
parent: 'projects/<project-number>/locations/us/instances/<instance-id>'
};
const iterable = chronicleClient.listReferenceListsAsync(request);
for await (const response of iterable) {
console.log(response);
}
}
callListReferenceLists();
}
process.on('unhandledRejection', err=> {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));PHP
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Chronicle\V1\Client\ReferenceListServiceClient;
use Google\Cloud\Chronicle\V1\ListReferenceListsRequest;
use Google\Cloud\Chronicle\V1\ReferenceList;
// TODO(developer): Replace these variables before running the sample.
const PROJECT = '';
const LOCATION = 'us';
const INSTANCE = '';
const ENDPOINT = 'us-chronicle.googleapis.com';
$client = new ReferenceListServiceClient([
'apiEndpoint' => ENDPOINT,
]);
$parent = ReferenceListServiceClient::instanceName(PROJECT, LOCATION, INSTANCE);
$request = (new ListReferenceListsRequest())->setParent($parent);
try {
/** @var PagedListResponse $response /
$response = $client->listReferenceLists($request);
/* @var ReferenceList $referenceList */
foreach ($response as $referenceList) {
printf('Name: %s' . PHP_EOL, $referenceList->getName());
printf('Description: %s' . PHP_EOL, $referenceList->getDescription());
printf('---' . PHP_EOL);
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}Python
from google.cloud import chronicle_v1
# TODO(developer): Replace these variables before running the sample.
PROJECT_ID = ""
LOCATION = "us"
INSTANCE_ID = ""
def list_reference_lists():
client = chronicle_v1.ReferenceListServiceClient(client_options={"api_endpoint":"us-chronicle.googleapis.com"})
parent = f"projects/{PROJECT_ID}/locations/{LOCATION}/instances/{INSTANCE_ID}"
response = client.list_reference_lists(parent=parent)
for reference_list in response:
print(f"Name: {reference_list.name}")
print(f"Display Name: {reference_list.display_name}")
if __name__=="__main__":
list_reference_lists()Ruby
require "google/cloud/chronicle/v1"
# TODO(developer): Replace these variables before running the sample.
PROJECT_ID = ""
LOCATION = "us"
INSTANCE_ID = ""
ENDPOINT = "us-chronicle.googleapis.com"
client = Google::Cloud::Chronicle::V1::ReferenceListService::Client.new do |config|
config.endpoint = ENDPOINT
end
parent = "projects/#{PROJECT_ID}/locations/#{LOCATION}/instances/#{INSTANCE_ID}"
request = Google::Cloud::Chronicle::V1::ListReferenceListsRequest.new(parent: parent)
begin
response = client.list_reference_lists request
response.each do |reference_list|
puts "Name: #{reference_list.name}"
puts "Description: #{reference_list.description}"
end
rescue Google::Cloud::Error => e
puts "API call failed: #{e.message}"
end추가 리소스
C++
다음 목록에는 C++용 클라이언트 라이브러리와 관련된 추가 리소스에 대한 링크가 포함되어 있습니다.
C#
다음 목록에는 C#용 클라이언트 라이브러리와 관련된 추가 리소스에 대한 링크가 포함되어 있습니다.
Go
다음 목록에는 Go용 클라이언트 라이브러리와 관련된 추가 리소스에 대한 링크가 포함되어 있습니다.
Java
다음 목록에는 Java용 클라이언트 라이브러리와 관련된 추가 리소스에 대한 링크가 포함되어 있습니다.
Node.js
다음 목록에는 Node.js용 클라이언트 라이브러리와 관련된 추가 리소스에 대한 링크가 포함되어 있습니다.
PHP
다음 목록에는 PHP용 클라이언트 라이브러리와 관련된 추가 리소스에 대한 링크가 포함되어 있습니다.
Python
다음 목록에는 Python용 클라이언트 라이브러리와 관련된 추가 리소스에 대한 링크가 포함되어 있습니다.
Ruby
다음 목록에는 Ruby용 클라이언트 라이브러리와 관련된 추가 리소스에 대한 링크가 포함되어 있습니다.