Search in sources :

Example 1 with OrganizationSettings

use of com.google.cloud.securitycenter.v1.OrganizationSettings in project google-cloud-java by GoogleCloudPlatform.

the class OrganizationSnippets method getOrganizationSettings.

/**
 * Gets current settings for an organization.
 *
 * @param organizationName The organization to get settings for.
 */
// [START securitycenter_get_org_settings]
static OrganizationSettings getOrganizationSettings(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request to get OrganizationSettings for.
        // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
        GetOrganizationSettingsRequest.Builder request = GetOrganizationSettingsRequest.newBuilder().setName(organizationName.toString() + "/organizationSettings");
        // Call the API.
        OrganizationSettings response = client.getOrganizationSettings(request.build());
        System.out.println("Organization Settings:");
        System.out.println(response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : GetOrganizationSettingsRequest(com.google.cloud.securitycenter.v1.GetOrganizationSettingsRequest) OrganizationSettings(com.google.cloud.securitycenter.v1.OrganizationSettings) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 2 with OrganizationSettings

use of com.google.cloud.securitycenter.v1.OrganizationSettings in project google-cloud-java by GoogleCloudPlatform.

the class OrganizationSnippets method updateOrganizationSettings.

// [END securitycenter_get_org_settings]
/**
 * Update Asset Discovery OrganizationSettings for an organization
 *
 * @param organizationName The organization to update settings for.
 */
// [START securitycenter_enable_asset_discovery]
static OrganizationSettings updateOrganizationSettings(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // Start setting up a request to update OrganizationSettings for.
        // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
        OrganizationSettings organizationSettings = OrganizationSettings.newBuilder().setName(organizationName.toString() + "/organizationSettings").setEnableAssetDiscovery(true).build();
        FieldMask updateMask = FieldMask.newBuilder().addPaths("enable_asset_discovery").build();
        UpdateOrganizationSettingsRequest.Builder request = UpdateOrganizationSettingsRequest.newBuilder().setOrganizationSettings(organizationSettings).setUpdateMask(updateMask);
        // Call the API.
        OrganizationSettings response = client.updateOrganizationSettings(request.build());
        System.out.println("Organization Settings have been updated:");
        System.out.println(response);
        return response;
    } catch (IOException e) {
        throw new RuntimeException("Couldn't create client.", e);
    }
}
Also used : UpdateOrganizationSettingsRequest(com.google.cloud.securitycenter.v1.UpdateOrganizationSettingsRequest) OrganizationSettings(com.google.cloud.securitycenter.v1.OrganizationSettings) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) FieldMask(com.google.protobuf.FieldMask)

Aggregations

OrganizationSettings (com.google.cloud.securitycenter.v1.OrganizationSettings)2 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)2 IOException (java.io.IOException)2 GetOrganizationSettingsRequest (com.google.cloud.securitycenter.v1.GetOrganizationSettingsRequest)1 UpdateOrganizationSettingsRequest (com.google.cloud.securitycenter.v1.UpdateOrganizationSettingsRequest)1 FieldMask (com.google.protobuf.FieldMask)1