セキュリティ ソースの一覧表示
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
組織内のセキュリティ ソースを一覧表示する方法を説明します。
コードサンプル
Go
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Java
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Node.js
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Python
Security Command Center で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],[],[],[],null,["Demonstrates how to list all security sources in an organization\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 \t\"google.golang.org/api/iterator\"\n )\n\n // listSources prints all sources in orgID to w. orgID is the numeric\n // identifier of the organization.\n func listSources(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.ListSourcesRequest{\n \t\t// Parent must be in one of the following formats:\n \t\t//\t\t\"organizations/{orgId}\"\n \t\t//\t\t\"projects/{projectId}\"\n \t\t//\t\t\"folders/{folderId}\"\n \t\tParent: fmt.Sprintf(\"organizations/%s\", orgID),\n \t}\n \tit := client.ListSources(ctx, req)\n \tfor {\n \t\tsource, err := it.Next()\n \t\tif err == iterator.Done {\n \t\t\tbreak\n \t\t}\n \t\tif err != nil {\n \t\t\treturn fmt.Errorf(\"it.Next: %w\", err)\n \t\t}\n \t\tfmt.Fprintf(w, \"Source Name: %s, \", source.Name)\n \t\tfmt.Fprintf(w, \"Display name: %s, \", source.DisplayName)\n \t\tfmt.Fprintf(w, \"Description: %s\\n\", source.Description)\n \t}\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 ImmutableList\u003cSource\u003e listSources(OrganizationName organizationName) {\n try (SecurityCenterClient client = SecurityCenterClient.create()) {\n // Start setting up a request to list sources in an organization, project, or folder.\n // Parent must be in one of the following formats:\n // OrganizationName organizationName = OrganizationName.of(\"organization-id\");\n // ProjectName projectName = ProjectName.of(\"project-id\");\n // FolderName folderName = FolderName.of(\"folder-id\");\n ListSourcesRequest.Builder request =\n ListSourcesRequest.newBuilder().setParent(organizationName.toString());\n\n // Call the API.\n ListSourcesPagedResponse response = client.listSources(request.build());\n\n // This creates one list for all sources. If your organization has a large number of sources\n // this can cause out of memory issues. You can process them batches by returning\n // the Iterable returned response.iterateAll() directly.\n ImmutableList\u003cSource\u003e results = ImmutableList.copyOf(response.iterateAll());\n System.out.println(\"Sources:\");\n System.out.println(results);\n return results;\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 // organizationId is the numeric ID of the organization.\n /*\n * TODO(developer): Uncomment the following lines\n */\n // parent: must be in one of the following formats:\n // `organizations/${organization_id}`\n // `projects/${project_id}`\n // `folders/${folder_id}`\n const parent = `organizations/${organizationId}`;\n // Call the API with automatic pagination.\n async function listSources() {\n const [response] = await client.listSources({parent: parent});\n let count = 0;\n console.log('Sources:');\n Array.from(response).forEach(source =\u003e\n console.log('%d %j', ++count, source)\n );\n }\n\n listSources();\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_v1\n\n # Create a new client.\n client = securitycenter_v1.SecurityCenterClient()\n # 'parent' must be in one of the following formats:\n # \"organizations/{organization_id}\"\n # \"projects/{project_id}\"\n # \"folders/{folder_id}\"\n parent = f\"organizations/{organization_id}\"\n\n # Call the API and print out each existing source.\n for i, source in enumerate(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_list_sources(request={\"parent\": parent})):\n print(i, source)\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)."]]