Get organization settings
Stay organized with collections
Save and categorize content based on your preferences.
Demonstrates how to retrieve organization settings configurations
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["# Get organization settings\n\nDemonstrates how to retrieve organization settings configurations\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Configuring asset discovery using the Security Command Center API](/security-command-center/docs/how-to-api-configure-asset-discovery)\n\nCode sample\n-----------\n\n### Go\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \tsecuritycenter \"cloud.google.com/go/securitycenter/apiv1\"\n \t\"cloud.google.com/go/securitycenter/apiv1/securitycenterpb\"\n )\n\n // getOrgSettings gets and prints the current organization asset discovery\n // settings to w. orgID is the numeric Organization ID.\n func getOrgSettings(w io.Writer, orgID string) error {\n \t// orgID := \"12321311\"\n \t// Instantiate a context and a security service client to make API calls.\n \tctx := context.Background()\n \tclient, err := securitycenter.https://cloud.google.com/go/docs/reference/cloud.google.com/go/securitycenter/latest/apiv1.html#cloud_google_com_go_securitycenter_apiv1_Client_NewClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"securitycenter.NewClient: %w\", err)\n \t}\n \tdefer client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/securitycenter/latest/apiv1.html#cloud_google_com_go_securitycenter_apiv1_Client_Close() // Closing the client safely cleans up background resources.\n\n \treq := &securitycenterpb.GetOrganizationSettingsRequest{\n \t\tName: fmt.Sprintf(\"organizations/%s/organizationSettings\", orgID),\n \t}\n \tsettings, err := client.GetOrganizationSettings(ctx, req)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"GetOrganizationSettings: %w\", err)\n \t}\n \tfmt.Fprintf(w, \"Retrieved Settings for: %s\\n\", settings.Name)\n \tfmt.Fprintf(w, \"Asset Discovery on? %v\", settings.EnableAssetDiscovery)\n \treturn nil\n }\n\n### Java\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n static OrganizationSettings getOrganizationSettings(OrganizationName organizationName) {\n try (SecurityCenterClient client = SecurityCenterClient.create()) {\n // Start setting up a request to get OrganizationSettings for.\n // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/\"123234324\");\n GetOrganizationSettingsRequest.Builder request =\n GetOrganizationSettingsRequest.newBuilder()\n .setName(organizationName.toString() + \"/organizationSettings\");\n\n // Call the API.\n OrganizationSettings response = client.getOrganizationSettings(request.build());\n\n System.out.println(\"Organization Settings:\");\n System.out.println(response);\n return response;\n } catch (IOException e) {\n throw new RuntimeException(\"Couldn't create client.\", e);\n }\n }\n\n### Node.js\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Imports the Google Cloud client library.\n const {SecurityCenterClient} = require('https://cloud.google.com/nodejs/docs/reference/security-center/latest/overview.html');\n\n // Creates a new client.\n const client = new https://cloud.google.com/nodejs/docs/reference/security-center/latest/overview.html();\n\n async function getOrgSettings() {\n // organizationId is the numeric ID of the organization.\n /*\n * TODO(developer): Uncomment the following lines\n */\n // const organizaionId = \"111122222444\";\n const orgName = client.organizationPath(organizationId);\n const [settings] = await client.getOrganizationSettings({\n name: `${orgName}/organizationSettings`,\n });\n\n console.log('Current settings: %j', settings);\n }\n getOrgSettings();\n\n### Python\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import securitycenter\n\n client = securitycenter.SecurityCenterClient()\n # organization_id is numeric ID for the organization. e.g.\n # organization_id = \"111112223333\"\n\n org_settings_name = client.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.services.security_center.SecurityCenterClient.html#google_cloud_securitycenter_v1_services_security_center_SecurityCenterClient_organization_settings_path(organization_id)\n\n org_settings = client.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.services.security_center.SecurityCenterClient.html#google_cloud_securitycenter_v1_services_security_center_SecurityCenterClient_get_organization_settings(request={\"name\": org_settings_name})\n print(org_settings)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=securitycenter)."]]