Skip to content

CLOUDP-330236: Adds NewServiceAccountTransport #4075

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

Merged
merged 3 commits into from
Aug 1, 2025

Conversation

cveticm
Copy link
Collaborator

@cveticm cveticm commented Aug 1, 2025

Proposed changes

Adds new transport for Service Accounts.

Unit testing:

Added two new unit tests for transport.go

  • TestNewAccessTokenTransport
  • TestNewServiceAccountTransport

Manual Testing:

I have tested this transport type by implementing the transport into the client creator logic (This implementation will be put for review as a part of CLOUDP-329787) and manually setting up SA credentials in the config. I've also ensured that the transport method continues to work even after the first token generated by this transport type expired to ensure refresh logic is working.

truncated config file:

version = 2

[oauth2]
client_id = 'mdb_sa_id_<...>'
client_secret = 'mdb_sa_sk_<...>'
auth_type = 'service_account'
org_id = '670cd17af33cea212ea1ed61'
project_id = '670e34d35a4f587387db2102'
service = 'cloud'

Cmd calls using Service Accounts profile
image

Jira ticket: CLOUDP-330236

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works
  • I have added any necessary documentation in document requirements section listed in CONTRIBUTING.md (if appropriate)
  • I have addressed the @mongodb/docs-cloud-team comments (if appropriate)
  • I have updated test/README.md (if an e2e test has been added)
  • I have run make fmt and formatted my code

Further comments

@cveticm cveticm requested review from a team as code owners August 1, 2025 14:15
@github-actions github-actions bot added need-doc-review Improvements or additions to documentation, will be reviewed by the docs team atlascli labels Aug 1, 2025
Copy link
Contributor

github-actions bot commented Aug 1, 2025

APIx Bot :bowtie:: a message has been sent to Docs Slack channel 🚀.

@cveticm cveticm changed the base branch from master to SA_refactor_feature_branch August 1, 2025 14:19
@github-actions github-actions bot removed need-doc-review Improvements or additions to documentation, will be reviewed by the docs team atlascli labels Aug 1, 2025

func NewServiceAccountTransport(clientID, clientSecret string, base http.RoundTripper) (http.RoundTripper, error) {
cfg := clientcredentials.NewConfig(clientID, clientSecret)
if config.OpsManagerURL() != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if is "" ?

Copy link
Collaborator Author

@cveticm cveticm Aug 1, 2025

Choose a reason for hiding this comment

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

clientcredentials.NewConfig already sets TokenURL and RevokeURL but points them to https://cloud.mongodb.com.

So this logic is to ensure we point to the correct cloud environment if OpsManagerURL is pointing to dev or qa.

Copy link
Contributor

github-actions bot commented Aug 1, 2025

Coverage Report 📈

Branch Commit Coverage
SA_refactor_feature_branch f9dd12d 26.0%
CLOUDP-330236_SA_transport 58b5eb9 26.0%
Difference 0%

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 57.846% (-0.1%) from 57.953%
when pulling 7cc5cb0 on CLOUDP-330236_SA_transport
into b0af9fc on master.

@cveticm cveticm merged commit 4d80050 into SA_refactor_feature_branch Aug 1, 2025
19 checks passed
@cveticm cveticm deleted the CLOUDP-330236_SA_transport branch August 1, 2025 16:31
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