Skip to content

Commit 31fd6b1

Browse files
author
Markus Binsteiner
committed
Updated jcommander version, Some minor adjustments
1 parent 555530a commit 31fd6b1

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
<dependency>
193193
<groupId>com.beust</groupId>
194194
<artifactId>jcommander</artifactId>
195-
<version>1.25</version>
195+
<version>1.30</version>
196196
</dependency>
197197
<dependency>
198198
<groupId>com.jcraft</groupId>

src/main/java/grith/jgrith/cred/AbstractCred.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ public Class getValueClass() {
9797
public static AbstractCred create(AbstractCallback callback) {
9898
return loadFromConfig(null, callback);
9999
}
100+
101+
public static AbstractCred getExistingOrCliCredential() {
102+
103+
ProxyCred pc = new ProxyCred();
104+
105+
if ( pc.isValid() ) {
106+
return pc;
107+
}
108+
109+
AbstractCred c = AbstractCred.loadFromConfig(null, new CliCallback());
110+
111+
return c;
112+
}
100113

101114
public static AbstractCred loadFromConfig(Map<PROPERTY, Object> config) {
102115
return loadFromConfig(config, null);
@@ -225,7 +238,7 @@ public static void main(String[] args) throws Exception {
225238
private CredentialMinThreshold minThresholdTask = null;
226239

227240
private CredentialRenewTask renewTask = null;
228-
private final Timer timer = new Timer(true);
241+
private final Timer timer = new Timer("CredentialUpdate timer", true);
229242

230243
private boolean saveProxyOnCreation = true;
231244

src/main/java/grith/jgrith/cred/GridCliParameters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class GridCliParameters {
4242
@Parameter(names = { "-s", "--start-session" }, description = "start or use existing background session to hold and update credential (on Linux)")
4343
private boolean startGridSession;
4444

45-
@Parameter(names = { "-h", "--help" }, description = "display this help text")
45+
@Parameter(names = { "-h", "--help" }, description = "display this help text", help = true)
4646
private boolean help;
4747

4848
private char[] password;

src/main/java/grith/jgrith/cred/GridLoginParameters.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,25 @@ public class GridLoginParameters {
3232

3333
public static GridLoginParameters createFromCommandlineArgs(
3434
GridCliParameters params, String[] args) {
35+
return createFromCommandlineArgs(params, args, true);
36+
}
37+
38+
public static GridLoginParameters createFromCommandlineArgs(
39+
GridCliParameters params, String[] args, boolean exitWhenHelp) {
3540

3641
// GridLoginParameters glp = new GridLoginParameters();
3742
try {
38-
39-
String[] gridArgs = CommandlineArgumentHelpers.extractGridParameters(params, args);
40-
43+
44+
String[] gridArgs = CommandlineArgumentHelpers
45+
.extractGridParameters(params, args);
46+
4147
JCommander jc = new JCommander(params, gridArgs);
4248

43-
if (params.isHelp()) {
44-
jc.usage();
45-
System.exit(0);
49+
if (exitWhenHelp) {
50+
if (params.isHelp()) {
51+
jc.usage();
52+
System.exit(0);
53+
}
4654
}
4755

4856
return createFromGridCliParameters(params);
@@ -54,7 +62,8 @@ public static GridLoginParameters createFromCommandlineArgs(
5462

5563
}
5664

57-
public static GridLoginParameters createFromGridCliParameters(GridCliParameters settings) {
65+
public static GridLoginParameters createFromGridCliParameters(
66+
GridCliParameters settings) {
5867
GridLoginParameters glp = new GridLoginParameters();
5968
try {
6069

@@ -174,21 +183,18 @@ public Map<PROPERTY, Object> getCredProperties() {
174183

175184
return result;
176185
}
177-
178-
186+
179187
public String getInstitution() {
180188
return institution.getValue();
181189
}
182190

183-
184191
public LoginType getLoginType() {
185192
if (loginType == null) {
186193
return null;
187194
}
188195
return LoginType.fromString(loginType.getValue());
189196
}
190197

191-
192198
public String getMyProxyHost() {
193199
return myproxyHost.getValue();
194200
}
@@ -221,8 +227,7 @@ public void populate() {
221227

222228
LoginType lt = getLoginType();
223229

224-
225-
if ( lt == null ) {
230+
if (lt == null) {
226231
String idp = institution.getValue();
227232
if (StringUtils.isBlank(idp)) {
228233
idp = CommonGridProperties.getDefault().getLastShibIdp();
@@ -267,19 +272,19 @@ public void populate() {
267272

268273
loginType.set(lt.toString());
269274

270-
switch(lt) {
275+
switch (lt) {
271276
case SHIBBOLETH:
272277
String idpToUse = institution.getValue();
273278
if (StringUtils.isBlank(idpToUse)) {
274279
String answer = callback.getStringValue(institution);
275280
institution.set(answer);
276281
}
277-
if (! username.isSet() ) {
282+
if (!username.isSet()) {
278283
String answer = callback.getStringValue(username);
279284
username.set(answer);
280285
}
281286

282-
if (! password.isSet()) {
287+
if (!password.isSet()) {
283288
char[] answer = callback.getPasswordValue(password);
284289
password.set(answer);
285290
}
@@ -313,11 +318,10 @@ public void populate() {
313318
"No valid credential after callbacks.");
314319
}
315320

316-
317321
}
318322

319323
public void setCallback(AbstractCallback c) {
320-
this.callback =c;
324+
this.callback = c;
321325
}
322326

323327
private void setForceAuthenticate(boolean forceAuth) {

src/main/java/grith/jgrith/utils/CommandlineArgumentHelpers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static Set<String> booleanParams(GridCliParameters params) {
8888

8989
for ( ParameterDescription pd : list ) {
9090

91-
Class type = pd.getField().getType();
91+
Class type = pd.getParameterized().getType();
9292
if ( type == boolean.class || type == Boolean.class ) {
9393
String[] tokens = pd.getNames().split(",");
9494
for ( String token : tokens ) {
@@ -110,7 +110,7 @@ public static Set<String> nonBooleanParameters(GridCliParameters params) {
110110

111111
for ( ParameterDescription pd : list ) {
112112

113-
Class type = pd.getField().getType();
113+
Class type = pd.getParameterized().getType();
114114
if ( type != boolean.class && type != Boolean.class ) {
115115
String[] tokens = pd.getNames().split(",");
116116
for ( String token : tokens ) {

0 commit comments

Comments
 (0)