Skip to content
Permalink
Browse files

[JENKINS-26099] First draft of ability to pick an ID for credentials.

  • Loading branch information
jglick committed Jan 13, 2015
1 parent 8baab36 commit d993c3879e07809edb0af847076eedcd984d7d7c
Showing with 125 additions and 79 deletions.
  1. +29 −0 src/main/java/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials.java
  2. +1 −2 src/main/java/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl.java
  3. +1 −3 src/main/java/com/cloudbees/plugins/credentials/impl/UsernamePasswordCredentialsImpl.java
  4. 0 ...redentials/impl/{UsernamePasswordCredentialsImpl → BaseStandardCredentials}/help-description.html
  5. 0 .../credentials/impl/{CertificateCredentialsImpl → BaseStandardCredentials}/help-description_ja.html
  6. +5 −0 src/main/resources/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials/help-id.html
  7. +36 −0 ...resources/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials/id-and-description.jelly
  8. +24 −0 ...s/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials/id-and-description_de.properties
  9. +23 −0 ...s/com/cloudbees/plugins/credentials/impl/BaseStandardCredentials/id-and-description_ja.properties
  10. +3 −8 ...ain/resources/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl/credentials.jelly
  11. +0 −1 ...urces/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl/credentials_de.properties
  12. +0 −1 ...urces/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl/credentials_ja.properties
  13. +0 −27 ...resources/com/cloudbees/plugins/credentials/impl/CertificateCredentialsImpl/help-description.html
  14. +3 −8 ...esources/com/cloudbees/plugins/credentials/impl/UsernamePasswordCredentialsImpl/credentials.jelly
  15. +0 −1 .../com/cloudbees/plugins/credentials/impl/UsernamePasswordCredentialsImpl/credentials_de.properties
  16. +0 −1 .../com/cloudbees/plugins/credentials/impl/UsernamePasswordCredentialsImpl/credentials_ja.properties
  17. +0 −27 ...s/com/cloudbees/plugins/credentials/impl/UsernamePasswordCredentialsImpl/help-description_ja.html
@@ -24,12 +24,15 @@
package com.cloudbees.plugins.credentials.impl;

import com.cloudbees.plugins.credentials.BaseCredentials;
import com.cloudbees.plugins.credentials.CredentialsDescriptor;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.common.IdCredentials;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Util;
import hudson.util.FormValidation;
import org.kohsuke.stapler.QueryParameter;

import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
@@ -109,4 +112,30 @@ public final boolean equals(Object o) {
public final int hashCode() {
return IdCredentials.Helpers.hashCode(this);
}

/**
* Descriptor to use for subclasses of {@link BaseStandardCredentials}.
* <p>{@code <st:include page="id-and-description" class="${descriptor.clazz}"/>} in {@code credentials.jelly} to pick up standard controls for {@link #getId} and {@link #getDescription}.
*/
protected static abstract class BaseStandardCredentialsDescriptor extends CredentialsDescriptor {

protected BaseStandardCredentialsDescriptor() {
clazz.asSubclass(BaseStandardCredentials.class);
}

protected BaseStandardCredentialsDescriptor(Class<? extends BaseStandardCredentials> clazz) {
super(clazz);
}

public final FormValidation doCheckId(@QueryParameter String value) {
if (value.isEmpty()) {
return FormValidation.ok();
}
// TODO syntax check
// TODO look for existing credentials with this ID (perhaps limited to the store associated with a User or ItemGroup in @AncestorInPath)
return FormValidation.ok();
}

}

}
@@ -1,6 +1,5 @@
package com.cloudbees.plugins.credentials.impl;

import com.cloudbees.plugins.credentials.CredentialsDescriptor;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.CredentialsSnapshotTaker;
@@ -144,7 +143,7 @@ public KeyStoreSource getKeyStoreSource() {
}

@Extension(ordinal = -1)
public static class DescriptorImpl extends CredentialsDescriptor {
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {

@Override
public String getDisplayName() {
@@ -23,8 +23,6 @@
*/
package com.cloudbees.plugins.credentials.impl;

import com.cloudbees.plugins.credentials.Credentials;
import com.cloudbees.plugins.credentials.CredentialsDescriptor;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import edu.umd.cs.findbugs.annotations.CheckForNull;
@@ -94,7 +92,7 @@ public String getUsername() {
* {@inheritDoc}
*/
@Extension(ordinal = 1)
public static class DescriptorImpl extends CredentialsDescriptor {
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {

/**
* {@inheritDoc}
@@ -0,0 +1,5 @@
<div>
An internal unique ID by which these credentials are identified from jobs and other configuration.
Normally left blank, in which case an ID will be generated, which is fine for jobs created using visual forms.
Useful to specify explicitly when using credentials from scripted configuration.
</div>
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License
Copyright 2015 Jesse Glick.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry title="${%Description}" field="description">
<f:textbox/>
</f:entry>
<f:advanced>
<f:entry field="id" title="${%ID}">
<f:textbox field="id" readonly="${instance != null ? 'readonly' : null}"/>
</f:entry>
</f:advanced>
</j:jelly>
@@ -0,0 +1,24 @@
#
# The MIT License
#
# Copyright (c) 2013 Harald Albers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Description=Beschreibung
@@ -0,0 +1,23 @@
# The MIT License
#
# Copyright (c) 2013 Seiji Sogabe.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

Description=\u8aac\u660e
@@ -23,10 +23,7 @@
~ THE SOFTWARE.
-->

<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:invisibleEntry>
<f:textbox style="display:none" field="id"/>
</f:invisibleEntry>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
<j:if test="${instance==null}">
<j:set var="instance" value="${descriptor.fixInstance(instance)}"/>
</j:if>
@@ -36,7 +33,5 @@
<f:entry title="${%Password}" field="password">
<f:password value="${instance==null || instance.passwordEmpty ? '' : instance.password}"/>
</f:entry>
<f:entry title="${%Description}" field="description">
<f:textbox/>
</f:entry>
</j:jelly>
<st:include page="id-and-description" class="${descriptor.clazz}"/>
</j:jelly>
@@ -22,4 +22,3 @@

Certificate=Zertifikat
Password=Passwort
Description=Beschreibung
@@ -22,4 +22,3 @@

Certificate=\u8a3c\u660e\u66f8
Password=\u30d1\u30b9\u30ef\u30fc\u30c9
Description=\u8aac\u660e

This file was deleted.

@@ -23,17 +23,12 @@
~ THE SOFTWARE.
-->

<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:invisibleEntry>
<f:textbox style="display:none" field="id"/>
</f:invisibleEntry>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
<f:entry title="${%Username}" field="username">
<f:textbox/>
</f:entry>
<f:entry title="${%Password}" field="password">
<f:password/>
</f:entry>
<f:entry title="${%Description}" field="description">
<f:textbox/>
</f:entry>
</j:jelly>
<st:include page="id-and-description" class="${descriptor.clazz}"/>
</j:jelly>
@@ -23,4 +23,3 @@

Username=Benutzername
Password=Passwort
Description=Beschreibung
@@ -22,4 +22,3 @@

Username=\u30e6\u30fc\u30b6\u30fc\u540d
Password=\u30d1\u30b9\u30ef\u30fc\u30c9
Description=\u8aac\u660e

This file was deleted.

0 comments on commit d993c38

Please sign in to comment.
You can’t perform that action at this time.