Skip to content

Commit

Permalink
azure - servicebus-namespace resource (#8536)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiteshmck committed May 8, 2023
1 parent 4a3c396 commit 9ba2a82
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 1 deletion.
1 change: 1 addition & 0 deletions tools/c7n_azure/c7n_azure/resources/resource_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"azure.roledefinition": "c7n_azure.resources.access_control.RoleDefinition",
"azure.routetable": "c7n_azure.resources.route_table.RouteTable",
"azure.search": "c7n_azure.resources.search.SearchService",
"azure.servicebus-namespace": "c7n_azure.resources.servicebus_namespace.ServiceBusNamespace",
"azure.service-fabric-cluster": "c7n_azure.resources.service_fabric.ServiceFabricCluster",
"azure.service-fabric-cluster-managed": "c7n_azure.resources.service_fabric.ServiceFabricClusterManaged", # noqa
"azure.sql-database": "c7n_azure.resources.sqldatabase.SqlDatabase",
Expand Down
39 changes: 39 additions & 0 deletions tools/c7n_azure/c7n_azure/resources/servicebus_namespace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0

from c7n_azure.provider import resources
from c7n_azure.resources.arm import ArmResourceManager


@resources.register('servicebus-namespace')
class ServiceBusNamespace(ArmResourceManager):
"""Azure Service Bus Namespace Resource
:example:
Returns Service Bus Namespace resources
.. code-block:: yaml
policies:
- name: basic-servicebus-namespace
resource: azure.servicebus-namespace
filters:
- type: value
key: authorizationRules
value: present
"""

class resource_type(ArmResourceManager.resource_type):
doc_groups = ['Events']

service = 'azure.mgmt.servicebus'
client = 'ServiceBusManagementClient'
enum_spec = ('namespaces', 'list', None)
default_report_fields = (
'name',
'location',
'resourceGroup'
)
resource_type = 'Microsoft.ServiceBus/namespaces'
21 changes: 20 additions & 1 deletion tools/c7n_azure/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tools/c7n_azure/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ azure-mgmt-servicefabric = "^1.0.0"
azure-mgmt-trafficmanager = "^0.51.0"
azure-mgmt-frontdoor = "^1.0.0"
azure-mgmt-security = "^1.0.0"
azure-mgmt-servicebus = "^8.2.0"

[tool.poetry.dev-dependencies]
# setup custodian as a dev dependency
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"version": 1,
"interactions": [
{
"request": {
"method": "GET",
"uri": "https://management.azure.com/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/providers/Microsoft.ServiceBus/namespaces?api-version=2021-11-01",
"body": null,
"headers": {}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"content-type": [
"application/json; charset=utf-8"
],
"date": [
"Thu, 04 May 2023 15:30:01 GMT"
],
"cache-control": [
"no-cache"
],
"x-ms-inline-count": [
""
],
"server-sb": [
"Service-Bus-Resource-Provider/SN1"
],
"content-length": [
"745"
]
},
"body": {
"data": {
"value": [
{
"sku": {
"name": "Standard",
"tier": "Standard"
},
"id": "/subscriptions/ea42f556-5106-4743-99b0-c129bfa71a47/resourceGroups/test_servicebus/providers/Microsoft.ServiceBus/namespaces/cctestservicebusnamespacejv67tef5di5hy",
"name": "cctestservicebusnamespacejv67tef5di5hy",
"type": "Microsoft.ServiceBus/Namespaces",
"location": "East US",
"tags": {
"product_id": "13742"
},
"properties": {
"disableLocalAuth": false,
"zoneRedundant": false,
"provisioningState": "Succeeded",
"metricId": "ea42f556-5106-4743-99b0-c129bfa71a47:cctestservicebusnamespacejv67tef5di5hy",
"createdAt": "2023-05-04T15:28:25.363Z",
"updatedAt": "2023-05-04T15:29:08.213Z",
"serviceBusEndpoint": "https://cctestservicebusnamespacejv67tef5di5hy.servicebus.windows.net:443/",
"status": "Active"
}
}
]
}
}
}
}
]
}
24 changes: 24 additions & 0 deletions tools/c7n_azure/tests_azure/templates/servicebus-namespace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"namespaceName": {
"type": "string",
"defaultValue": "[concat('cctestservicebusnamespace', uniqueString(resourceGroup().id))]"
}
},
"resources": [
{
"type": "Microsoft.ServiceBus/namespaces",
"apiVersion": "2021-11-01",
"name": "[parameters('namespaceName')]",
"location": "eastus",
"properties": {
"sku": {
"name": "Standard"
},
"enableHttpsTrafficOnly": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0
from ..azure_common import BaseTest


class ServiceBusNamespaceTest(BaseTest):
def test_azure_servicebus_namespace_schema_validate(self):
p = self.load_policy({
'name': 'test-azure-servicebus-namespace-schema-validate',
'resource': 'azure.servicebus-namespace'
}, validate=True)
self.assertTrue(p)

def test_find_by_name(self):
p = self.load_policy({
'name': 'test-azure-azure-servicebus-namespace',
'resource': 'azure.servicebus-namespace',
'filters': [
{'type': 'value',
'key': 'name',
'value': 'cctestservicebusnamespacejv67tef5di5hy'}],
})
resources = p.run()
self.assertEqual(len(resources), 1)

0 comments on commit 9ba2a82

Please sign in to comment.