Skip to content

Extract shared OIDC JSON helpers and ForDevOps wrapper#110

Open
kbukum1 wants to merge 1 commit intomainfrom
extract-oidc-json-helpers
Open

Extract shared OIDC JSON helpers and ForDevOps wrapper#110
kbukum1 wants to merge 1 commit intomainfrom
extract-oidc-json-helpers

Conversation

@kbukum1
Copy link
Copy Markdown
Contributor

@kbukum1 kbukum1 commented Apr 24, 2026

Extract shared OIDC JSON helpers and ForDevOps wrapper

Follow-up from #108 — eliminates duplicated HTTP boilerplate and token exchange patterns across OIDC providers.

Changes

buildJSONRequest / executeRequest helpers:

  • Standardize the repeated marshal → create request → set headers → execute → read body pattern
  • buildJSONRequest sets only Content-Type and User-Agent (minimal); callers add provider-specific headers (e.g., Accept, Authorization) between build and execute
  • Refactored: JFrog, Cloudsmith, GCP STS, GCP IAM
  • Not refactored: Azure (form-encoded), AWS (form-encoded + SigV4) — these don't fit the JSON pattern

getAccessTokenForDevOps wrapper:

  • Consolidates the identical OIDC-configured check → GitHub token fetch → provider exchange → error wrapping flow
  • All 5 Get*AccessTokenForDevOps functions now delegate to this shared helper
  • Each caller passes a getGitHubToken function (Azure uses fixed-audience GetTokenForAzureADExchange, others use GetToken(ctx, audience)) and a exchangeToken function

Tests added

  • TestBuildJSONRequest — headers, body, custom header addition, invalid URL
  • TestExecuteRequest — success, non-200 status, connection failure
  • TestGetAccessTokenForDevOps — OIDC not configured, token fetch failure, exchange failure with provider name, success with token passthrough

All existing tests continue to pass unchanged.

Copilot AI review requested due to automatic review settings April 24, 2026 23:10
@kbukum1 kbukum1 requested a review from a team as a code owner April 24, 2026 23:10
@kbukum1 kbukum1 marked this pull request as draft April 24, 2026 23:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the OIDC providers to remove duplicated JSON request boilerplate and consolidates the common “ForDevOps” token-fetch/exchange flow into shared helpers.

Changes:

  • Added buildJSONRequest and executeRequest helpers and refactored JFrog, Cloudsmith, and GCP flows to use them.
  • Introduced getAccessTokenForDevOps wrapper and updated the provider-specific Get*AccessTokenForDevOps functions to delegate to it.
  • Added unit tests covering the new helpers and wrapper behavior.
Show a summary per file
File Description
internal/oidc/actions_oidc.go Adds shared JSON request/execution helpers and a shared ForDevOps wrapper; refactors multiple providers to use the helpers.
internal/oidc/actions_oidc_test.go Adds focused tests for the new helper functions and shared wrapper logic.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread internal/oidc/actions_oidc_test.go Outdated
Comment thread internal/oidc/actions_oidc.go Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new

@kbukum1 kbukum1 marked this pull request as ready for review April 27, 2026 17:08
@kbukum1 kbukum1 force-pushed the extract-oidc-json-helpers branch 2 times, most recently from 87145b6 to 10ce848 Compare April 27, 2026 23:25
Extract buildJSONRequest/executeRequest helpers to eliminate repeated
HTTP boilerplate across OIDC token exchange functions. Refactor JFrog,
Cloudsmith, and GCP providers to use the new helpers.

Extract getAccessTokenForDevOps to consolidate the identical OIDC
configuration check, GitHub token fetch, and provider token exchange
pattern shared by all 5 ForDevOps wrappers.

Azure and AWS are intentionally not refactored for JSON helpers:
Azure uses form-encoded requests, AWS uses form-encoded + SigV4 signing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kbukum1 kbukum1 force-pushed the extract-oidc-json-helpers branch from 10ce848 to b4cbb48 Compare April 28, 2026 19:52
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.

2 participants