diff --git a/rpe/resources/gcp.py b/rpe/resources/gcp.py index 0f7165f..883bf26 100644 --- a/rpe/resources/gcp.py +++ b/rpe/resources/gcp.py @@ -917,3 +917,41 @@ def _get_request_args(self): 'location': self._resource_data['location'], 'view': 'JOB_VIEW_DESCRIPTION' } + +class GcpRedisInstance(GoogleAPIResource): + + service_name = "redis" + resource_path = "projects.locations.instances" + version = "v1" + + required_resource_data = ['name', 'project_id', 'location'] + + resource_type = 'redis.googleapis.com/Instance' + + def _get_request_args(self): + return { + 'name': 'projects/{}/locations/{}/instances/{}'.format( + self._resource_data['project_id'], + self._resource_data['location'], + self._resource_data['name'] + ), + } + +class GcpMemcacheInstance(GoogleAPIResource): + + service_name = "memcache" + resource_path = "projects.locations.instances" + version = "v1" + + required_resource_data = ['name', 'project_id', 'location'] + + resource_type = 'memcache.googleapis.com/Instance' + + def _get_request_args(self): + return { + 'name': 'projects/{}/locations/{}/instances/{}'.format( + self._resource_data['project_id'], + self._resource_data['location'], + self._resource_data['name'] + ), + } diff --git a/tests/test_resources.py b/tests/test_resources.py index 7b7392d..e02a584 100644 --- a/tests/test_resources.py +++ b/tests/test_resources.py @@ -40,6 +40,8 @@ from rpe.resources.gcp import GcpComputeFirewall from rpe.resources.gcp import GcpComputeSubnetwork from rpe.resources.gcp import GcpDataflowJob +from rpe.resources.gcp import GcpRedisInstance +from rpe.resources.gcp import GcpMemcacheInstance test_project = "my_project" test_resource_name = "my_resource" @@ -244,6 +246,26 @@ resource_type='dataflow.googleapis.com/Job', name='//dataflow.googleapis.com/projects/my_project/locations/us-central1/jobs/my_resource' ), + ResourceTestCase( + resource_data={ + 'name': test_resource_name, + 'location': 'us-central1', + 'project_id': test_project + }, + cls=GcpRedisInstance, + resource_type='redis.googleapis.com/Instance', + name='//redis.googleapis.com/projects/my_project/locations/us-central1/instances/my_resource' + ), + ResourceTestCase( + resource_data={ + 'name': test_resource_name, + 'location': 'us-central1', + 'project_id': test_project + }, + cls=GcpMemcacheInstance, + resource_type='memcache.googleapis.com/Instance', + name='//memcache.googleapis.com/projects/my_project/locations/us-central1/instances/my_resource' + ), ] diff --git a/tests/test_resources_cai.py b/tests/test_resources_cai.py index 733baa6..91521fa 100644 --- a/tests/test_resources_cai.py +++ b/tests/test_resources_cai.py @@ -43,6 +43,8 @@ from rpe.resources.gcp import GcpIamServiceAccount from rpe.resources.gcp import GcpIamServiceAccountKey from rpe.resources.gcp import GcpDataflowJob +from rpe.resources.gcp import GcpRedisInstance +from rpe.resources.gcp import GcpMemcacheInstance client_kwargs = { 'credentials': Credentials(token='') @@ -212,6 +214,20 @@ }, resource_cls=GcpDataflowJob ), + CaiTestCase( + data={ + "name": "//redis.googleapis.com/projects/test-project/locations/us-central1/instances/test-resource", + "asset_type": "redis.googleapis.com/Instance", + }, + resource_cls=GcpRedisInstance + ), + CaiTestCase( + data={ + "name": "//memcache.googleapis.com/projects/test-project/locations/us-central1/instances/test-resource", + "asset_type": "memcache.googleapis.com/Instance", + }, + resource_cls=GcpMemcacheInstance + ), ]