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.versions = [PolicyVersion(self.arn, document, True)]
|
||||
|
||||
self.create_datetime = datetime.now(pytz.utc)
|
||||
self.update_datetime = datetime.now(pytz.utc)
|
||||
self.create_datetime = datetime.strftime(datetime.utcnow(), "%Y-%m-%dT%H:%M:%SZ")
|
||||
self.update_datetime = datetime.strftime(datetime.utcnow(), "%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
|
||||
class SAMLProvider(BaseModel):
|
||||
@ -76,7 +76,7 @@ class PolicyVersion(object):
|
||||
self.is_default = is_default
|
||||
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):
|
||||
@ -132,8 +132,9 @@ class Role(BaseModel):
|
||||
self.path = path or '/'
|
||||
self.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.description = ""
|
||||
|
||||
@classmethod
|
||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||
@ -473,6 +474,10 @@ class IAMBackend(BaseBackend):
|
||||
policy = arns[policy_arn]
|
||||
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):
|
||||
arns = dict((p.arn, p) for p in self.managed_policies.values())
|
||||
try:
|
||||
|
@ -107,6 +107,10 @@ class IamResponse(BaseResponse):
|
||||
template = self.response_template(LIST_POLICIES_TEMPLATE)
|
||||
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):
|
||||
role_name = self._get_param('RoleName')
|
||||
path = self._get_param('Path')
|
||||
@ -169,6 +173,20 @@ class IamResponse(BaseResponse):
|
||||
template = self.response_template(GENERIC_EMPTY_TEMPLATE)
|
||||
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):
|
||||
policy_arn = self._get_param('PolicyArn')
|
||||
policy_document = self._get_param('PolicyDocument')
|
||||
@ -654,6 +672,33 @@ class IamResponse(BaseResponse):
|
||||
template = self.response_template(UNTAG_ROLE_TEMPLATE)
|
||||
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>
|
||||
<ResponseMetadata>
|
||||
@ -696,12 +741,12 @@ CREATE_POLICY_TEMPLATE = """<CreatePolicyResponse>
|
||||
<Policy>
|
||||
<Arn>{{ policy.arn }}</Arn>
|
||||
<AttachmentCount>{{ policy.attachment_count }}</AttachmentCount>
|
||||
<CreateDate>{{ policy.create_datetime.isoformat() }}</CreateDate>
|
||||
<CreateDate>{{ policy.create_datetime }}</CreateDate>
|
||||
<DefaultVersionId>{{ policy.default_version_id }}</DefaultVersionId>
|
||||
<Path>{{ policy.path }}</Path>
|
||||
<PolicyId>{{ policy.id }}</PolicyId>
|
||||
<PolicyName>{{ policy.name }}</PolicyName>
|
||||
<UpdateDate>{{ policy.update_datetime.isoformat() }}</UpdateDate>
|
||||
<UpdateDate>{{ policy.update_datetime }}</UpdateDate>
|
||||
</Policy>
|
||||
</CreatePolicyResult>
|
||||
<ResponseMetadata>
|
||||
@ -719,8 +764,8 @@ GET_POLICY_TEMPLATE = """<GetPolicyResponse>
|
||||
<Path>{{ policy.path }}</Path>
|
||||
<Arn>{{ policy.arn }}</Arn>
|
||||
<AttachmentCount>{{ policy.attachment_count }}</AttachmentCount>
|
||||
<CreateDate>{{ policy.create_datetime.isoformat() }}</CreateDate>
|
||||
<UpdateDate>{{ policy.update_datetime.isoformat() }}</UpdateDate>
|
||||
<CreateDate>{{ policy.create_datetime }}</CreateDate>
|
||||
<UpdateDate>{{ policy.update_datetime }}</UpdateDate>
|
||||
</Policy>
|
||||
</GetPolicyResult>
|
||||
<ResponseMetadata>
|
||||
@ -898,6 +943,32 @@ GET_ROLE_POLICY_TEMPLATE = """<GetRolePolicyResponse xmlns="https://iam.amazonaw
|
||||
</ResponseMetadata>
|
||||
</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/">
|
||||
<GetRoleResult>
|
||||
<Role>
|
||||
|
@ -72,19 +72,6 @@ from datetime import datetime
|
||||
from datetime import timedelta
|
||||
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
|
||||
# SocketType variable incorrectly https://bugs.python.org/issue20386
|
||||
BAD_SOCKET_SHADOW = socket.socket != socket.SocketType
|
||||
@ -168,34 +155,15 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
||||
"""
|
||||
|
||||
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
|
||||
# unicode strings, it must be converted into a utf-8 encoded
|
||||
# byte string
|
||||
self.raw_headers = utf8(headers.strip())
|
||||
|
||||
if DEBUG:
|
||||
logging.debug('raw_headers: '+str(self.raw_headers))
|
||||
|
||||
self.body = utf8(body)
|
||||
|
||||
if DEBUG:
|
||||
logging.debug('body: '+str(self.body))
|
||||
|
||||
# Now let's concatenate the headers with the body, and create
|
||||
# `rfile` based on it
|
||||
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
|
||||
# StringIO, just to avoid any real
|
||||
# I/O calls
|
||||
@ -203,10 +171,6 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
||||
# parsing the request line preemptively
|
||||
self.raw_requestline = self.rfile.readline()
|
||||
|
||||
if DEBUG:
|
||||
logging.debug('raw_requestline: '+str(self.raw_requestline))
|
||||
|
||||
|
||||
# initiating the error attributes with None
|
||||
self.error_code = None
|
||||
self.error_message = None
|
||||
@ -218,9 +182,6 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
||||
# making the HTTP method string available as the command
|
||||
self.method = self.command
|
||||
|
||||
if DEBUG:
|
||||
logging.debug('method: '+str(self.method))
|
||||
|
||||
# Now 2 convenient attributes for the HTTPretty API:
|
||||
|
||||
# `querystring` holds a dictionary with the parsed query string
|
||||
@ -246,23 +207,8 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
if DEBUG:
|
||||
logging.debug('expanded: '+str(expanded))
|
||||
|
||||
parsed = parse_qs(expanded)
|
||||
|
||||
if DEBUG:
|
||||
logging.debug('parsed: '+str(parsed))
|
||||
|
||||
result = {}
|
||||
for k in parsed:
|
||||
result[k] = list(map(decode_utf8, parsed[k]))
|
||||
@ -272,12 +218,6 @@ class HTTPrettyRequest(BaseHTTPRequestHandler, BaseClass):
|
||||
def parse_request_body(self, body):
|
||||
""" 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 = {
|
||||
'application/json': json.loads,
|
||||
'text/json': json.loads,
|
||||
@ -1173,4 +1113,4 @@ def httprettified(test):
|
||||
|
||||
if isinstance(test, ClassTypes):
|
||||
return decorate_class(test)
|
||||
return decorate_callable(test)
|
||||
return decorate_callable(test)
|
@ -133,7 +133,6 @@ def parse_requestline(s):
|
||||
...
|
||||
ValueError: Not a Request-Line
|
||||
"""
|
||||
|
||||
methods = '|'.join(HttpBaseClass.METHODS)
|
||||
m = re.match(r'(' + methods + ')\s+(.*)\s+HTTP/(1.[0|1])', s, re.I)
|
||||
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
|
||||
"""
|
||||
|
||||
for line in reversed(sent_data):
|
||||
try:
|
||||
parse_requestline(decode_utf8(line))
|
||||
|
@ -821,7 +821,6 @@ def get_function_policy():
|
||||
assert res['Statement'][0]['Action'] == 'lambda:InvokeFunction'
|
||||
|
||||
|
||||
|
||||
@mock_lambda
|
||||
@mock_s3
|
||||
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'
|
||||
|
||||
|
||||
|
||||
@mock_lambda
|
||||
@mock_s3
|
||||
def test_create_function_with_already_exists():
|
||||
|
@ -1,6 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
import os, re
|
||||
|
||||
import boto3
|
||||
import boto.kms
|
||||
from boto.exception import JSONResponseError
|
||||
|
Loading…
Reference in New Issue
Block a user