Skip to content

CP-11565 - Update webhook secret to load for new accounts#49

Merged
bernardodsanderson merged 7 commits intomainfrom
CP-11565-2
Feb 17, 2026
Merged

CP-11565 - Update webhook secret to load for new accounts#49
bernardodsanderson merged 7 commits intomainfrom
CP-11565-2

Conversation

@bernardodsanderson
Copy link
Collaborator

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.

@ryanarakawa
Copy link
Collaborator

@bernardodsanderson
I don't know enough about this, is there any risk to have this viewable in a public repo?

@bernardodsanderson
Copy link
Collaborator Author

@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')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add CAREERPLUG_WEBHOOK_URL?


validates :external_account_id, uniqueness: true, allow_nil: true

after_create :create_careerplug_webhook
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

@mikhael-rakauskas mikhael-rakauskas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One q but otherwise looks good!

Comment on lines +131 to +136
# 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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason for removing this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😅

@bernardodsanderson bernardodsanderson merged commit 3570b7c into main Feb 17, 2026
5 checks passed
@bernardodsanderson bernardodsanderson deleted the CP-11565-2 branch February 17, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants