Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

started working on using default config for a lambda, as returned by … #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 53 additions & 15 deletions lambda_uploader/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@
REQUIRED_PARAMS = {u'name': basestring, u'description': basestring,
u'region': basestring, u'handler': basestring,
u'role': basestring, u'timeout': int, u'memory': int}
REQUIRED_PARAMSaws = {u'FunctionName': basestring, u'Description': basestring,
u'FunctionArn': basestring, u'Handler': basestring,
u'Role': basestring, u'Timeout': int, u'MemorySize': int}

REQUIRED_VPC_PARAMS = {u'subnets': list, u'security_groups': list}
REQUIRED_VPC_PARAMSaws = {u'SubnetIds': list, u'SecurityGroupIds': list}

DEFAULT_PARAMS = {u'requirements': [], u'publish': False,
u'alias': None, u'alias_description': None,
u'ignore': [], u'extra_files': [], u'vpc': None,
u's3_bucket': None, u's3_key': None}

DEFAULT_PARAMSaws = {u'requirements': [], u'publish': False,
u'alias': None, u'alias_description': None,
u'ignore': [], u'extra_files': [], u'vpc': None,
u's3_bucket': None, u's3_key': None}


class Config(object):
def __init__(self, pth, config_file=None, role=None):
Expand All @@ -40,11 +50,19 @@ def __init__(self, pth, config_file=None, role=None):
if role is not None:
self._config['role'] = role
self._set_defaults()
if self._config['vpc']:
self._validate_vpc()

for param, clss in REQUIRED_PARAMS.items():
self._validate(param, cls=clss)
if self._config['FunctionArn']:
REQUIRED_PARAMS=REQUIRED_PARAMSaws
REQUIRED_VPC_PARAMS=REQUIRED_VPC_PARAMSaws
DEFAULT_PARAMS=DEFAULT_PARAMSaws
if self._config['VpcConfig']:
self._validate_vpc(1)
for param, clss in REQUIRED_PARAMSaws.items():
self._validate(param, cls=clss)
else:
if self._config['vpc']:
self._validate_vpc()
for param, clss in REQUIRED_PARAMS.items():
self._validate(param, cls=clss)

'''
Return raw config
Expand All @@ -65,7 +83,10 @@ def alias_description(self):
if self._config['alias_description'] is None:
return self._config['description']
else:
return self._config['alias_description']
if self._config['Description'] != None:
return self._config['Description']
else:
return self._config['alias_description']

'''
Public method to set the S3 bucket and keyname
Expand Down Expand Up @@ -93,25 +114,42 @@ def _set_defaults(self):

'''Validate the configuration file'''
def _validate(self, key, cls=None):
if self._config['FunctionArn']:
REQUIRED_PARAMS=REQUIRED_PARAMSaws
REQUIRED_VPC_PARAMS=REQUIRED_VPC_PARAMSaws
DEFAULT_PARAMS=DEFAULT_PARAMSaws
if key not in self._config:
raise ValueError("Config %s must have %s set"
% (self._path, key))

return self._compare(key, cls, self._config[key])

'''Validate the VPC configuration'''
def _validate_vpc(self):
for param, clss in REQUIRED_VPC_PARAMS.items():
self._compare(param, clss, self._config['vpc'].get(param))
def _validate_vpc(self,awsversion=None):
if awsversion:
for param, clss in REQUIRED_VPC_PARAMSaws.items():
self._compare(param, clss, self._config['VpcConfig'].get(param))

if len(self._config['VpcConfig'].get(param)) == 0:
raise TypeError("VPC Config '%s' should have at least"
" one item in its array!" % param)
for value in self._config['VpcConfig'].get(param):
if not isinstance(value, basestring):
raise TypeError("VPC Config arrays can only contain"
" strings. '%s' contains something else"
% param)
else:
for param, clss in REQUIRED_VPC_PARAMS.items():
self._compare(param, clss, self._config['vpc'].get(param))

if len(self._config['vpc'].get(param)) == 0:
raise TypeError("VPC Config '%s' should have at least"
" one item in its array!" % param)
raise TypeError("VPC Config '%s' should have at least"
" one item in its array!" % param)
for value in self._config['vpc'].get(param):
if not isinstance(value, basestring):
raise TypeError("VPC Config arrays can only contain"
" strings. '%s' contains something else"
% param)
if not isinstance(value, basestring):
raise TypeError("VPC Config arrays can only contain"
" strings. '%s' contains something else"
% param)

'''Compare if a string is a certain type'''
def _compare(self, key, cls, value):
Expand Down