Navigation Menu

Skip to content

Commit

Permalink
[FIXED JENKINS-24631] Expose the credentials details by the XML/JSON API
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed May 31, 2016
1 parent 56b9751 commit 3d2779e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +80,7 @@
/**
* An action for a {@link CredentialsStore}
*/
@ExportedBean
public abstract class CredentialsStoreAction
implements Action, IconSpec, AccessControlled, ModelObjectWithContextMenu, ModelObjectWithChildren {

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

/**
Expand Down Expand Up @@ -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>();
Expand All @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
Expand Up @@ -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;
Expand All @@ -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 {

/**
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 3d2779e

Please sign in to comment.