Skip to content
Permalink
Browse files
[FIXED JENKINS-24631] Expose the credentials details by the XML/JSON API
  • Loading branch information
stephenc committed May 31, 2016
1 parent 56b9751 commit 3d2779ec7e2f84e8aa64546ee8be7065180c7ecb
@@ -48,6 +48,7 @@
import hudson.util.FormValidation;
import hudson.util.HttpResponses;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
@@ -79,6 +80,7 @@
/**
* An action for a {@link CredentialsStore}
*/
@ExportedBean
public abstract class CredentialsStoreAction
implements Action, IconSpec, AccessControlled, ModelObjectWithContextMenu, ModelObjectWithChildren {

@@ -109,7 +111,6 @@
* @return the {@link CredentialsStore}.
*/
@NonNull
@Exported
public abstract CredentialsStore getStore();

/**
@@ -609,7 +610,6 @@ public CredentialsWrapper.DescriptorImpl getCredentialDescriptor() {
*
* @return a map of the wrapped credentials.
*/
@Exported
@NonNull
public Map<String, CredentialsWrapper> getCredentials() {
Map<String, CredentialsWrapper> result = new LinkedHashMap<String, CredentialsWrapper>();
@@ -630,6 +630,18 @@ public Map<String, CredentialsWrapper> getCredentials() {
return result;
}

/**
* Exposes the wrapped credentials for the XML API.
*
* @return the wrapped credentials for the XML API.
* @since 2.0.8
*/
@NonNull
@Exported(name = "credentials", visibility = 1)
public List<CredentialsWrapper> getCredentialsList() {
return new ArrayList<CredentialsWrapper>(getCredentials().values());
}

/**
* Get a credential by id.
*
@@ -874,6 +886,17 @@ public CredentialsWrapper(DomainWrapper domain, Credentials credentials, String
this.id = id;
}

/**
* Return the id for the XML API.
*
* @return the id.
* @since 2.0.8
*/
@Exported
public String getId() {
return id;
}

/**
* Return the URL name.
*
@@ -47,7 +47,9 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import jenkins.model.ModelObjectWithContextMenu;
@@ -57,10 +59,13 @@
import org.jenkins.ui.icon.IconSpec;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

/**
* An {@link Action} that lets you view the available credentials for any {@link ModelObject}.
*/
@ExportedBean
public class ViewCredentialsAction implements Action, IconSpec, AccessControlled, ModelObjectWithContextMenu {

/**
@@ -153,6 +158,23 @@ public List<CredentialsStoreAction> getStoreActions() {
return result;
}

/**
* Exposes the {@link #getLocalStores()} for the XML API.
*
* @return the {@link #getLocalStores()} for the XML API.
* @since 2.0.8
*/
@NonNull
@SuppressWarnings("unused") // Stapler XML/JSON API
@Exported(name = "stores")
public Map<String,CredentialsStoreAction> getStoreActionsMap() {
Map<String,CredentialsStoreAction> result = new TreeMap<String, CredentialsStoreAction>();
for (CredentialsStoreAction a: getStoreActions()) {
result.put(a.getUrlName(), a);
}
return result;
}

/**
* Exposes the {@link #getStoreActions()} by {@link CredentialsStoreAction#getUrlName()} for Stapler.
*

0 comments on commit 3d2779e

Please sign in to comment.