directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [1/2] directory-kerby git commit: Add the feature of parsing time duration for kinit tool. Contributed by Lin Zeng.
Date Thu, 10 Aug 2017 02:03:38 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk bc1c1a62f -> 06acee13d


Add the feature of parsing time duration for kinit tool. Contributed by Lin Zeng.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/f880978f
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/f880978f
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/f880978f

Branch: refs/heads/trunk
Commit: f880978f5022977c70db5fa461c01f08c0b414be
Parents: 6080d55
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Thu Aug 10 10:01:46 2017 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Thu Aug 10 10:01:46 2017 +0800

----------------------------------------------------------------------
 .../main/java/org/apache/kerby/KOptionType.java |  3 +-
 .../main/java/org/apache/kerby/KOptions.java    | 31 ++++++++++++++++++++
 .../kerby/kerberos/tool/kinit/KinitOption.java  |  6 ++--
 3 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f880978f/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptionType.java
----------------------------------------------------------------------
diff --git a/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptionType.java b/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptionType.java
index d7e53b3..5a7f548 100644
--- a/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptionType.java
+++ b/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptionType.java
@@ -31,5 +31,6 @@ public enum KOptionType {
     FILE, // file path value
     DIR, // dir path value
     OBJ,  // arbitrary object
-    DATE // date value
+    DATE, // date value
+    DURATION // date duration value
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f880978f/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptions.java
----------------------------------------------------------------------
diff --git a/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptions.java b/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptions.java
index 9934751..24c6a9d 100644
--- a/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptions.java
+++ b/kerby-common/kerby-util/src/main/java/org/apache/kerby/KOptions.java
@@ -28,6 +28,8 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * A KOption container.
@@ -78,6 +80,35 @@ public class KOptions {
             } catch (ParseException e) {
                 throw new IllegalArgumentException("Fail to parse the date: " + strValue);
             }
+        } else if (kt == KOptionType.DURATION) {
+            int duration;
+            Matcher matcherColon = Pattern.compile("\\d+(?::\\d+){0,2}").matcher(strValue);
+            Matcher matcherWord = Pattern.compile("(?:(\\d+)D)?(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?",
+                Pattern.CASE_INSENSITIVE).matcher(strValue);
+            if (matcherColon.matches()) {
+                String[] durations = strValue.split(":");
+                if (durations.length == 1) {
+                    duration = Integer.valueOf(durations[0]);
+                } else if (durations.length == 2) {
+                    duration = Integer.valueOf(durations[0]) * 3600 + Integer.valueOf(durations[1])
* 60;
+                } else {
+                    duration = Integer.valueOf(durations[0]) * 3600 + Integer.valueOf(durations[1])
* 60;
+                    duration += Integer.valueOf(durations[2]);
+                }
+                kopt.setValue(duration);
+            } else if (matcherWord.matches()) {
+                int[] durations = new int[4];
+                for (int i = 0; i < 4; i++) {
+                    String durationMatch = matcherWord.group(i + 1);
+                    if (durationMatch != null) {
+                        durations[i] = Integer.valueOf(durationMatch);
+                    }
+                }
+                duration = durations[0] * 86400 + durations[1] * 3600 + durations[2] * 60
+ durations[3];
+                kopt.setValue(duration);
+            } else {
+                throw new IllegalArgumentException("Text can't be parsed to a Duration: "
+ strValue);
+            }
         } else if (kt == KOptionType.BOOL) {
             kopt.setValue(Boolean.valueOf(strValue));
         } else {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f880978f/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
----------------------------------------------------------------------
diff --git a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
index a4b581d..3eb18f1 100644
--- a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
+++ b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
@@ -30,11 +30,11 @@ public enum KinitOption implements KOption {
     CLIENT_PRINCIPAL(new KOptionInfo("client-principal", "Client principal",
         KrbOptionGroup.KRB, KOptionType.STR)),
     LIFE_TIME(new KOptionInfo("-l", "lifetime",
-        KrbOptionGroup.KRB, KOptionType.INT)),
+        KrbOptionGroup.KRB, KOptionType.DURATION)),
     START_TIME(new KOptionInfo("-s", "start time",
-        KrbOptionGroup.KRB, KOptionType.INT)),
+        KrbOptionGroup.KRB, KOptionType.DURATION)),
     RENEWABLE_LIFE(new KOptionInfo("-r", "renewable lifetime",
-        KrbOptionGroup.KRB, KOptionType.INT)),
+        KrbOptionGroup.KRB, KOptionType.DURATION)),
     AS_ENTERPRISE_PN(new KOptionInfo("-E", "client is enterprise principal name",
         KrbOptionGroup.KRB)),
     INCLUDE_ADDRESSES(new KOptionInfo("-a", "include addresses",


Mime
View raw message