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

addition of role and region flags #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions actions/lib/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def get_r53zone(self, zone):
def st2_user_data(self):
return self.userdata

def create_boto3_session(self, role=None):
if role is not None:
print "create_boto3_session - role: %s region: %s" % (role, self.credentials['region'])
client = boto3.client('sts', region_name=self.credentials['region'])
creds = client.assume_role(RoleArn=role, RoleSessionName='st2session')

boto3.setup_default_session(aws_access_key_id=creds['Credentials']['AccessKeyId'],
aws_secret_access_key=creds['Credentials']['SecretAccessKey'],
aws_session_token=creds['Credentials']['SessionToken'])

def get_boto3_session(self, resource):
region = self.credentials['region']
del self.credentials['region']
Expand Down
5 changes: 5 additions & 0 deletions actions/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ def run(self, **kwargs):
del kwargs['action']
module_path = kwargs['module_path']
del kwargs['module_path']
if 'region_name' in kwargs.keys() and kwargs['region_name'] is not None:
self.credentials['region'] = kwargs['region_name']
del kwargs['region_name']
self.create_boto3_session(kwargs['assume_role'])
del kwargs['assume_role']
if action == 'run_instances':
kwargs['user_data'] = self.st2_user_data()
if action == 'create_tags':
Expand Down
4 changes: 4 additions & 0 deletions etc/st2packgen/templates/action_template.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ parameters:
default: boto3
immutable: true
type: string
region_name:
type: string
assume_role:
type: string
{%- for parameter in paramsreq %}
{{ parameter.name }}:
type: {{ parameter.type }}
Expand Down