-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from whdalsrnt/master
feat: add metrics
- Loading branch information
Showing
17 changed files
with
300 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import logging | ||
from plugin.connector import GoogleCloudConnector | ||
|
||
__all__ = ["CloudIdentityConnector"] | ||
|
||
_LOGGER = logging.getLogger("spaceone") | ||
|
||
|
||
class CloudIdentityConnector(GoogleCloudConnector): | ||
google_client_service = "cloudidentity" | ||
version = "v1" | ||
|
||
def list_groups(self, customer_id): | ||
parent = f"customers/{customer_id}" | ||
result = self.client.groups().list(parent=parent).execute() | ||
print(result) | ||
return result.get("groups", []) | ||
|
||
def list_memberships(self, parent): | ||
result = self.client.groups().memberships(parent=parent).list().execute() | ||
return result.get("memberships", []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .service_account_manager import ServiceAccountManager | ||
from .role_manager import RoleManager | ||
from .permission_manager import PermissionManager | ||
# from .group_manager import GroupManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
from typing import Generator | ||
from spaceone.inventory.plugin.collector.lib import * | ||
from plugin.connector.cloud_identity_connector import CloudIdentityConnector | ||
from plugin.connector.resource_manager_v3_connector import ResourceManagerV3Connector | ||
from plugin.manager.base import ResourceManager | ||
|
||
_LOGGER = logging.getLogger("spaceone") | ||
|
||
|
||
class GroupManager(ResourceManager): | ||
service = "IAM" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
self.cloud_service_group = "IAM" | ||
self.cloud_service_type = "Group" | ||
self.service_code = None | ||
self.is_primary = False | ||
self.icon = "iam.svg" | ||
self.labels = [] | ||
self.metadata_path = "metadata/group.yaml" | ||
self.identity_connector = None | ||
self.rm_v3_connector = None | ||
|
||
def collect_cloud_services(self, options: dict, secret_data: dict, schema: str) -> Generator[dict, None, None]: | ||
self.identity_connector = CloudIdentityConnector(options, secret_data, schema) | ||
self.rm_v3_connector = ResourceManagerV3Connector(options, secret_data, schema) | ||
for organization in self.rm_v3_connector.search_organizations(): | ||
print(organization) | ||
customer_id = organization.get('directoryCustomerId') | ||
groups = self.identity_connector.list_groups(customer_id) | ||
print(groups) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
search: | ||
fields: | ||
- Status: data.status | ||
type: enum | ||
enums: | ||
- ENABLED: green.500 | ||
label: Enabled | ||
- DISABLED: red.500 | ||
label: Disabled | ||
- Role ID: data.name | ||
- Type: data.type | ||
type: enum | ||
enums: | ||
- PREDEFINED: gray.500 | ||
label: Predefined | ||
- CUSTOM: blue.500 | ||
label: Custom | ||
- Location: account | ||
- Permission Count: data.permissionCount | ||
data_type: integer | ||
- Role Launch Stage: data.stage | ||
|
||
table: | ||
sort: | ||
key: data.type | ||
fields: | ||
- Status: data.status | ||
type: enum | ||
enums: | ||
- ENABLED: green.500 | ||
name: Enabled | ||
type: state | ||
- DISABLED: red.500 | ||
name: Disabled | ||
type: state | ||
- Role ID: data.name | ||
is_optional: true | ||
- Permission Count: data.permissionCount | ||
data_type: integer | ||
- Type: data.type | ||
type: enum | ||
enums: | ||
- PREDEFINED: gray.500 | ||
name: Predefined | ||
- CUSTOM: blue.500 | ||
name: Custom | ||
- Location: account | ||
- Role Launch Stage: data.stage | ||
is_optional: true | ||
|
||
tabs.0: | ||
name: Details | ||
type: item | ||
fields: | ||
- Role ID: data.name | ||
- Name: name | ||
- Status: data.status | ||
type: enum | ||
enums: | ||
- ENABLED: green.500 | ||
name: Enabled | ||
type: state | ||
- DISABLED: red.500 | ||
name: Disabled | ||
type: state | ||
- Description: data.description | ||
- Type: data.type | ||
type: enum | ||
enums: | ||
- PREDEFINED: gray.500 | ||
name: Predefined | ||
- CUSTOM: blue.500 | ||
name: Custom | ||
- Location: account | ||
- Role Launch Stage: data.stage | ||
|
||
tabs.1: | ||
name: Permissions | ||
type: raw | ||
root_path: data.includedPermissions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
namespace_id: ns-google-cloud-iam-permission | ||
name: IAM/Permission | ||
category: ASSET | ||
resource_type: inventory.CloudService:google_cloud.IAM.Permission | ||
group: google_cloud | ||
icon: 'https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/google_cloud/iam.svg' | ||
version: '1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
metric_id: metric-google-cloud-iam-permission-count | ||
name: Permission Count | ||
metric_type: GAUGE | ||
resource_type: inventory.CloudService:google_cloud.IAM.Permission | ||
query_options: | ||
group_by: | ||
- key: data.type | ||
name: Permission Type | ||
default: true | ||
- key: account | ||
name: Google Project ID | ||
- key: data.status | ||
name: Status | ||
- key: data.inherited | ||
name: Inherited | ||
fields: | ||
value: | ||
operator: count | ||
unit: Count | ||
namespace_id: ns-google-cloud-iam-permission | ||
version: '1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
metric_id: metric-google-cloud-iam-rb-count | ||
name: Role Binding Count | ||
metric_type: GAUGE | ||
resource_type: inventory.CloudService:google_cloud.IAM.Permission | ||
query_options: | ||
unwind: | ||
path: data.bindings | ||
group_by: | ||
- key: data.type | ||
name: Principal Type | ||
default: true | ||
- key: data.memberId | ||
name: Principal ID | ||
- key: data.bindings.role.id | ||
name: Role ID | ||
- key: data.bindings.role.name | ||
name: Role Name | ||
- key: data.bindings.role.roleType | ||
name: Role Type | ||
- key: data.bindings.target.type | ||
name: Target Type | ||
- key: data.bindings.target.location | ||
name: Location | ||
- key: data.bindings.target.id | ||
name: Target ID | ||
fields: | ||
value: | ||
operator: count | ||
unit: Count | ||
namespace_id: ns-google-cloud-iam-permission | ||
version: '1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
namespace_id: ns-google-cloud-iam-role | ||
name: IAM/Role | ||
category: ASSET | ||
resource_type: inventory.CloudService:google_cloud.IAM.Role | ||
group: google_cloud | ||
icon: 'https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/google_cloud/iam.svg' | ||
version: '1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
metric_id: metric-google-cloud-iam-role-count | ||
name: Role Count | ||
metric_type: GAUGE | ||
resource_type: inventory.CloudService:google_cloud.IAM.Role | ||
query_options: | ||
group_by: | ||
- key: data.type | ||
name: Role Type | ||
default: true | ||
- key: account | ||
name: Location | ||
- key: data.status | ||
name: Status | ||
fields: | ||
value: | ||
operator: count | ||
unit: Count | ||
namespace_id: ns-google-cloud-iam-role | ||
version: '1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
namespace_id: ns-google-cloud-iam-sa | ||
name: IAM/ServiceAccount | ||
category: ASSET | ||
resource_type: inventory.CloudService:google_cloud.IAM.ServiceAccount | ||
group: google_cloud | ||
icon: 'https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/google_cloud/iam.svg' | ||
version: '1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
metric_id: metric-google-cloud-iam-sa-count | ||
name: Service Account Count | ||
metric_type: GAUGE | ||
resource_type: inventory.CloudService:google_cloud.IAM.ServiceAccount | ||
query_options: | ||
group_by: | ||
- key: data.projectId | ||
name: Google Project ID | ||
default: true | ||
- key: data.status | ||
name: Status | ||
fields: | ||
value: | ||
operator: count | ||
unit: Count | ||
namespace_id: ns-google-cloud-iam-sa | ||
version: '1.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
metric_id: metric-google-cloud-iam-sa-key-count | ||
name: Key Count | ||
metric_type: GAUGE | ||
resource_type: inventory.CloudService:google_cloud.IAM.ServiceAccount | ||
query_options: | ||
unwind: | ||
path: data.keys | ||
group_by: | ||
- key: data.projectId | ||
name: Google Project ID | ||
default: true | ||
- key: data.keys.status | ||
name: Status | ||
- key: data.keys.keyType | ||
name: Key Type | ||
- key: data.keys.keyAlgorithm | ||
name: Key Algorithm | ||
fields: | ||
value: | ||
operator: count | ||
unit: Count | ||
namespace_id: ns-google-cloud-iam-sa | ||
version: '1.0' |
Oops, something went wrong.