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
[JENKINS-50204] Implemented the Credentials view page #7
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d272a6e
[JENKINS-50204] Implemented the credentials page
agentgonzo 0e4ab09
[JENKINS-50204] Implemented CredentialsStoreAction
agentgonzo a5f6ccb
[JENKINS-50204] Use UnsupportedException instead of NotImplementedExc…
agentgonzo 6a1ad95
[JENKINS-50204] Restricting by domain and read-only permissions
agentgonzo 7dad737
[JENKINS-50204] Ensure user has permission to view credentials.
agentgonzo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
128 changes: 128 additions & 0 deletions
128
...cloudbees/jenkins/plugins/kubernetes_credentials_provider/KubernetesCredentialsStore.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.cloudbees.jenkins.plugins.kubernetes_credentials_provider; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import edu.umd.cs.findbugs.annotations.Nullable; | ||
import org.acegisecurity.Authentication; | ||
import org.jenkins.ui.icon.Icon; | ||
import org.jenkins.ui.icon.IconSet; | ||
import org.jenkins.ui.icon.IconType; | ||
import org.kohsuke.stapler.export.ExportedBean; | ||
import hudson.model.ModelObject; | ||
import hudson.security.ACL; | ||
import hudson.security.Permission; | ||
import jenkins.model.Jenkins; | ||
import com.cloudbees.plugins.credentials.Credentials; | ||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import com.cloudbees.plugins.credentials.CredentialsStore; | ||
import com.cloudbees.plugins.credentials.CredentialsStoreAction; | ||
import com.cloudbees.plugins.credentials.domains.Domain; | ||
|
||
public class KubernetesCredentialsStore extends CredentialsStore { | ||
|
||
private final KubernetesCredentialProvider provider; | ||
private final KubernetesCredentialsStoreAction action = new KubernetesCredentialsStoreAction(this); | ||
|
||
public KubernetesCredentialsStore(KubernetesCredentialProvider provider) { | ||
super(KubernetesCredentialProvider.class); | ||
this.provider = provider; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public ModelObject getContext() { | ||
return Jenkins.getInstance(); | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(@NonNull Authentication authentication, @NonNull Permission permission) { | ||
return CredentialsProvider.VIEW.equals(permission) && | ||
Jenkins.getInstance().getACL().hasPermission(authentication, permission); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<Credentials> getCredentials(@NonNull Domain domain) { | ||
// Only the global domain is supported | ||
if (Domain.global().equals(domain) && Jenkins.getInstance().hasPermission(CredentialsProvider.VIEW)) | ||
return provider.getCredentials(Credentials.class, Jenkins.getInstance(), ACL.SYSTEM); | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public boolean addCredentials(@NonNull Domain domain, @NonNull Credentials credentials) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public boolean removeCredentials(@NonNull Domain domain, @NonNull Credentials credentials) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public boolean updateCredentials(@NonNull Domain domain, @NonNull Credentials current, | ||
@NonNull Credentials replacement) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public CredentialsStoreAction getStoreAction() { | ||
return action; | ||
} | ||
|
||
/** | ||
* Expose the store. | ||
*/ | ||
@ExportedBean | ||
public static class KubernetesCredentialsStoreAction extends CredentialsStoreAction { | ||
|
||
private final KubernetesCredentialsStore store; | ||
|
||
private KubernetesCredentialsStoreAction(KubernetesCredentialsStore store) { | ||
this.store = store; | ||
addIcons(); | ||
} | ||
|
||
private void addIcons() { | ||
IconSet.icons.addIcon(new Icon("icon-credentials-kubernetes-store icon-sm", | ||
"kubernetes-credentials-provider/images/16x16/kubernetes-store.png", | ||
Icon.ICON_SMALL_STYLE, IconType.PLUGIN)); | ||
IconSet.icons.addIcon(new Icon("icon-credentials-kubernetes-store icon-md", | ||
"kubernetes-credentials-provider/images/24x24/kubernetes-store.png", | ||
Icon.ICON_MEDIUM_STYLE, IconType.PLUGIN)); | ||
IconSet.icons.addIcon(new Icon("icon-credentials-kubernetes-store icon-lg", | ||
"kubernetes-credentials-provider/images/32x32/kubernetes-store.png", | ||
Icon.ICON_LARGE_STYLE, IconType.PLUGIN)); | ||
IconSet.icons.addIcon(new Icon("icon-credentials-kubernetes-store icon-xlg", | ||
"kubernetes-credentials-provider/images/48x48/kubernetes-store.png", | ||
Icon.ICON_XLARGE_STYLE, IconType.PLUGIN)); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public CredentialsStore getStore() { | ||
return store; | ||
} | ||
|
||
@Override | ||
public String getIconFileName() { | ||
return isVisible() | ||
? "/plugin/kubernetes-credentials-provider/images/32x32/kubernetes-store.png" | ||
: null; | ||
} | ||
|
||
@Override | ||
public String getIconClassName() { | ||
return isVisible() | ||
? "icon-credentials-kubernetes-store" | ||
: null; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Kubernetes"; | ||
} | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
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.
can you request access so you can release as well. https://github.com/jenkins-infra/repository-permissions-updater/blob/master/permissions/plugin-kubernetes-credentials-provider.yml#L6
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.
Done: jenkins-infra/repository-permissions-updater#666