Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify UI and exposed Data model #36

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package com.cloudbees.jenkins.plugins.sshcredentials.impl;

import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsScope;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand All @@ -33,7 +32,6 @@
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.model.Items;
import hudson.remoting.Channel;
import hudson.util.Secret;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -100,11 +98,21 @@ public class BasicSSHUserPrivateKey extends BaseSSHUser implements SSHUserPrivat
*
* @param scope the credentials scope
* @param username the username.
* @param privateKeySource the private key.
* @param privateKey the private key.
* @param passphrase the password.
* @param description the description.
*/
@DataBoundConstructor
public BasicSSHUserPrivateKey(CredentialsScope scope, String id, String username, Secret privateKey,
String passphrase,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be of type Secret, and should be moved into a @DataBoundSetter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, didn't want to make more changes that strictly required, but I'm fine to get one step further

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use a DataBoundSetter ? Does it make any sense to create a SSHUserPrivateKey without a private key ?

String description) {
super(scope, id, username, description);
this.privateKeySource = new DirectEntryPrivateKeySource(privateKey);
this.passphrase = fixEmpty(passphrase == null ? null : Secret.fromString(passphrase));
}


@Deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also deprecate PrivateKeySourceDescriptor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

public BasicSSHUserPrivateKey(CredentialsScope scope, String id, String username, PrivateKeySource privateKeySource,
String passphrase,
String description) {
Expand Down Expand Up @@ -296,6 +304,7 @@ public boolean isSnapshotSource() {
/**
* Descriptor for a {@link PrivateKeySource}
*/
@Deprecated
public static abstract class PrivateKeySourceDescriptor extends Descriptor<PrivateKeySource> {
}

Expand All @@ -310,9 +319,12 @@ public static class DirectEntryPrivateKeySource extends PrivateKeySource impleme

private final Secret privateKey;

@DataBoundConstructor
public DirectEntryPrivateKeySource(Secret privateKey) {
this.privateKey = privateKey;
}

public DirectEntryPrivateKeySource(String privateKey) {
this.privateKey = Secret.fromString(privateKey);
this(Secret.fromString(privateKey));
}

public DirectEntryPrivateKeySource(List<String> privateKeys) {
Expand Down Expand Up @@ -348,21 +360,6 @@ public String getPrivateKey() {
public boolean isSnapshotSource() {
return true;
}

/**
* {@inheritDoc}
*/
@Extension
public static class DescriptorImpl extends PrivateKeySourceDescriptor {

/**
* {@inheritDoc}
*/
@Override
public String getDisplayName() {
return Messages.BasicSSHUserPrivateKey_DirectEntryPrivateKeySourceDisplayName();
}
}
}

/**
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,8 @@
<f:entry title="${%Username}" field="username">
<f:textbox/>
</f:entry>
<f:entry title="${%Private Key}" field="privateKeySource">
<!-- TODO switch back to hetero-radio when the initial expansion bug is fixed -->
<j:scope>
<table style="width:100%">
<j:set var="currentInstance" value="${instance != null ? instance.privateKeySource : null}"/>
<j:set var="currentDescriptor" value="${currentInstance != null ? currentInstance.descriptor : null}"/>
<j:set var="currentName" value="${h.generateId()}.privateKeySource" />
<j:forEach var="d" items="${descriptor.privateKeySources}" varStatus="loop">
<f:radioBlock name="${currentName}" help="${d.helpFile}" value="${loop.index}"
title="${d.displayName}" checked="${currentDescriptor==d}">
<j:set var="descriptor" value="${d}" />
<j:set var="instance" value="${currentDescriptor==d?currentInstance:null}" />
<st:include from="${d}" page="${d.configPage}" optional="true" />
<f:invisibleEntry>
<input type="hidden" name="stapler-class" value="${d.clazz.name}" />
</f:invisibleEntry>
</f:radioBlock>
</j:forEach>
</table>
</j:scope>
<f:entry title="${%Private Key}" field="privateKey">
<f:textarea/>
</f:entry>
<f:entry title="${%Passphrase}" field="passphrase">
<f:password/>
Expand Down