-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adjust admin-login module to handle replica #6
Open
minaslater
wants to merge
7
commits into
main
Choose a base branch
from
ms-update-with-replica
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
77f560c
Adjust admin-login module to handle replica
minaslater ceaf276
use can to eval replica to bool
minaslater 3692ea8
Pass in replica hostname
minaslater 44d9ce6
Update replica url in RDs secret rotation script
OlamideOl1 78b9e06
Pass REPLICA_HOST address in as env var
minaslater 7ffe6c3
fixes indentation
minaslater 2729d2f
Update lambda_function.py
OlamideOl1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
ALTERNATE_USERNAME = os.environ['ALTERNATE_USERNAME'] | ||
PRIMARY_USERNAME = os.environ['PRIMARY_USERNAME'] | ||
REPLICA_HOST = os.environ['REPLICA_HOST'] | ||
|
||
|
||
def lambda_handler(event, context): | ||
|
@@ -31,7 +32,7 @@ def lambda_handler(event, context): | |
'username': <required: username>, | ||
'password': <required: password>, | ||
'dbname': <optional: database name, default to 'postgres'>, | ||
'port': <optional: if not specified, default port 5432 will be used> | ||
'port': <optional: if not specified, default port 5432 will be used>, | ||
} | ||
|
||
Args: | ||
|
@@ -126,7 +127,11 @@ def create_secret(service_client, arn, token): | |
current_dict['password'] = passwd['RandomPassword'] | ||
|
||
# Add DATABASE_URL to secret | ||
current_dict['DATABASE_URL'] = dict_to_url(current_dict) | ||
current_dict['DATABASE_URL'] = dict_to_url(current_dict, False) | ||
|
||
if REPLICA_HOST: | ||
# Add DATABASE_REPLICA_URL to secret | ||
current_dict['DATABASE_REPLICA_URL'] = dict_to_url(current_dict, True) | ||
|
||
# Put the secret | ||
service_client.put_secret_value(SecretId=arn, ClientRequestToken=token, SecretString=json.dumps(current_dict), VersionStages=['AWSPENDING']) | ||
|
@@ -278,7 +283,7 @@ def finish_secret(service_client, arn, token): | |
service_client.update_secret_version_stage(SecretId=arn, VersionStage="AWSCURRENT", MoveToVersionId=token, RemoveFromVersionId=current_version) | ||
logger.info("finishSecret: Successfully set AWSCURRENT stage to version %s for secret %s." % (token, arn)) | ||
|
||
def dict_to_url(secret): | ||
def dict_to_url(secret, replica): | ||
"""Reformats connection details as a URL string | ||
|
||
Generate a Heroku-style DATABASE_URL with connection details | ||
|
@@ -289,9 +294,13 @@ def dict_to_url(secret): | |
Returns: | ||
url: DATABASE_URL-style string | ||
""" | ||
if replica: | ||
host = secret['host'] | ||
else: | ||
host = REPLICA_HOST | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
return "postgres://%s:%s@%s:%s/%s" % (secret['username'], | ||
secret['password'], secret['host'], secret['port'], | ||
secret['password'], host, secret['port'], | ||
secret['dbname']) | ||
|
||
def get_connection(secret_dict): | ||
|
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed so that we're passing the replica DB host address in only one way; as an environment variable rather than also as part of the secrets.