scopely-devops / skew

Apache License 2.0
242 stars 70 forks source link

Allow aws_creds to be loaded from _config #86

Closed ryandub closed 5 years ago

ryandub commented 8 years ago

The current configuration instantiation for skew makes it a bit challenging to use it programmatically as a library. This change allows someone to load AWS credentials into the skew.config._config like so:

        skew.config._config = {
            'accounts': {
                account: {
                    'credentials': creds
                }
            }
        }

Without this change, you can inject aws_creds into skew.scan() and those kwargs get passed all the way down until you start to iterate resources, at which point things like https://github.com/scopely-devops/skew/blob/develop/skew/resources/aws/__init__.py#L106-L109 attempt to create a new client without the kwargs and things break. :)

Thanks for making this!

kapilt commented 8 years ago

i'm also interested in library usage. but i think its a little cleaner is instead parameterizing use of resources across around a session factory, so the additional client can be created as needed, without having to refetch credential info from a particular entry point.

rsimac commented 6 years ago

Confirming the @ryandub commits working, tested, see example below. Although not ideal (as mentioned by @kapilt, I'd vote for merging this one, to allow for programmatic usage. Maybe not advertise it as official api, to allow changing it later to proper, more elegant way.

Test:

    skew_creds={'aws_access_key_id': 'ZZZZZZZZZZZZZZZZZZ', 'aws_secret_access_key': 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'}

    skew.config._config = {'accounts': {'111111111111111111': {'credentials': skew_creds}}}

    arn = scan('arn:aws:ec2:us-east-2:111111111111111111:vpc/*')
twitu commented 5 years ago

I am interested in using it programmatically specifically in a lambda function. This will make it much easier to read account credentials from environment variables and configure skew accordingly. When will it be merged?

twitu commented 5 years ago

Thank you for adding the functionality. I will be making the same modification in the code to get it working.

When will it be released on PYPI? Keeping the old version as a requirement might create problems when redeploying. On the other hand is there a way to add this override it, without modifying the library code.

avram commented 5 years ago

You can specify the version explicitly from Git: https://stackoverflow.com/a/35998253