Skip to content

Commit

Permalink
[azure][feat] Add PostgreSQL collection for cosmos-db resources (#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 authored Sep 2, 2024
1 parent 3b3c4cf commit 0b83034
Show file tree
Hide file tree
Showing 8 changed files with 939 additions and 10 deletions.
544 changes: 536 additions & 8 deletions plugins/azure/fix_plugin_azure/resource/cosmosdb.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions plugins/azure/test/collector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def test_collect(
config, Cloud(id="azure"), azure_subscription, credentials, core_feedback
)
subscription_collector.collect()
assert len(subscription_collector.graph.nodes) == 492
assert len(subscription_collector.graph.edges) == 754
assert len(subscription_collector.graph.nodes) == 505
assert len(subscription_collector.graph.edges) == 779

graph_collector = MicrosoftGraphOrganizationCollector(
config, Cloud(id="azure"), MicrosoftGraphOrganization(id="test", name="test"), credentials, core_feedback
Expand Down
6 changes: 6 additions & 0 deletions plugins/azure/test/cosmos-db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
AzureCosmosDBRestorableAccount,
AzureCosmosDBLocation,
AzureCosmosDBMongoDBCluster,
AzureCosmosDBPostgresqlCluster,
)


Expand All @@ -32,3 +33,8 @@ def test_cosmos_db_location(builder: GraphBuilder) -> None:
def test_mongo_db_cluster(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureCosmosDBMongoDBCluster, builder)
assert len(collected) == 1


def test_postgres_cluster(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureCosmosDBPostgresqlCluster, builder)
assert len(collected) == 1
136 changes: 136 additions & 0 deletions plugins/azure/test/files/cosmos-db/configurations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"value": [
{
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/array_nulls",
"name": "array_nulls",
"type": "Microsoft.DBforPostgreSQL/serverGroupsv2/configurations",
"systemData": {
"createdBy": "user1",
"createdByType": "User",
"createdAt": "2020-01-01T17:18:19.1234567Z",
"lastModifiedBy": "user2",
"lastModifiedByType": "User",
"lastModifiedAt": "2020-01-02T17:18:19.1234567Z"
},
"properties": {
"description": "Enable input of NULL elements in arrays.",
"dataType": "Boolean",
"allowedValues": "on,off",
"serverRoleGroupConfigurations": [
{
"role": "Coordinator",
"value": "on",
"defaultValue": "on",
"source": "system-default"
},
{
"role": "Worker",
"value": "off",
"defaultValue": "on",
"source": "user-override"
}
],
"provisioningState": "Succeeded"
}
},
{
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/backslash_quote",
"name": "backslash_quote",
"type": "Microsoft.DBforPostgreSQL/serverGroupsv2/configurations",
"systemData": {
"createdBy": "user1",
"createdByType": "User",
"createdAt": "2020-01-01T17:18:19.1234567Z",
"lastModifiedBy": "user2",
"lastModifiedByType": "User",
"lastModifiedAt": "2020-01-02T17:18:19.1234567Z"
},
"properties": {
"description": "Sets whether \"\\'\" is allowed in string literals.",
"dataType": "Enumeration",
"allowedValues": "safe_encoding,on,off",
"serverRoleGroupConfigurations": [
{
"role": "Coordinator",
"value": "off",
"defaultValue": "safe_encoding",
"source": "user-override"
},
{
"role": "Worker",
"value": "safe_encoding",
"defaultValue": "safe_encoding",
"source": "system-default"
}
],
"provisioningState": "Succeeded"
}
},
{
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/work_mem",
"name": "work_mem",
"type": "Microsoft.DBforPostgreSQL/serverGroupsv2/configurations",
"systemData": {
"createdBy": "user1",
"createdByType": "User",
"createdAt": "2020-01-01T17:18:19.1234567Z",
"lastModifiedBy": "user2",
"lastModifiedByType": "User",
"lastModifiedAt": "2020-01-02T17:18:19.1234567Z"
},
"properties": {
"description": "Sets the amount of memory to be used by internal sort operations and hash tables before writing to temporary disk files.",
"dataType": "Integer",
"allowedValues": "4096-2097151",
"serverRoleGroupConfigurations": [
{
"role": "Coordinator",
"value": "158720",
"defaultValue": "158720",
"source": "system-default"
},
{
"role": "Worker",
"value": "115712",
"defaultValue": "115712",
"source": "system-default"
}
],
"provisioningState": "Succeeded"
}
},
{
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/client_encoding",
"name": "client_encoding",
"type": "Microsoft.DBforPostgreSQL/serverGroupsv2/configurations",
"systemData": {
"createdBy": "user1",
"createdByType": "User",
"createdAt": "2020-01-01T17:18:19.1234567Z",
"lastModifiedBy": "user2",
"lastModifiedByType": "User",
"lastModifiedAt": "2020-01-02T17:18:19.1234567Z"
},
"properties": {
"description": "Sets the client's character set encoding.",
"dataType": "Enumeration",
"allowedValues": "BIG5,EUC_CN,EUC_JP,EUC_JIS_2004,EUC_KR,EUC_TW,GB18030,GBK,ISO_8859_5,ISO_8859_6,ISO_8859_7,ISO_8859_8,JOHAB,KOI8R,KOI8U,LATIN1,LATIN2,LATIN3,LATIN4,LATIN5,LATIN6,LATIN7,LATIN8,LATIN9,LATIN10,MULE_INTERNAL,SJIS,SHIFT_JIS_2004,SQL_ASCII,UHC,UTF8,WIN866,WIN874,WIN1250,WIN1251,WIN1252,WIN1253,WIN1254,WIN1255,WIN1256,WIN1257,WIN1258",
"serverRoleGroupConfigurations": [
{
"role": "Coordinator",
"value": "ISO_8859_7",
"defaultValue": "sql_ascii",
"source": "user-override"
},
{
"role": "Worker",
"value": "ISO_8859_7",
"defaultValue": "sql_ascii",
"source": "user-override"
}
],
"provisioningState": "Succeeded"
}
}
]
}
58 changes: 58 additions & 0 deletions plugins/azure/test/files/cosmos-db/privateEndpointConnections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"value": [
{
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/privateEndpointConnections/private-endpoint-connection-name",
"name": "private-endpoint-connection-name",
"type": "Microsoft.DBforPostgreSQL/serverGroupsv2/privateEndpointConnections",
"systemData": {
"createdBy": "user1",
"createdByType": "User",
"createdAt": "2022-01-01T17:18:19.1234567Z",
"lastModifiedBy": "user2",
"lastModifiedByType": "User",
"lastModifiedAt": "2022-01-02T17:18:19.1234567Z"
},
"properties": {
"provisioningState": "Succeeded",
"privateEndpoint": {
"id": "/subscriptions/55555555-6666-7777-8888-999999999999/resourceGroups/Default-Network/providers/Microsoft.Network/privateEndpoints/private-endpoint-name"
},
"groupIds": [
"coordinator"
],
"privateLinkServiceConnectionState": {
"status": "Approved",
"description": "Auto-approved",
"actionsRequired": "None"
}
}
},
{
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/privateEndpointConnections/private-endpoint-connection-name-2",
"name": "private-endpoint-connection-name-2",
"type": "Microsoft.DBforPostgreSQL/serverGroupsv2/privateEndpointConnections",
"systemData": {
"createdBy": "user1",
"createdByType": "User",
"createdAt": "2022-01-01T17:18:19.1234567Z",
"lastModifiedBy": "user2",
"lastModifiedByType": "User",
"lastModifiedAt": "2022-01-02T17:18:19.1234567Z"
},
"properties": {
"provisioningState": "Succeeded",
"privateEndpoint": {
"id": "/subscriptions/55555555-6666-7777-8888-999999999999/resourceGroups/Default-Network/providers/Microsoft.Network/privateEndpoints/private-endpoint-name-2"
},
"groupIds": [
"worker-0"
],
"privateLinkServiceConnectionState": {
"status": "Approved",
"description": "Auto-approved",
"actionsRequired": "None"
}
}
}
]
}
36 changes: 36 additions & 0 deletions plugins/azure/test/files/cosmos-db/roles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"value": [
{
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/roles/role1",
"name": "role1",
"type": "Microsoft.DBforPostgreSQL/serverGroupsv2/roles",
"systemData": {
"createdBy": "user1",
"createdByType": "User",
"createdAt": "2020-01-01T17:18:19.1234567Z",
"lastModifiedBy": "user2",
"lastModifiedByType": "User",
"lastModifiedAt": "2020-01-02T17:18:19.1234567Z"
},
"properties": {
"provisioningState": "Succeeded"
}
},
{
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/roles/role2",
"name": "role2",
"type": "Microsoft.DBforPostgreSQL/serverGroupsv2/roles",
"systemData": {
"createdBy": "user1",
"createdByType": "User",
"createdAt": "2020-01-01T17:18:19.1234567Z",
"lastModifiedBy": "user2",
"lastModifiedByType": "User",
"lastModifiedAt": "2020-01-02T17:18:19.1234567Z"
},
"properties": {
"provisioningState": "Succeeded"
}
}
]
}
74 changes: 74 additions & 0 deletions plugins/azure/test/files/cosmos-db/serverGroupsv2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"nextLink": null,
"value": [
{
"id": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster1",
"name": "testcluster1",
"type": "Microsoft.DBforPostgreSQL/serverGroupsv2",
"tags": {
"additionalProp1": "string"
},
"location": "eastus",
"systemData": {
"createdBy": "user1",
"createdByType": "User",
"createdAt": "2020-01-01T17:18:19.1234567Z",
"lastModifiedBy": "user2",
"lastModifiedByType": "User",
"lastModifiedAt": "2020-01-02T17:18:19.1234567Z"
},
"properties": {
"provisioningState": "Succeeded",
"state": "Ready",
"postgresqlVersion": "14",
"citusVersion": "11.1",
"maintenanceWindow": {
"dayOfWeek": 0,
"startHour": 0,
"startMinute": 0,
"customWindow": "Disabled"
},
"aadAuthEnabled": "disabled",
"administratorLogin": "citus",
"dataEncryption": {
"type": "SystemManaged"
},
"passwordEnabled": "enabled",
"preferredPrimaryZone": "1",
"enableHa": false,
"enableShardsOnCoordinator": false,
"coordinatorServerEdition": "GeneralPurpose",
"coordinatorStorageQuotaInMb": 2097152,
"coordinatorVCores": 4,
"coordinatorEnablePublicIpAccess": true,
"databaseName": "citus",
"nodeServerEdition": "MemoryOptimized",
"nodeCount": 2,
"nodeStorageQuotaInMb": 2097152,
"nodeVCores": 8,
"nodeEnablePublicIpAccess": false,
"serverNames": [
{
"name": "testcluster1-c",
"fullyQualifiedDomainName": "testcluster1-c.postgres.database.azure.com"
},
{
"name": "testcluster1-w0",
"fullyQualifiedDomainName": "testcluster1-w0.postgres.database.azure.com"
},
{
"name": "testcluster1-w1",
"fullyQualifiedDomainName": "testcluster1-w1.postgres.database.azure.com"
}
],
"sourceResourceId": null,
"readReplicas": [
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-01",
"/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-02"
],
"earliestRestoreTime": "2020-09-14T00:00:37.467Z",
"privateEndpointConnections": []
}
}
]
}
Loading

0 comments on commit 0b83034

Please sign in to comment.