Mencantumkan modul kustom Event Threat Detection

Contoh kode untuk mencantumkan modul kustom Event Threat Detection.

Contoh kode

Go

Untuk melakukan autentikasi ke Security Command Center, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


import (
	"context"
	"fmt"
	"io"

	securitycentermanagement "cloud.google.com/go/securitycentermanagement/apiv1"
	securitycentermanagementpb "cloud.google.com/go/securitycentermanagement/apiv1/securitycentermanagementpb"
	iterator "google.golang.org/api/iterator"
)

// listEventThreatDetectionCustomModule lists all custom modules for Event Threat Detection.
func listEventThreatDetectionCustomModule(w io.Writer, parent string) error {
	// parent: Use any one of the following options:
	// - organizations/{organization_id}/locations/{location_id}
	// - folders/{folder_id}/locations/{location_id}
	// - projects/{project_id}/locations/{location_id}

	ctx := context.Background()
	client, err := securitycentermanagement.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("securitycentermanagement.NewClient: %w", err)
	}
	defer client.Close()

	req := &securitycentermanagementpb.ListEventThreatDetectionCustomModulesRequest{
		Parent: parent,
	}

	// List all Event Threat Detection custom modules present in the resource.
	it := client.ListEventThreatDetectionCustomModules(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("it.Next: %w", err)
		}
		fmt.Fprintf(w, "Custom Module Name: %s,\n", resp.Name)
	}
	return nil
}

Java

Untuk melakukan autentikasi ke Security Command Center, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import com.google.cloud.securitycentermanagement.v1.ListEventThreatDetectionCustomModulesRequest;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient;
import com.google.cloud.securitycentermanagement.v1.SecurityCenterManagementClient.ListEventThreatDetectionCustomModulesPagedResponse;
import java.io.IOException;

public class ListEventThreatDetectionCustomModules {

  public static void main(String[] args) throws IOException {
    // https://cloud.google.com/security-command-center/docs/reference/security-center-management/rest/v1/organizations.locations.eventThreatDetectionCustomModules/list
    // TODO: Developer should replace project_id with a real project ID before running this code
    String projectId = "project_id";

    listEventThreatDetectionCustomModules(projectId);
  }

  public static ListEventThreatDetectionCustomModulesPagedResponse
      listEventThreatDetectionCustomModules(String projectId) throws IOException {

    // Initialize client that will be used to send requests. This client only needs
    // to be created
    // once, and can be reused for multiple requests.
    try (SecurityCenterManagementClient client = SecurityCenterManagementClient.create()) {

      String parent = String.format("projects/%s/locations/global", projectId);

      ListEventThreatDetectionCustomModulesRequest request =
          ListEventThreatDetectionCustomModulesRequest.newBuilder().setParent(parent).build();

      ListEventThreatDetectionCustomModulesPagedResponse response =
          client.listEventThreatDetectionCustomModules(request);

      return response;
    }
  }
}

Langkah selanjutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat browser contoh Google Cloud .