diff --git a/bin/msign b/bin/msign index 4f362e1..808ecfb 100755 --- a/bin/msign +++ b/bin/msign @@ -29,9 +29,10 @@ var OPTIONS_PARSER = dashdash.createParser({ options: manta.DEFAULT_CLI_OPTIONS.concat([ { names: ['expires', 'e'], - type: 'positiveInteger', - help: 'expiration time (epoch). Default is 1hr from now.', - 'default': Math.floor((new Date().getTime() / 1000) + 3600), + type: 'string', + help: 'expiration time (ISO 8601 DateTimeString or time since' + + ' the epoch in seconds). Default is 1hr from now.', + 'default': null, helpArg: 'EXPIRATION' }, { @@ -103,6 +104,31 @@ function parseOptions() { return (opts); } +function validateDate(dateString) { + var num_reg =/^\d+$/; + var iso_reg =/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/; + var rtn; + + if (dateString === null) { + return Math.floor((Date.now() / 1000) + 3600); + } + + if (num_reg.test(dateString)) { + rtn = parseInt(dateString); + } + else if (iso_reg.test(dateString)) { + date = new Date(dateString); + if (isNaN(date.valueOf())) { + ifError(date); + } + rtn = Math.floor(date.getTime() / 1000); + } + else { + ifError('Inproper Date format'); + } + + return (rtn); +} ///--- Mainline @@ -122,7 +148,7 @@ function parseOptions() { var _opts = { algorithm: opts.algorithm, - expires: opts.expires, + expires: validateDate(opts.expires), host: url.parse(opts.url).host, keyId: opts.keyId, log: opts.log, diff --git a/docs/man/msign.md b/docs/man/msign.md index fb2a80b..71b66ba 100644 --- a/docs/man/msign.md +++ b/docs/man/msign.md @@ -1,4 +1,4 @@ -msign 1 "May 2013" Manta "Manta Commands" +msign 1 "July 2013" Manta "Manta Commands" ======================================= NAME @@ -23,7 +23,7 @@ The default expiration for URLs is 1 hour from `now`, but this can be changed with the `expires` option. The expires option is designed to be used in conjunction with the UNIX date command. In general, you should use the date command with a modifier (the syntax is different between BSD and GNU forms), and -format the output to epoch time. +format the output to epoch time or use an ISO 8601 format. EXAMPLES -------- diff --git a/man/man1/msign.1 b/man/man1/msign.1 index cc7d881..405774c 100644 --- a/man/man1/msign.1 +++ b/man/man1/msign.1 @@ -1,4 +1,4 @@ -.TH msign 1 "May 2013" Manta "Manta Commands" +.TH msign 1 "July 2013" Manta "Manta Commands" .SH NAME .PP msign \- create a signed URL to a Manta object @@ -16,7 +16,7 @@ The default expiration for URLs is 1 hour from \fB\fCnow\fR, but this can be cha with the \fB\fCexpires\fR option. The expires option is designed to be used in conjunction with the UNIX date command. In general, you should use the date command with a modifier (the syntax is different between BSD and GNU forms), and -format the output to epoch time. +format the output to epoch time or use an ISO 8601 format. .SH EXAMPLES .PP Assuming the GNU date command, generate a signed URL that expires in one month: