Skip to content

Commit

Permalink
Allow specifying session token (#1283)
Browse files Browse the repository at this point in the history
* Allow specifying session token

* add docs

* add comment
  • Loading branch information
flying-sheep committed Jan 5, 2021
1 parent 3d41ab1 commit 43190b2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions kombu/transport/SQS.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
pair in order to manage all SQS queues (e.g. listing queues, creating
queues, polling queues, deleting messages).
If it is preferable for your environment to use a single AWS credential, you
can use the 'predefined_queues' setting inside the 'transport_options' map.
If it is preferable for your environment to use multiple AWS credentials, you
can use the 'predefined_queues' setting inside the 'transport_options' map.
This setting allows you to specify the SQS queue URL and AWS credentials for
each of your queues. For example, if you have two queues which both already
exist in AWS) you can tell this transport about them as follows:
Expand All @@ -65,6 +65,14 @@
}
}
If you authenticate using Okta_ (e.g. calling |gac|_), you can also specify
a 'session_token' to connect to a queue. Note that those tokens have a
limited lifetime and are therefore only suited for short-lived tests.
.. _Okta: https://www.okta.com/
.. _gac: https://github.com/Nike-Inc/gimme-aws-creds#readme
.. |gac| replace:: ``gimme-aws-creds``
Client config
-------------
Expand Down Expand Up @@ -538,11 +546,12 @@ def close(self):
# if "can't set attribute" not in str(exc):
# raise

def new_sqs_client(self, region, access_key_id, secret_access_key):
def new_sqs_client(self, region, access_key_id, secret_access_key, session_token=None):
session = boto3.session.Session(
region_name=region,
aws_access_key_id=access_key_id,
aws_secret_access_key=secret_access_key,
aws_session_token=session_token,
)
is_secure = self.is_secure if self.is_secure is not None else True
client_kwargs = {
Expand All @@ -568,6 +577,8 @@ def sqs(self, queue=None):
region=q.get('region', self.region),
access_key_id=q.get('access_key_id', self.conninfo.userid),
secret_access_key=q.get('secret_access_key', self.conninfo.password), # noqa: E501
# With session_token, this client’s access will expire, but it’s useful for testing
session_token=q.get('session_token', None),
)
return c

Expand Down

0 comments on commit 43190b2

Please sign in to comment.