Benutzerdefiniertes Security Health Analytics-Modul löschen

Beispielcode für das Löschen benutzerdefinierter Module von Security Health Analytics.

Codebeispiel

Java

Richten Sie zur Authentifizierung bei Security Command Center Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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

public class DeleteSecurityHealthAnalyticsCustomModule {

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

    String customModuleId = "custom_module_id";

    deleteSecurityHealthAnalyticsCustomModule(projectId, customModuleId);
  }

  public static boolean deleteSecurityHealthAnalyticsCustomModule(
      String projectId, String customModuleId) 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 name =
          String.format(
              "projects/%s/locations/global/securityHealthAnalyticsCustomModules/%s",
              projectId, customModuleId);

      DeleteSecurityHealthAnalyticsCustomModuleRequest request =
          DeleteSecurityHealthAnalyticsCustomModuleRequest.newBuilder().setName(name).build();

      client.deleteSecurityHealthAnalyticsCustomModule(request);

      return true;
    }
  }
}

Node.js

Richten Sie zur Authentifizierung bei Security Command Center Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

// npm install '@google-cloud/securitycentermanagement'
const {
  SecurityCenterManagementClient,
} = require('@google-cloud/securitycentermanagement');

const client = new SecurityCenterManagementClient();

/*
 * Required. Resource name of security health analytics module.
 *     Its format is
 *    `organizations/[organization_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
 *    `folders/[folder_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
 *    `projects/[project_id]/locations/[location_id]/securityHealthAnalyticsCustomModules/[custom_module]`
 */
const name = `organizations/${organizationId}/locations/${locationId}/securityHealthAnalyticsCustomModules/${customModuleId}`;

async function deleteSecurityHealthAnalyticsCustomModule() {
  const [response] = await client.deleteSecurityHealthAnalyticsCustomModule({
    name: name,
  });
  console.log(
    'Security Health Analytics Custom Module delete succeeded: ',
    response
  );
}

deleteSecurityHealthAnalyticsCustomModule();

Python

Richten Sie zur Authentifizierung bei Security Command Center Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

def delete_security_health_analytics_custom_module(parent: str, module_id: str):
    """
    Deletes a Security Health Analytics custom module.
    Args:
        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}
    Returns:
        The deleted Security Health Analytics custom module.
    Raises:
        NotFound: If the specified custom module does not exist.
    """
    client = securitycentermanagement_v1.SecurityCenterManagementClient()

    try:
        request = securitycentermanagement_v1.DeleteSecurityHealthAnalyticsCustomModuleRequest(
            name=f"{parent}/securityHealthAnalyticsCustomModules/{module_id}",
        )

        client.delete_security_health_analytics_custom_module(request=request)
        print(f"Deleted SecurityHealthAnalyticsCustomModule Successfully: {module_id}")
    except NotFound as e:
        print(f"Custom Module not found: {module_id}")
        raise e

Nächste Schritte

Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.