Last active
December 10, 2020 17:40
-
-
Save gfabrizio/6cba82e461ca9501b07b59f6fe78dae3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to get all config vars in a Heroku app and transfer to a new AWS Secrets Manager | |
# To get Heroku Auth Token: | |
# $ heroku auth:token | |
# Usage: | |
# python to_secrets.py | |
import boto3 | |
import heroku3 | |
import json | |
heroku_token = input("Enter Heroku Auth Token: ") | |
heroku_conn = heroku3.from_key(heroku_token) | |
heroku_app = input("Enter Heroku App: ") | |
secrets_manager_client = boto3.client("secretsmanager") | |
def get_heroku_app(): | |
return heroku_conn.apps()[heroku_app] | |
def create_new_secret(): | |
secret_name = input("Enter the name of the new secret: ") | |
app = get_heroku_app() | |
config = app.config().__dict__ | |
exported_config = dict() | |
for k,v in config["_ConfigVars__data"].items(): | |
if k.startswith("HEROKU") is False: | |
exported_config[k] = v | |
response = secrets_manager_client.create_secret( | |
Name = secret_name, | |
SecretString = "{}".format(json.dumps(exported_config)) | |
) | |
print(response) | |
create_new_secret() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment