Mendapatkan setelan organisasi
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Menunjukkan cara mengambil konfigurasi setelan organisasi
Mempelajari lebih lanjut
Untuk dokumentasi mendetail yang menyertakan contoh kode ini, lihat artikel berikut:
Contoh kode
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],[],[],[],null,["Demonstrates how to retrieve organization settings configurations\n\nExplore further\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\nGo\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\nJava\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\nNode.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\nPython\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\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=securitycenter)."]]