Skip to content

Commit

Permalink
[JENKINS-50204] Implemented CredentialsStoreAction
Browse files Browse the repository at this point in the history
This allows inspecting of individual secrets when clicking on them in
the credentials view instead of receiving a big stapler stack trace
  • Loading branch information
agentgonzo committed Apr 12, 2018
1 parent d272a6e commit 0e4ab09
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
Expand Up @@ -211,4 +211,10 @@ IdCredentials convertSecret(Secret s) {
public CredentialsStore getStore(ModelObject object) {
return object == Jenkins.getInstance() ? store : null;
}

@Override
public String getIconClassName() {
return "icon-credentials-kubernetes-store";
}

}
@@ -1,21 +1,27 @@
package com.cloudbees.jenkins.plugins.kubernetes_credentials_provider;

import java.io.IOException;
import java.util.List;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import org.acegisecurity.Authentication;
import org.apache.commons.lang.NotImplementedException;
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.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);
Expand Down Expand Up @@ -55,4 +61,75 @@ public boolean updateCredentials(@NonNull Domain domain, @NonNull Credentials cu
@NonNull Credentials replacement) {
throw new NotImplementedException();
}

@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));
}

/**
* {@inheritDoc}
*/
@NonNull
public CredentialsStore getStore() {
return store;
}

/**
* {@inheritDoc}
*/
@Override
public String getIconFileName() {
return isVisible()
? "/plugin/kubernetes-credentials-provider/images/32x32/kubernetes-store.png"
: null;
}

/**
* {@inheritDoc}
*/
@Override
public String getIconClassName() {
return isVisible()
? "icon-credentials-kubernetes-store"
: null;
}

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return "Kubernetes";
}
}
}
Binary file added src/main/webapp/images/16x16/kubernetes-store.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/webapp/images/24x24/kubernetes-store.png
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.
Binary file added src/main/webapp/images/48x48/kubernetes-store.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0e4ab09

Please sign in to comment.