-
Notifications
You must be signed in to change notification settings - Fork 214
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
Add option to set Basic credentials #292
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
847d27c
Add option to set Basic credentials
kwin f838043
Merge branch 'master' into feature/basic-auth
kwin 5e77d25
Update plugin-management-library/src/main/java/io/jenkins/tools/plugi…
kwin 1be02a1
Incorporate feedback from PR
kwin 968d7c0
log redirected URI even in case of errors
kwin a968447
log redirected URL always in case of errors
kwin 2db27af
Update plugin-management-library/src/main/java/io/jenkins/tools/plugi…
kwin eac1477
prevent NPE when printing usage
kwin ec045af
Merge branch 'feature/basic-auth' of [email protected]:kwin/plugin-insta…
kwin e02a022
Workaround null list
timja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...gement-cli/src/main/java/io/jenkins/tools/pluginmanager/cli/CredentialsOptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.jenkins.tools.pluginmanager.cli; | ||
|
||
import io.jenkins.tools.pluginmanager.config.Credentials; | ||
import org.kohsuke.args4j.CmdLineException; | ||
import org.kohsuke.args4j.CmdLineParser; | ||
import org.kohsuke.args4j.OptionDef; | ||
import org.kohsuke.args4j.spi.OneArgumentOptionHandler; | ||
import org.kohsuke.args4j.spi.Setter; | ||
|
||
public class CredentialsOptionHandler extends OneArgumentOptionHandler<Credentials> { | ||
|
||
public CredentialsOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super Credentials> setter) { | ||
super(parser, option, setter); | ||
} | ||
|
||
@Override | ||
protected Credentials parse(String argument) throws CmdLineException { | ||
final Credentials option; | ||
// extract the 4 pieces: username, password, host, port | ||
final String[] parts = argument.split(":", 4); | ||
if (parts.length < 3) { | ||
throw new CmdLineException(owner, Messages.INVALID_CREDENTIALS_VALUE, argument); | ||
} | ||
if (parts.length == 3) { | ||
option = new Credentials(parts[1], parts[2], parts[0]); | ||
} else { | ||
int port = Integer.parseInt(parts[1]); | ||
option = new Credentials(parts[2], parts[3], parts[0], port); | ||
} | ||
return option; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
plugin-management-cli/src/main/java/io/jenkins/tools/pluginmanager/cli/Messages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.jenkins.tools.pluginmanager.cli; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Locale; | ||
import java.util.ResourceBundle; | ||
import org.kohsuke.args4j.Localizable; | ||
|
||
enum Messages implements Localizable { | ||
INVALID_CREDENTIALS_VALUE; | ||
|
||
public String formatWithLocale(Locale locale, Object... args) { | ||
ResourceBundle localized = ResourceBundle.getBundle(Messages.class.getName(), locale); | ||
return MessageFormat.format(localized.getString(name()),args); | ||
} | ||
|
||
public String format(Object... args) { | ||
return formatWithLocale(Locale.getDefault(),args); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...t-cli/src/main/java/io/jenkins/tools/pluginmanager/cli/MultiCredentialsOptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.jenkins.tools.pluginmanager.cli; | ||
|
||
import io.jenkins.tools.pluginmanager.config.Credentials; | ||
import org.kohsuke.args4j.CmdLineParser; | ||
import org.kohsuke.args4j.OptionDef; | ||
import org.kohsuke.args4j.spi.DelimitedOptionHandler; | ||
import org.kohsuke.args4j.spi.Setter; | ||
|
||
public class MultiCredentialsOptionHandler extends DelimitedOptionHandler<Credentials> { | ||
|
||
public MultiCredentialsOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super Credentials> setter) { | ||
super(parser, option, setter, ",", new CredentialsOptionHandler(parser, option, setter)); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...-management-cli/src/main/resources/io/jenkins/tools/pluginmanager/cli/Messages.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
INVALID_CREDENTIALS_VALUE = \ | ||
Require at least a value containing 2 colons but found "{0}". The value must adhere to the grammar "<host>[:port]:<username>:<password>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...n-management-library/src/main/java/io/jenkins/tools/pluginmanager/config/Credentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package io.jenkins.tools.pluginmanager.config; | ||
|
||
public class Credentials { | ||
|
||
private final String username; | ||
private final String password; | ||
private final String host; | ||
private final int port; | ||
|
||
public Credentials(String username, String password, String host, int port) { | ||
this.username = username; | ||
this.password = password; | ||
this.host = host; | ||
this.port = port; | ||
} | ||
|
||
public Credentials(String username, String password, String host) { | ||
this(username, password, host, -1); | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Credentials [username=" + username + ", password=***, host=" + host + ", port=" + port + "]"; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((host == null) ? 0 : host.hashCode()); | ||
result = prime * result + ((password == null) ? 0 : password.hashCode()); | ||
result = prime * result + port; | ||
result = prime * result + ((username == null) ? 0 : username.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
Credentials other = (Credentials) obj; | ||
if (host == null) { | ||
if (other.host != null) | ||
return false; | ||
} else if (!host.equals(other.host)) | ||
return false; | ||
if (password == null) { | ||
if (other.password != null) | ||
return false; | ||
} else if (!password.equals(other.password)) | ||
return false; | ||
if (port != other.port) | ||
return false; | ||
if (username == null) { | ||
if (other.username != null) | ||
return false; | ||
} else if (!username.equals(other.username)) | ||
return false; | ||
return true; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Messages.properties
doesn't need to be filtered. Can move it tosrc/main/resources-filtered
but this has the overhead of unnecessary filtering...