필터를 사용해 애셋 그룹화
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
애셋을 유형별로 필터링하고 그룹화하는 방법을 보여줍니다.
코드 샘플
Java
Security Command Center에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
Python
Security Command Center에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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 filter and group assets by type\n\nCode sample \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\u003cGroupResult\u003e groupAssetsWithFilter(OrganizationName organizationName) {\n try (SecurityCenterClient client = SecurityCenterClient.create()) {\n // Start setting up a request to filter all assets by type and group them by project in an\n // organization.\n // You can also use a project or folder as a parent resource and filter assets in them\n // respectively.\n GroupAssetsRequest.Builder request =\n GroupAssetsRequest.newBuilder()\n .setFilter(\n \"security_center_properties.resource_type=\\\"google.cloud.resourcemanager.Project\\\"\")\n .setGroupBy(\"security_center_properties.resource_project\")\n .setParent(organizationName.toString());\n\n // Call the API.\n GroupAssetsPagedResponse response = client.groupAssets(request.build());\n\n // This creates one list for all assets. If your organization has a large number of assets\n // this can cause out of memory issues. You can process them batches by returning\n // the Iterable returned response.iterateAll() directly.\n ImmutableList\u003cGroupResult\u003e results = ImmutableList.copyOf(response.iterateAll());\n System.out.println(\"All assets:\");\n System.out.println(results);\n return results;\n } catch (IOException e) {\n throw new RuntimeException(\"Couldn't create client.\", e);\n }\n }\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\n # 'organization_id' is the numeric ID of the organization.\n # organization_id = \"1234567777\"\n org_name = f\"organizations/{organization_id}\"\n\n group_by_type = \"security_center_properties.resource_type\"\n only_projects = (\n \"security_center_properties.resource_type=\"\n + '\"google.cloud.resourcemanager.Project\"'\n )\n # You can also use a project/ folder as a parent resource and filter assets in them\n # respectively.\n result_iterator = 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_group_assets(\n request={\"parent\": org_name, \"group_by\": group_by_type, \"filter\": only_projects}\n )\n for i, result in enumerate(result_iterator):\n print((i + 1), result)\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)."]]