Repository navigation
fix: use SW360KeycloakClient to renew Keycloak tokens automatically - #248
Merged
Merged
Conversation
added 2 commits
November 11, 2026 17:11
Every bom and project command repeated the same block to read client_id and client_secret from the command line or the environment, create a Keycloak token and log in. Move it to the new ScriptBase.login_with_args() and leave ScriptBase.login() unchanged, so the static token path is unaffected. Two inconsistencies disappear with the deduplication: "project createbom" only honoured the command line options and ignored the environment variables SW360Client_id and SW360Client_secret, and "bom findsources" never checked the result of login(). Signed-off-by: Berke Yoncaci <berke.yoncaci@siemens.com>
Commands which run longer than the Keycloak token lifetime failed once the initial token expired. Use SW360KeycloakClient from sw360 1.13.0, which takes the client credentials instead of a token and renews the token shortly before it expires, so that every request carries a valid token. The component cache refresh created a second client from the token string. It now reuses the authenticated client, as this is the operation which runs long enough for the token to expire. An invalid client_id or client_secret reported an unhandled SW360Error before and is now reported as an authorization error. Fixes sw360#241 Signed-off-by: Berke Yoncaci <berke.yoncaci@siemens.com>
Collaborator
|
Thanks, @berke581, for this PR and the other PR for sw360python. |
Collaborator
|
Sorry for not answering earlier! Also big thanks from my side, great rework! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #241
capycli fetched one Keycloak token at startup, so long running commands failed once it expired. This switches to
SW360KeycloakClient(sw360 >= 1.13.0), which renews the token itself.ScriptBase.login_with_args(). No behaviour change.SW360KeycloakClientthere, and reuse that client for the component cache refresh.Login with a token (
-t/SW360ProductionToken) is unchanged.Side effects:
project createbomnow reads the client id/secret from the environment and only prints token details with--verbose;bom findsourceschecks the login result; invalid credentials give a clean auth error instead of a traceback.Testing: new unit tests for the login paths.
SW360KeycloakClientwas also verified against a real SW360/Keycloak with forced renewal in another tool; I couldn't run capycli itself end to end.Based on the approach in #242 by @dhruvv16-hash. The 401 retry from #242 is dropped, since sw360python now handles renewal.