cleaning up files
This commit is contained in:
parent
e35d99ff09
commit
921a993330
9
file.tmp
9
file.tmp
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
AWSTemplateFormatVersion: '2010-09-09'
|
|
||||||
Description: Simple CloudFormation Test Template
|
|
||||||
Resources:
|
|
||||||
S3Bucket:
|
|
||||||
Type: AWS::S3::Bucket
|
|
||||||
Properties:
|
|
||||||
AccessControl: PublicRead
|
|
||||||
BucketName: cf-test-bucket-1
|
|
@ -51,8 +51,8 @@ class Policy(BaseModel):
|
|||||||
self.default_version_id = default_version_id or 'v1'
|
self.default_version_id = default_version_id or 'v1'
|
||||||
self.versions = [PolicyVersion(self.arn, document, True)]
|
self.versions = [PolicyVersion(self.arn, document, True)]
|
||||||
|
|
||||||
self.create_datetime = datetime.now(pytz.utc)
|
self.create_datetime = datetime.strftime(datetime.utcnow(), "%Y-%m-%dT%H:%M:%SZ")
|
||||||
self.update_datetime = datetime.now(pytz.utc)
|
self.update_datetime = datetime.strftime(datetime.utcnow(), "%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
|
|
||||||
class SAMLProvider(BaseModel):
|
class SAMLProvider(BaseModel):
|
||||||
@ -76,7 +76,7 @@ class PolicyVersion(object):
|
|||||||
self.is_default = is_default
|
self.is_default = is_default
|
||||||
self.version_id = 'v1'
|
self.version_id = 'v1'
|
||||||
|
|
||||||
self.create_datetime = datetime.now(pytz.utc)
|
self.create_datetime = datetime.strftime(datetime.utcnow(), "%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
|
||||||
|
|
||||||
class ManagedPolicy(Policy):
|
class ManagedPolicy(Policy):
|
||||||
@ -132,8 +132,9 @@ class Role(BaseModel):
|
|||||||
self.path = path or '/'
|
self.path = path or '/'
|
||||||
self.policies = {}
|
self.policies = {}
|
||||||
self.managed_policies = {}
|
self.managed_policies = {}
|
||||||
self.create_date = datetime.now(pytz.utc)
|
self.create_date = datetime.strftime(datetime.utcnow(), "%Y-%m-%dT%H:%M:%SZ")
|
||||||
self.tags = {}
|
self.tags = {}
|
||||||
|
self.description = ""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||||
@ -473,6 +474,10 @@ class IAMBackend(BaseBackend):
|
|||||||
policy = arns[policy_arn]
|
policy = arns[policy_arn]
|
||||||
policy.attach_to(self.get_role(role_name))
|
policy.attach_to(self.get_role(role_name))
|
||||||
|
|
||||||
|
def update_role_description(self, role_name, role_description):
|
||||||
|
role = self.get_role(role_name)
|
||||||
|
role.description = role_description
|
||||||
|
|
||||||
def detach_role_policy(self, policy_arn, role_name):
|
def detach_role_policy(self, policy_arn, role_name):
|
||||||
arns = dict((p.arn, p) for p in self.managed_policies.values())
|
arns = dict((p.arn, p) for p in self.managed_policies.values())
|
||||||
try:
|
try:
|
||||||
|
@ -107,6 +107,10 @@ class IamResponse(BaseResponse):
|
|||||||
template = self.response_template(LIST_POLICIES_TEMPLATE)
|
template = self.response_template(LIST_POLICIES_TEMPLATE)
|
||||||
return template.render(policies=policies, marker=marker)
|
return template.render(policies=policies, marker=marker)
|
||||||
|
|
||||||
|
def list_entities_for_policy(self):
|
||||||
|
template = self.response_template(LIST_ENTITIES_FOR_POLICY_TEMPLATE)
|
||||||
|
return template.render()
|
||||||
|
|
||||||
def create_role(self):
|
def create_role(self):
|
||||||
role_name = self._get_param('RoleName')
|
role_name = self._get_param('RoleName')
|
||||||
path = self._get_param('Path')
|
path = self._get_param('Path')
|
||||||
@ -169,6 +173,20 @@ class IamResponse(BaseResponse):
|
|||||||
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
|
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
|
||||||
return template.render(name="UpdateAssumeRolePolicyResponse")
|
return template.render(name="UpdateAssumeRolePolicyResponse")
|
||||||
|
|
||||||
|
def update_role_description(self):
|
||||||
|
role_name = self._get_param('RoleName')
|
||||||
|
description = self._get_param('Description')
|
||||||
|
role = iam_backend.update_role_description(role_name,description)
|
||||||
|
template = self.response_template(UPDATE_ROLE_DESCRIPTION_TEMPLATE)
|
||||||
|
return template.render(role=role)
|
||||||
|
|
||||||
|
def update_role(self):
|
||||||
|
role_name = self._get_param('RoleName')
|
||||||
|
description = self._get_param('Description')
|
||||||
|
role = iam_backend.update_role_description(role_name,description)
|
||||||
|
template = self.response_template(UPDATE_ROLE_DESCRIPTION_TEMPLATE)
|
||||||
|
return template.render(role=role)
|
||||||
|
|
||||||
def create_policy_version(self):
|
def create_policy_version(self):
|
||||||
policy_arn = self._get_param('PolicyArn')
|
policy_arn = self._get_param('PolicyArn')
|
||||||
policy_document = self._get_param('PolicyDocument')
|
policy_document = self._get_param('PolicyDocument')
|
||||||
@ -654,6 +672,33 @@ class IamResponse(BaseResponse):
|
|||||||
template = self.response_template(UNTAG_ROLE_TEMPLATE)
|
template = self.response_template(UNTAG_ROLE_TEMPLATE)
|
||||||
return template.render()
|
return template.render()
|
||||||
|
|
||||||
|
LIST_ENTITIES_FOR_POLICY_TEMPLATE = """<ListEntitiesForPolicyResponse>
|
||||||
|
<ListEntitiesForPolicyResult>
|
||||||
|
<PolicyRoles>
|
||||||
|
<member>
|
||||||
|
<RoleName>DevRole</RoleName>
|
||||||
|
</member>
|
||||||
|
</PolicyRoles>
|
||||||
|
<PolicyGroups>
|
||||||
|
<member>
|
||||||
|
<GroupName>Dev</GroupName>
|
||||||
|
</member>
|
||||||
|
</PolicyGroups>
|
||||||
|
<IsTruncated>false</IsTruncated>
|
||||||
|
<PolicyUsers>
|
||||||
|
<member>
|
||||||
|
<UserName>Alice</UserName>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<UserName>Bob</UserName>
|
||||||
|
</member>
|
||||||
|
</PolicyUsers>
|
||||||
|
</ListEntitiesForPolicyResult>
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>eb358e22-9d1f-11e4-93eb-190ecEXAMPLE</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</ListEntitiesForPolicyResponse>"""
|
||||||
|
|
||||||
|
|
||||||
ATTACH_ROLE_POLICY_TEMPLATE = """<AttachRolePolicyResponse>
|
ATTACH_ROLE_POLICY_TEMPLATE = """<AttachRolePolicyResponse>
|
||||||
<ResponseMetadata>
|
<ResponseMetadata>
|
||||||
@ -696,12 +741,12 @@ CREATE_POLICY_TEMPLATE = """<CreatePolicyResponse>
|
|||||||
<Policy>
|
<Policy>
|
||||||
<Arn>{{ policy.arn }}</Arn>
|
<Arn>{{ policy.arn }}</Arn>
|
||||||
<AttachmentCount>{{ policy.attachment_count }}</AttachmentCount>
|
<AttachmentCount>{{ policy.attachment_count }}</AttachmentCount>
|
||||||
<CreateDate>{{ policy.create_datetime.isoformat() }}</CreateDate>
|
<CreateDate>{{ policy.create_datetime }}</CreateDate>
|
||||||
<DefaultVersionId>{{ policy.default_version_id }}</DefaultVersionId>
|
<DefaultVersionId>{{ policy.default_version_id }}</DefaultVersionId>
|
||||||
<Path>{{ policy.path }}</Path>
|
<Path>{{ policy.path }}</Path>
|
||||||
<PolicyId>{{ policy.id }}</PolicyId>
|
<PolicyId>{{ policy.id }}</PolicyId>
|
||||||
<PolicyName>{{ policy.name }}</PolicyName>
|
<PolicyName>{{ policy.name }}</PolicyName>
|
||||||
<UpdateDate>{{ policy.update_datetime.isoformat() }}</UpdateDate>
|
<UpdateDate>{{ policy.update_datetime }}</UpdateDate>
|
||||||
</Policy>
|
</Policy>
|
||||||
</CreatePolicyResult>
|
</CreatePolicyResult>
|
||||||
<ResponseMetadata>
|
<ResponseMetadata>
|
||||||
@ -719,8 +764,8 @@ GET_POLICY_TEMPLATE = """<GetPolicyResponse>
|
|||||||
<Path>{{ policy.path }}</Path>
|
<Path>{{ policy.path }}</Path>
|
||||||
<Arn>{{ policy.arn }}</Arn>
|
<Arn>{{ policy.arn }}</Arn>
|
||||||
<AttachmentCount>{{ policy.attachment_count }}</AttachmentCount>
|
<AttachmentCount>{{ policy.attachment_count }}</AttachmentCount>
|
||||||
<CreateDate>{{ policy.create_datetime.isoformat() }}</CreateDate>
|
<CreateDate>{{ policy.create_datetime }}</CreateDate>
|
||||||
<UpdateDate>{{ policy.update_datetime.isoformat() }}</UpdateDate>
|
<UpdateDate>{{ policy.update_datetime }}</UpdateDate>
|
||||||
</Policy>
|
</Policy>
|
||||||
</GetPolicyResult>
|
</GetPolicyResult>
|
||||||
<ResponseMetadata>
|
<ResponseMetadata>
|
||||||
@ -898,6 +943,32 @@ GET_ROLE_POLICY_TEMPLATE = """<GetRolePolicyResponse xmlns="https://iam.amazonaw
|
|||||||
</ResponseMetadata>
|
</ResponseMetadata>
|
||||||
</GetRolePolicyResponse>"""
|
</GetRolePolicyResponse>"""
|
||||||
|
|
||||||
|
UPDATE_ROLE_DESCRIPTION_TEMPLATE = """<UpdateRoleDescriptionResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
|
||||||
|
<UpdateRoleDescriptionResult>
|
||||||
|
<Role>
|
||||||
|
<Path>{{ role.path }}</Path>
|
||||||
|
<Arn>{{ role.arn }}</Arn>
|
||||||
|
<RoleName>{{ role.name }}</RoleName>
|
||||||
|
<AssumeRolePolicyDocument>{{ role.assume_role_policy_document }}</AssumeRolePolicyDocument>
|
||||||
|
<CreateDate>{{ role.create_date }}</CreateDate>
|
||||||
|
<RoleId>{{ role.id }}</RoleId>
|
||||||
|
{% if role.tags %}
|
||||||
|
<Tags>
|
||||||
|
{% for tag in role.get_tags() %}
|
||||||
|
<member>
|
||||||
|
<Key>{{ tag['Key'] }}</Key>
|
||||||
|
<Value>{{ tag['Value'] }}</Value>
|
||||||
|
</member>
|
||||||
|
{% endfor %}
|
||||||
|
</Tags>
|
||||||
|
{% endif %}
|
||||||
|
</Role>
|
||||||
|
</UpdateRoleDescriptionResult>
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>df37e965-9967-11e1-a4c3-270EXAMPLE04</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</UpdateRoleDescriptionResponse>"""
|
||||||
|
|
||||||
GET_ROLE_TEMPLATE = """<GetRoleResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
|
GET_ROLE_TEMPLATE = """<GetRoleResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
|
||||||
<GetRoleResult>
|
<GetRoleResult>
|
||||||
<Role>
|
<Role>
|
||||||
|
@ -72,19 +72,6 @@ from datetime import datetime
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from errno import EAGAIN
|
from errno import EAGAIN
|
||||||
|
|
||||||
import logging
|
|
||||||
from inspect import currentframe
|
|
||||||
import inspect
|
|
||||||
|
|
||||||
logging.basicConfig(filename='/tmp/models.log',level=logging.DEBUG)
|
|
||||||
|
|
||||||
DEBUG=0
|
|
||||||
|
|
||||||
def get_linenumber():
|
|
||||||
cf = currentframe()
|
|
||||||
return " - "+str(cf.f_back.f_lineno)
|
|
||||||
|
|
||||||
|
|
||||||
# Some versions of python internally shadowed the
|
# Some versions of python internally shadowed the
|
||||||
# SocketType variable incorrectly https://bugs.python.org/issue20386
|
# SocketType variable incorrectly https://bugs.python.org/issue20386
|
||||||
BAD_SOCKET_SHADOW = socket.socket != socket.SocketType
|
BAD_SOCKET_SHADOW = socket.socket != socket.SocketType
|
||||||
@ -168,34 +155,15 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, headers, body=''):
|
def __init__(self, headers, body=''):
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('__init__ - '
|
|
||||||
' -caller: ' + str(
|
|
||||||
inspect.stack()[1][3]) + "-" + get_linenumber())
|
|
||||||
logging.debug('headers: '+str(headers))
|
|
||||||
|
|
||||||
# first of all, lets make sure that if headers or body are
|
# first of all, lets make sure that if headers or body are
|
||||||
# unicode strings, it must be converted into a utf-8 encoded
|
# unicode strings, it must be converted into a utf-8 encoded
|
||||||
# byte string
|
# byte string
|
||||||
self.raw_headers = utf8(headers.strip())
|
self.raw_headers = utf8(headers.strip())
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('raw_headers: '+str(self.raw_headers))
|
|
||||||
|
|
||||||
self.body = utf8(body)
|
self.body = utf8(body)
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('body: '+str(self.body))
|
|
||||||
|
|
||||||
# Now let's concatenate the headers with the body, and create
|
# Now let's concatenate the headers with the body, and create
|
||||||
# `rfile` based on it
|
# `rfile` based on it
|
||||||
self.rfile = StringIO(b'\r\n\r\n'.join([self.raw_headers, self.body]))
|
self.rfile = StringIO(b'\r\n\r\n'.join([self.raw_headers, self.body]))
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('rfile: '+str(self.rfile))
|
|
||||||
|
|
||||||
|
|
||||||
self.wfile = StringIO() # Creating `wfile` as an empty
|
self.wfile = StringIO() # Creating `wfile` as an empty
|
||||||
# StringIO, just to avoid any real
|
# StringIO, just to avoid any real
|
||||||
# I/O calls
|
# I/O calls
|
||||||
@ -203,10 +171,6 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
|||||||
# parsing the request line preemptively
|
# parsing the request line preemptively
|
||||||
self.raw_requestline = self.rfile.readline()
|
self.raw_requestline = self.rfile.readline()
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('raw_requestline: '+str(self.raw_requestline))
|
|
||||||
|
|
||||||
|
|
||||||
# initiating the error attributes with None
|
# initiating the error attributes with None
|
||||||
self.error_code = None
|
self.error_code = None
|
||||||
self.error_message = None
|
self.error_message = None
|
||||||
@ -218,9 +182,6 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
|||||||
# making the HTTP method string available as the command
|
# making the HTTP method string available as the command
|
||||||
self.method = self.command
|
self.method = self.command
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('method: '+str(self.method))
|
|
||||||
|
|
||||||
# Now 2 convenient attributes for the HTTPretty API:
|
# Now 2 convenient attributes for the HTTPretty API:
|
||||||
|
|
||||||
# `querystring` holds a dictionary with the parsed query string
|
# `querystring` holds a dictionary with the parsed query string
|
||||||
@ -246,23 +207,8 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def parse_querystring(self, qs):
|
def parse_querystring(self, qs):
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('parse_querystring - '
|
|
||||||
' -caller: ' + str(
|
|
||||||
inspect.stack()[1][3]) + "-" + get_linenumber())
|
|
||||||
logging.debug('qs: '+str(qs))
|
|
||||||
|
|
||||||
expanded = unquote_utf8(qs)
|
expanded = unquote_utf8(qs)
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('expanded: '+str(expanded))
|
|
||||||
|
|
||||||
parsed = parse_qs(expanded)
|
parsed = parse_qs(expanded)
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('parsed: '+str(parsed))
|
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
for k in parsed:
|
for k in parsed:
|
||||||
result[k] = list(map(decode_utf8, parsed[k]))
|
result[k] = list(map(decode_utf8, parsed[k]))
|
||||||
@ -272,12 +218,6 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
|||||||
def parse_request_body(self, body):
|
def parse_request_body(self, body):
|
||||||
""" Attempt to parse the post based on the content-type passed. Return the regular body if not """
|
""" Attempt to parse the post based on the content-type passed. Return the regular body if not """
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
logging.debug('parse_request_body - '
|
|
||||||
' -caller: ' + str(
|
|
||||||
inspect.stack()[1][3]) + "-" + get_linenumber())
|
|
||||||
logging.debug('body: '+str(body))
|
|
||||||
|
|
||||||
PARSING_FUNCTIONS = {
|
PARSING_FUNCTIONS = {
|
||||||
'application/json': json.loads,
|
'application/json': json.loads,
|
||||||
'text/json': json.loads,
|
'text/json': json.loads,
|
||||||
|
@ -133,7 +133,6 @@ def parse_requestline(s):
|
|||||||
...
|
...
|
||||||
ValueError: Not a Request-Line
|
ValueError: Not a Request-Line
|
||||||
"""
|
"""
|
||||||
|
|
||||||
methods = '|'.join(HttpBaseClass.METHODS)
|
methods = '|'.join(HttpBaseClass.METHODS)
|
||||||
m = re.match(r'(' + methods + ')\s+(.*)\s+HTTP/(1.[0|1])', s, re.I)
|
m = re.match(r'(' + methods + ')\s+(.*)\s+HTTP/(1.[0|1])', s, re.I)
|
||||||
if m:
|
if m:
|
||||||
@ -146,7 +145,6 @@ def last_requestline(sent_data):
|
|||||||
"""
|
"""
|
||||||
Find the last line in sent_data that can be parsed with parse_requestline
|
Find the last line in sent_data that can be parsed with parse_requestline
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for line in reversed(sent_data):
|
for line in reversed(sent_data):
|
||||||
try:
|
try:
|
||||||
parse_requestline(decode_utf8(line))
|
parse_requestline(decode_utf8(line))
|
||||||
|
@ -821,7 +821,6 @@ def get_function_policy():
|
|||||||
assert res['Statement'][0]['Action'] == 'lambda:InvokeFunction'
|
assert res['Statement'][0]['Action'] == 'lambda:InvokeFunction'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@mock_lambda
|
@mock_lambda
|
||||||
@mock_s3
|
@mock_s3
|
||||||
def test_list_versions_by_function():
|
def test_list_versions_by_function():
|
||||||
@ -854,7 +853,6 @@ def test_list_versions_by_function():
|
|||||||
assert versions['Versions'][0]['FunctionArn'] == 'arn:aws:lambda:us-west-2:123456789012:function:testFunction:$LATEST'
|
assert versions['Versions'][0]['FunctionArn'] == 'arn:aws:lambda:us-west-2:123456789012:function:testFunction:$LATEST'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@mock_lambda
|
@mock_lambda
|
||||||
@mock_s3
|
@mock_s3
|
||||||
def test_create_function_with_already_exists():
|
def test_create_function_with_already_exists():
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import os, re
|
import os, re
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import boto.kms
|
import boto.kms
|
||||||
from boto.exception import JSONResponseError
|
from boto.exception import JSONResponseError
|
||||||
|
Loading…
Reference in New Issue
Block a user