forked from cloud-custodian/cloud-custodian
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from cloud-custodian/master
Sync with Original
- Loading branch information
Showing
101 changed files
with
4,713 additions
and
1,109 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,115 @@ | ||
# Copyright The Cloud Custodian Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from c7n.manager import resources | ||
from c7n.query import QueryResourceManager, TypeInfo | ||
from c7n.filters.kms import KmsRelatedFilter | ||
from c7n.tags import RemoveTag, Tag, TagDelayedAction, TagActionFilter | ||
|
||
|
||
@resources.register('airflow') | ||
class ApacheAirflow(QueryResourceManager): | ||
class resource_type(TypeInfo): | ||
service = 'mwaa' | ||
id = name = 'Name' | ||
enum_spec = ('list_environments', 'Environments', None) | ||
detail_spec = ('get_environment', 'Name', None, 'Environment') | ||
arn = 'Arn' | ||
arn_type = 'environment' | ||
cfn_type = 'AWS::MWAA::Environment' | ||
permission_prefix = 'airflow' | ||
|
||
permissions = ( | ||
'airflow:GetEnvironment', | ||
'airflow:ListEnvironments', | ||
) | ||
|
||
def augment(self, resources): | ||
resources = super(ApacheAirflow, self).augment(resources) | ||
for r in resources: | ||
r['Tags'] = [{'Key': k, 'Value': v} for k, v in r.get('Tags', {}).items()] | ||
return resources | ||
|
||
|
||
@ApacheAirflow.filter_registry.register('kms-key') | ||
class ApacheAirflowKmsFilter(KmsRelatedFilter): | ||
""" | ||
Filter a Managed Workflow for Apache Airflow environment by its associcated kms key | ||
and optionally the aliasname of the kms key by using 'c7n:AliasName' | ||
:example: | ||
.. code-block:: yaml | ||
policies: | ||
- name: airflow-kms-key-filter | ||
resource: airflow | ||
filters: | ||
- type: kms-key | ||
key: c7n:AliasName | ||
value: alias/aws/mwaa | ||
""" | ||
RelatedIdsExpression = 'KmsKey' | ||
|
||
|
||
@ApacheAirflow.action_registry.register('tag') | ||
class TagApacheAirflow(Tag): | ||
"""Action to create tag(s) on a Managed Workflow for Apache Airflow environment | ||
:example: | ||
.. code-block:: yaml | ||
policies: | ||
- name: tag-airflow | ||
resource: airflow | ||
filters: | ||
- "tag:target-tag": absent | ||
actions: | ||
- type: tag | ||
key: target-tag | ||
value: target-tag-value | ||
""" | ||
|
||
permissions = ('airflow:TagResource',) | ||
|
||
def process_resource_set(self, client, airflow, new_tags): | ||
for r in airflow: | ||
try: | ||
client.tag_resource( | ||
ResourceArn=r['Arn'], | ||
Tags={t['Key']: t['Value'] for t in new_tags}) | ||
except client.exceptions.ResourceNotFound: | ||
continue | ||
|
||
|
||
@ApacheAirflow.action_registry.register('remove-tag') | ||
class UntagApacheAirflow(RemoveTag): | ||
"""Action to remove tag(s) on a Managed Workflow for Apache Airflow environment | ||
:example: | ||
.. code-block:: yaml | ||
policies: | ||
- name: airflow-remove-tag | ||
resource: airflow | ||
filters: | ||
- "tag:OutdatedTag": present | ||
actions: | ||
- type: remove-tag | ||
tags: ["OutdatedTag"] | ||
""" | ||
|
||
permissions = ('airflow:UntagResource',) | ||
|
||
def process_resource_set(self, client, airflow, tags): | ||
for r in airflow: | ||
try: | ||
client.untag_resource(ResourceArn=r['Arn'], tagKeys=tags) | ||
except client.exceptions.ResourceNotFound: | ||
continue | ||
|
||
|
||
ApacheAirflow.filter_registry.register('marked-for-op', TagActionFilter) | ||
ApacheAirflow.action_registry.register('mark-for-op', TagDelayedAction) |
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,2 +1,2 @@ | ||
# Generated via tools/dev/poetrypkg.py | ||
version = "0.9.13" | ||
version = "0.9.14" |
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
Oops, something went wrong.