-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gcp - add artifact-repository resource (#8444)
- Loading branch information
1 parent
38774f2
commit 4a3c396
Showing
10 changed files
with
151 additions
and
7 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
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,46 @@ | ||
# Copyright The Cloud Custodian Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import json | ||
from pathlib import Path | ||
|
||
from .provider import resources | ||
from .query import TypeInfo | ||
|
||
|
||
REGION_DATA_PATH = Path(__file__).parent / "regions.json" | ||
|
||
|
||
@resources.register('region') | ||
class Region: | ||
|
||
class resource_type(TypeInfo): | ||
|
||
name = id = 'name' | ||
scope = 'global' | ||
default_report_fields = ['name'] | ||
service = 'regions' | ||
|
||
filter_registry = {} | ||
action_registry = {} | ||
|
||
def __init__(self, ctx=None, data=()): | ||
self.ctx = ctx | ||
self.data = data | ||
with open(REGION_DATA_PATH) as fh: | ||
self.regions = json.load(fh) | ||
|
||
def get_permissions(self): | ||
return () | ||
|
||
def resources(self, resource_ids=()): | ||
if resource_ids: | ||
return [{'name': r} for r in self.regions if r in resource_ids] | ||
elif 'query' in self.data: | ||
qregions = {q['name'] for q in self.data['query']} | ||
return [{'name': r} for r in self.regions if r in qregions] | ||
else: | ||
return [{'name': r} for r in self.regions] | ||
|
||
@classmethod | ||
def get_regions(cls): | ||
return list(cls().regions) |
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 @@ | ||
from c7n.utils import local_session | ||
from c7n_gcp.provider import resources | ||
from c7n_gcp.query import RegionalResourceManager, ChildTypeInfo | ||
|
||
|
||
@resources.register('artifact-repository') | ||
class ArtifactRegistryRepository(RegionalResourceManager): | ||
"""Artifact Registry Repository | ||
https://cloud.google.com/artifact-registry/docs/reference/rest/v1/projects.locations.repositories | ||
""" | ||
class resource_type(ChildTypeInfo): | ||
service = 'artifactregistry' | ||
version = 'v1' | ||
component = 'projects.locations.repositories' | ||
enum_spec = ('list', 'repositories[]', None) | ||
scope = 'parent' | ||
name = id = 'id' | ||
parent_spec = { | ||
'resource': 'region', | ||
'child_enum_params': { | ||
('name', 'region')}, | ||
'use_child_query': True, | ||
} | ||
permissions = ('artifactregistry.repositories.list',) | ||
default_report_fields = ['displayName', 'expireTime'] | ||
|
||
def _get_child_enum_args(self, parent_instance): | ||
return { | ||
'parent': 'projects/{}/locations/{}'.format( | ||
local_session(self.session_factory).get_default_project(), | ||
parent_instance['name'], | ||
) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
...ositories-query/get-v1-projects-cloud-custodian-locations-us-central1-repositories_1.json
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,28 @@ | ||
{ | ||
"headers": { | ||
"content-type": "application/json; charset=UTF-8", | ||
"vary": "Origin, X-Origin, Referer", | ||
"date": "Mon, 18 Jul 2022 13:03:45 GMT", | ||
"server": "ESF", | ||
"cache-control": "private", | ||
"x-xss-protection": "0", | ||
"x-frame-options": "SAMEORIGIN", | ||
"x-content-type-options": "nosniff", | ||
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"", | ||
"transfer-encoding": "chunked", | ||
"status": "200", | ||
"content-length": "251", | ||
"-content-encoding": "gzip", | ||
"content-location": "https://artifactregistry.googleapis.com/v1/projects/cloud-custodian/locations/us-central1/repositories?alt=json" | ||
}, | ||
"body": { | ||
"repositories": [ | ||
{ | ||
"name": "projects/cloud-custodian/locations/us-central1/repositories/test", | ||
"format": "DOCKER", | ||
"createTime": "2022-07-18T12:12:41.936064Z", | ||
"updateTime": "2022-07-18T12:12:41.936064Z" | ||
} | ||
] | ||
} | ||
} |
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,17 @@ | ||
from gcp_common import BaseTest | ||
|
||
|
||
class ArtifactRegistryRepositoryTest(BaseTest): | ||
|
||
def test_query(self): | ||
factory = self.replay_flight_data('artifactregistry-repositories-query') | ||
p = self.load_policy({ | ||
'name': 'artifact', | ||
'resource': 'gcp.artifact-repository'}, | ||
config={'region': 'us-central1'}, | ||
session_factory=factory) | ||
resources = p.run() | ||
|
||
self.assertTrue(len(resources), 1) | ||
self.assertEqual(resources[0]['name'], 'projects/cloud-custodian/' | ||
'locations/us-central1/repositories/test') |
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