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
Changes from 4 commits
d272a6e
0e4ab09
a5f6ccb
6a1ad95
7dad737
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 |
---|---|---|
@@ -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 | ||
return Domain.global().equals(domain) | ||
? provider.getCredentials(Credentials.class, Jenkins.getInstance(), ACL.SYSTEM) | ||
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. Ahh I think you need to pass 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. If I do that, then this check fails and we don't see the credentials 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. Hmm.. I used this code as a reference for that. |
||
: 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() { | ||
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.
|
||
return store; | ||
} | ||
|
||
@Override | ||
public String getIconFileName() { | ||
return isVisible() | ||
? "/plugin/kubernetes-credentials-provider/images/32x32/kubernetes-store.png" | ||
: null; | ||
} | ||
|
||
@Override | ||
public String getIconClassName() { | ||
return isVisible() | ||
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. what is isVisible? 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. |
||
? "icon-credentials-kubernetes-store" | ||
: null; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Kubernetes"; | ||
} | ||
} | ||
} |
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