Skip to content
Open
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
34 changes: 30 additions & 4 deletions bin/msign
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
{
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions docs/man/msign.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
msign 1 "May 2013" Manta "Manta Commands"
msign 1 "July 2013" Manta "Manta Commands"
=======================================

NAME
Expand All @@ -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
--------
Expand Down
4 changes: 2 additions & 2 deletions man/man1/msign.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH msign 1 "May 2013" Manta "Manta Commands"
.TH msign 1 "July 2013" Manta "Manta Commands"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You need to edit docs/man/msign.md, which is the primary copy, and then regenerate the roff version with md2roff.

.SH NAME
.PP
msign \- create a signed URL to a Manta object
Expand All @@ -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:
Expand Down