Skip to content

Commit

Permalink
[JENKINS-26099] First draft of ability to pick an ID for credentials.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jan 13, 2015
1 parent 8baab36 commit d993c38
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 79 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -144,7 +143,7 @@ private static char[] toCharArray(Secret password) {
}

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

@Override
public String getDisplayName() {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +92,7 @@ public String getUsername() {
* {@inheritDoc}
*/
@Extension(ordinal = 1)
public static class DescriptorImpl extends CredentialsDescriptor {
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {

/**
* {@inheritDoc}
Expand Down
@@ -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
Expand Up @@ -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>
Expand All @@ -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>
Expand Up @@ -22,4 +22,3 @@

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

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

This file was deleted.

Expand Up @@ -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>
Expand Up @@ -23,4 +23,3 @@

Username=Benutzername
Password=Passwort
Description=Beschreibung
Expand Up @@ -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.