Skip to content

Commit

Permalink
Add secrets manager (#108)
Browse files Browse the repository at this point in the history
* add secrets manager
* add conditions
* refactor to support common way to add extra services
  • Loading branch information
matt-land authored and markpeek committed Dec 5, 2018
1 parent bf9960f commit 6909d2c
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -37,5 +37,8 @@ nosetests.xml
# Ignore vim swap files
.*.sw*

# Ignore intellij
.idea/

# Ignore virtualenv
env/
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -116,7 +116,7 @@ an AWS resource and auto-generate new files.
The following commands can be run to update the repo:

.. code-block:: sh
% pip install -r tools/requirements.txt
% rm -rf generated/
% python tools/gen.py
% diff -u awacs generated
Expand Down
8 changes: 4 additions & 4 deletions awacs/aws_marketplace.py
Expand Up @@ -6,7 +6,7 @@
from aws import Action as BaseAction
from aws import BaseARN

service_name = 'AWS Marketplace Metering Service'
service_name = 'AWS Marketplace'
prefix = 'aws-marketplace'


Expand All @@ -23,9 +23,9 @@ def __init__(self, resource='', region='', account=''):
account=account)


BatchMeterUsage = Action('BatchMeterUsage')
MeterUsage = Action('MeterUsage')
ResolveCustomer = Action('ResolveCustomer')
Subscribe = Action('Subscribe')
Unsubscribe = Action('Unsubscribe')
ViewSubscriptions = Action('ViewSubscriptions')
BatchMeterUsage = Action('BatchMeterUsage')
MeterUsage = Action('MeterUsage')
ResolveCustomer = Action('ResolveCustomer')
43 changes: 43 additions & 0 deletions awacs/secretsmanager.py
@@ -0,0 +1,43 @@
# Copyright (c) 2012-2013, Mark Peek <mark@peek.org>
# All rights reserved.
#
# See LICENSE file for full license.

from aws import Action as BaseAction
from aws import BaseARN

service_name = 'AWS Secrets Manager'
prefix = 'secretsmanager'


class Action(BaseAction):
def __init__(self, action=None):
sup = super(Action, self)
sup.__init__(prefix, action)


class ARN(BaseARN):
def __init__(self, resource='', region='', account=''):
sup = super(ARN, self)
sup.__init__(service=prefix, resource=resource, region=region,
account=account)


CancelRotateSecret = Action('CancelRotateSecret')
CreateSecret = Action('CreateSecret')
DeleteResourcePolicy = Action('DeleteResourcePolicy')
DeleteSecret = Action('DeleteSecret')
DescribeSecret = Action('DescribeSecret')
GetRandomPassword = Action('GetRandomPassword')
GetResourcePolicy = Action('GetResourcePolicy')
GetSecretValue = Action('GetSecretValue')
ListSecretVersionIds = Action('ListSecretVersionIds')
ListSecrets = Action('ListSecrets')
PutResourcePolicy = Action('PutResourcePolicy')
PutSecretValue = Action('PutSecretValue')
RestoreSecret = Action('RestoreSecret')
RotateSecre = Action('RotateSecre')
TagResource = Action('TagResource')
UntagResource = Action('UntagResource')
UpdateSecret = Action('UpdateSecret')
UpdateSecretVersionStage = Action('UpdateSecretVersionStage')
63 changes: 55 additions & 8 deletions tools/gen.py
Expand Up @@ -4,7 +4,10 @@
#
import json
import os
import urllib2
try:
from urllib2 import urlopen
except ImportError:
from urllib.request import urlopen
from slimit.parser import Parser
from slimit.visitors import nodevisitor
from slimit.visitors.ecmavisitor import ECMAVisitor
Expand Down Expand Up @@ -66,7 +69,7 @@ def __init__(self, *args, **kwargs):

basedir = 'generated'

response = urllib2.urlopen(aws_url)
response = urlopen(aws_url)
config = response.read()


Expand All @@ -87,7 +90,7 @@ def visit_UnaryOp(self, node):

visitor = JSONVisitor()
parser = Parser()
tree = parser.parse(config)
tree = parser.parse(config.decode('utf-8'))

flag = False
policy_editor_config = ""
Expand All @@ -106,17 +109,55 @@ def visit_UnaryOp(self, node):
except OSError:
pass

extra_services = [
('SMM Messages', {

# Extra services are for those not advertised in policies.js,
# but are available to be called via AWS apis. If/When these
# services are added to policies.js, the entry in extra_services
# will be ignored. IE, policies.js takes priority over
# extra_services entries.

extra_services = {
'SMM Messages': {
'StringPrefix': 'ssmmessages',
'Actions': [
'CreateControlChannel',
'CreateDataChannel',
'OpenControlChannel',
'OpenDataChannel',
],
},),
]
},
'AWS Secrets Manager': {
'ARNFormat': 'arn:aws:secretsmanager:'
'<region>:<account>'
':secret:<resourceType>/<resourcePath>',
'ARNRegex': '^arn:aws:secretsmanager:.+',
'Actions': [
'CancelRotateSecret', 'CreateSecret', 'DeleteResourcePolicy',
'DeleteSecret', 'DescribeSecret', 'GetRandomPassword',
'GetResourcePolicy', 'GetSecretValue', 'ListSecrets',
'ListSecretVersionIds', 'PutResourcePolicy',
'PutSecretValue', 'RestoreSecret', 'RotateSecre',
'TagResource', 'UntagResource', 'UpdateSecret',
'UpdateSecretVersionStage'
],
'HasResource': '!0',
'StringPrefix': 'secretsmanager',
'conditionKeys': [
'secretsmanager:Resource/AllowRotationLambdaArn',
'secretsmanager:Description',
'secretsmanager:ForceDeleteWithoutRecovery',
'secretsmanager:KmsKeyId',
'secretsmanager:Name',
'secretsmanager:RecoveryWindowInDays',
'secretsmanager:ResourceTag/<tagname>',
'secretsmanager:RotationLambdaArn',
'secretsmanager:SecretId',
'secretsmanager:VersionId',
'secretsmanager:VersionStage'
],
},
}


extra_actions = {
'cloudformation': [
Expand Down Expand Up @@ -213,8 +254,14 @@ def visit_UnaryOp(self, node):
],
}

# patch in the extra_services if they are not present in policies.js
for service_name in extra_services:
if not d['serviceMap'].get(service_name):
d['serviceMap'][service_name] = extra_services[service_name]


filename_seen = {}
for serviceName, serviceValue in d['serviceMap'].items() + extra_services:
for serviceName, serviceValue in d['serviceMap'].items():
prefix = serviceValue['StringPrefix']
service = prefix
# Handle prefix such as "directconnect:"
Expand Down
1 change: 1 addition & 0 deletions tools/requirements.txt
@@ -0,0 +1 @@
git+https://github.com/rspivak/slimit.git#egg=slimit

0 comments on commit 6909d2c

Please sign in to comment.