-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
update updated OpenId access and refresh token in memory config #5888
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
package io.fabric8.kubernetes.client.utils; | ||
|
||
import io.fabric8.kubernetes.api.model.AuthInfo; | ||
import io.fabric8.kubernetes.api.model.AuthProviderConfig; | ||
import io.fabric8.kubernetes.api.model.NamedAuthInfo; | ||
import io.fabric8.kubernetes.api.model.NamedContext; | ||
import io.fabric8.kubernetes.client.Config; | ||
|
@@ -37,10 +38,7 @@ | |
import java.security.cert.CertificateException; | ||
import java.security.spec.InvalidKeySpecException; | ||
import java.time.Instant; | ||
import java.util.Base64; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.*; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Consumer; | ||
|
||
|
@@ -242,6 +240,12 @@ static boolean persistKubeConfigWithUpdatedToken(Config currentConfig, Map<Strin | |
*/ | ||
public static boolean persistKubeConfigWithUpdatedAuthInfo(Config currentConfig, Consumer<AuthInfo> updateAction) | ||
throws IOException { | ||
AuthInfo authInfo = new AuthInfo(); | ||
authInfo.setAuthProvider(new AuthProviderConfig(new HashMap<>(2), currentConfig.getAuthProvider().getName())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This leads to a NPE if the current config has no auth provider set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently working on some refactors and fixes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think the OpenIDConnectionUtils wouldn't be invoked if no auth provider set, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not, but that's unclear in tests. Anyway, this might have some ramifications. I'll work on refactoring some of this stuff and maybe moving it elsewhere to avoid latent bugs. |
||
updateAction.accept(authInfo); | ||
//update new auth info to in-memory config | ||
currentConfig.getAuthProvider().getConfig().putAll(authInfo.getAuthProvider().getConfig()); | ||
|
||
if (currentConfig.getFile() == null) { | ||
return false; | ||
} | ||
|
@@ -259,10 +263,13 @@ public static boolean persistKubeConfigWithUpdatedAuthInfo(Config currentConfig, | |
config.getUsers().add(result); | ||
return result; | ||
}); | ||
//update new auth info to kubeConfig | ||
if (namedAuthInfo.getUser() == null) { | ||
namedAuthInfo.setUser(new AuthInfo()); | ||
namedAuthInfo.setUser(authInfo); | ||
} else { | ||
Optional.ofNullable(authInfo.getToken()).ifPresent(t -> namedAuthInfo.getUser().setToken(t)); | ||
namedAuthInfo.getUser().getAuthProvider().getConfig().putAll(authInfo.getAuthProvider().getConfig()); | ||
} | ||
updateAction.accept(namedAuthInfo.getUser()); | ||
// Persist changes to KUBECONFIG | ||
KubeConfigUtils.persistKubeConfigIntoFile(config, currentConfig.getFile().getAbsolutePath()); | ||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please revert this import related change?