Skip to content
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

Handle missing access token don't clear access key #258

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/integ-test-inject-develocity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ jobs:
id: gradle
working-directory: .github/workflow-samples/no-ge
run: gradle help
- name: Check access key is blank (DEVELOCITY_ACCESS_KEY)
run: "[ \"${DEVELOCITY_ACCESS_KEY}\" == \"\" ] || (echo 'DEVELOCITY_ACCESS_KEY has leaked!'; exit 1)"
- name: Check access key is not blank (DEVELOCITY_ACCESS_KEY)
run: "[ \"${DEVELOCITY_ACCESS_KEY}\" != \"\" ] || (echo 'using DEVELOCITY_ACCESS_KEY!'; exit 1)"
- name: Check access key is not blank (GRADLE_ENTERPRISE_ACCESS_KEY)
run: "[ \"${GRADLE_ENTERPRISE_ACCESS_KEY}\" != \"\" ] || (echo 'GRADLE_ENTERPRISE_ACCESS_KEY is still supported in v3!'; exit 1)"

Expand Down
11 changes: 6 additions & 5 deletions sources/src/develocity/short-lived-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ export async function setupToken(
core.setSecret(token)
exportAccessKeyEnvVars(token)
} else {
// In case of not being able to generate a token we set the env variable to empty to avoid leaks
clearAccessKeyEnvVarsWithDeprecationWarning()
handleMissingAccessTokenWithDeprecationWarning()
}
} catch (e) {
clearAccessKeyEnvVarsWithDeprecationWarning()
handleMissingAccessTokenWithDeprecationWarning()
core.warning(`Failed to fetch short-lived token, reason: ${e}`)
}
}
Expand All @@ -35,12 +34,14 @@ function exportAccessKeyEnvVars(value: string): void {
)
}

function clearAccessKeyEnvVarsWithDeprecationWarning(): void {
function handleMissingAccessTokenWithDeprecationWarning(): void {
if (process.env[BuildScanConfig.GradleEnterpriseAccessKeyEnvVar]) {
// We do not clear the GRADLE_ENTERPRISE_ACCESS_KEY env var in v3, to let the users upgrade to DV 2024.1
recordDeprecation(`The ${BuildScanConfig.GradleEnterpriseAccessKeyEnvVar} env var is deprecated`)
}
core.exportVariable(BuildScanConfig.DevelocityAccessKeyEnvVar, '')
if (process.env[BuildScanConfig.DevelocityAccessKeyEnvVar]) {
core.warning(`Failed to fetch short-lived token, using Develocity Access key`)
}
}

export async function getToken(
Expand Down
Loading