Skip to content

Commit 4fdc45c

Browse files
committed
Merge pull request rackerlabs#23 from rackerlabs/feature_role_flag
Added a role flag
2 parents 8de5a97 + 4aecebb commit 4fdc45c

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lambda_uploader/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424

2525

2626
class Config(object):
27-
def __init__(self, pth, config_file=None):
27+
def __init__(self, pth, config_file=None, role=None):
2828
self._path = pth
2929
self._config = None
3030
self._load_config(config_file)
31+
if role is not None:
32+
self._config['role'] = role
3133
self._set_defaults()
3234

3335
for param, clss in REQUIRED_PARAMS.iteritems():

lambda_uploader/shell.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import traceback
2323
import lambda_uploader
2424

25-
from os import getcwd, path
25+
from os import getcwd, path, getenv
2626
from lambda_uploader import package, config, uploader
2727

2828
LOG = logging.getLogger(__name__)
@@ -47,7 +47,7 @@ def _print(txt):
4747
def _execute(args):
4848
pth = path.abspath(args.function_dir)
4949

50-
cfg = config.Config(pth, args.config)
50+
cfg = config.Config(pth, args.config, role=args.role)
5151

5252
_print('Building Package')
5353
pkg = package.build_package(pth, cfg.requirements)
@@ -97,6 +97,10 @@ def main(arv=None):
9797
action='store_const',
9898
help='publish an upload to an immutable version',
9999
const=True)
100+
parser.add_argument('--role', dest='role',
101+
default=getenv('LAMBDA_UPLOADER_ROLE'),
102+
help=('IAM role to assign the lambda function, '
103+
'can be set with $LAMBDA_UPLOADER_ROLE'))
100104
parser.add_argument('--profile', dest='profile',
101105
help='specify AWS cli profile')
102106
alias_help = 'alias for published version (WILL SET THE PUBLISH FLAG)'

test/test_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ def test_load_config():
1717
assert cfg.raw[key] == val
1818

1919

20+
def test_role_override():
21+
role = 'arn:aws:iam::00000000000:role/myfunc_role'
22+
cfg = config.Config(EX_CONFIG, role=role)
23+
24+
assert cfg.role is role
25+
26+
2027
def test_set_publish():
2128
cfg = config.Config(EX_CONFIG)
2229
# Check that we default to false

0 commit comments

Comments
 (0)