Making Optional Credentials on Jelly

68 views
Skip to first unread message

Aldrin Leal

unread,
Nov 25, 2015, 6:10:54 AM11/25/15
to jenkin...@googlegroups.com
Silly question: How can I make a Credentials Select optional? I've tried the optional block, to no avail. Right now, I just left this on my Model as a Kludge:

config.jelly:

<f:section title="AWS Credentials and Region">
<f:entry title="${%Credentials}" field="credentialsId">
<c:select expressionAllowed="true"/>
</f:entry>

<f:entry title="AWS Region" field="awsRegion">
<f:textbox default="us-east-1"/>
</f:entry>

<!-- Not yet
<f:validateButton method="validateCredentials" title="Validate Credentials" with="credentialsId,awsRegion"/>
-->
</f:section>
and on the Descriptor:
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item owner) {
if (owner == null || !owner.hasPermission(Item.CONFIGURE)) {
return new ListBoxModel();
}
// when configuring the job, you only want those credentials that are available to ACL.SYSTEM selectable
// as we cannot select from a user's credentials unless they are the only user submitting the build
// (which we cannot assume) thus ACL.SYSTEM is correct here.
List<IdCredentials> credentials = new ArrayList<>();

credentials.add(new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "NONE", "None", "", ""));

credentials.addAll(CredentialsProvider.lookupCredentials(AmazonWebServicesCredentials.class, owner, ACL.SYSTEM, Collections.<DomainRequirement>emptyList()));

return new Model().withAll(credentials);
}
Works, but... Ugly.


Any ideas?

Stephen Connolly

unread,
Nov 25, 2015, 7:07:04 AM11/25/15
to jenkin...@googlegroups.com
What was wrong with using StandardListBoxModel?

e.g.

return new StandardUsernameListBoxModel()
    .withEmptySelection()
    .withAll(CredentialsProvider.lookupCredentials(AmazonWebServicesCredentials.class, owner, ACL.SYSTEM, Collections.<DomainRequirement>emptyList()))

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CALpo8NvOUwhiQbxAQsUBwNfpaSsGmambjgt8MDcvvFPgR7U9%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Aldrin Leal

unread,
Nov 29, 2015, 2:36:23 PM11/29/15
to jenkin...@googlegroups.com
the keyboard and chair interface. Thanks on this one! :)
Reply all
Reply to author
Forward
0 new messages