It may be worth taking this opportunity to switch up the composer auth method if possible to either using the composer cli e.g. php composer.phar config http-basic.repo.magento.com username password or the COMPOSER_AUTH env var - https://getcomposer.org/doc/03-cli.md#composer-auth
That way we may be able to make it a bit more generic so it can just be an array of credential objects and iterate over them (not sure if bitbucket supports object arrays though it does support arrays: https://support.atlassian.com/bitbucket-cloud/docs/advanced-techniques-for-writing-pipes/ )