CP-11565 - Update webhook secret to load for new accounts#49
CP-11565 - Update webhook secret to load for new accounts#49bernardodsanderson merged 7 commits intomainfrom
Conversation
|
@bernardodsanderson |
|
@ryanarakawa - The actual secret is in AWS, so I think we're safe. What do you think, @mikhael-rakauskas? |
Load dotenv in development for environment variable access
default Removed default URL for CareerPlug webhook configuration to force explicit setting of required environment variable.
| export SECURED_STORAGE_BUCKET=$(echo "$SECRET_JSON" | jq -r '.secured_storage_bucket') | ||
| export SECURED_STORAGE_REGION=$(echo "$SECRET_JSON" | jq -r '.secured_storage_region') | ||
| export ENCRYPTION_SECRET=$(echo "$SECRET_JSON" | jq -r '.ENCRYPTION_SECRET // empty') | ||
| export CAREERPLUG_WEBHOOK_SECRET=$(echo "$SECRET_JSON" | jq -r '.CAREERPLUG_WEBHOOK_SECRET // empty') |
There was a problem hiding this comment.
add CAREERPLUG_WEBHOOK_URL?
app/models/account.rb
Outdated
|
|
||
| validates :external_account_id, uniqueness: true, allow_nil: true | ||
|
|
||
| after_create :create_careerplug_webhook |
There was a problem hiding this comment.
Should we change this to after_commit? So if there's some error in the account creation we don't have a random webhook hanging around?
after_commit :create_careerplug_webhook, on: :create
Read CAREERPLUG_WEBHOOK_SECRET and CAREERPLUG_WEBHOOK_URL from SECRET_JSON and write them to .env.production and .env.staging across all start scripts; remove old vars with a single regex and only append the new vars when provided
This ensures that CareerPlug webhooks are only created after the account transaction has been successfully committed to the database. This prevents orphaned webhook records if account creation fails or is rolled back. The change improves data consistency and follows Rails best practices for callbacks that create associated records or have external side effects. Includes tests to verify that: - Webhooks are created after successful account creation - Webhooks are not created if account creation fails/rolls back - Webhooks are not created when CAREERPLUG_WEBHOOK_SECRET is blank
mikhael-rakauskas
left a comment
There was a problem hiding this comment.
One q but otherwise looks good!
| # Remove existing ALLOWED_HOSTS line if it exists | ||
| if [ -f "./.env.production" ]; then | ||
| grep -v "^ALLOWED_HOSTS=" ./.env.production > ./.env.production.tmp || true | ||
| mv ./.env.production.tmp ./.env.production | ||
| fi | ||
|
|
There was a problem hiding this comment.
Was there a reason for removing this?
There was a problem hiding this comment.
This is needed since Docker containers in ECS restart frequently, and the .env.production file persists across restarts, causing duplicates without this cleanup logic. At least that's my understanding 😅
This update allows for future added accounts to have the webhook setup automatically. Currently, all accounts have the secret, but for the future ones, we don't want to manually add it.