Skip to content
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

Tuftool - accept relative dates #438

Merged
merged 3 commits into from
Oct 21, 2019
Merged

Tuftool - accept relative dates #438

merged 3 commits into from
Oct 21, 2019

Conversation

tjkirch
Copy link
Contributor

@tjkirch tjkirch commented Oct 21, 2019

0df8d11 tuftool: allow for relative date arguments like 'in 7 days'
81c6a71 tuftool: disable clippy use_self lint for clearer identifiers
dd6cc7a tuftool: fix typo that put snapshot version/expires into timestamp

Fixes #213

Testing done:

New usage message for root expire:

$ cargo run -- root expire --help
tuftool-root-expire 0.1.0
Set the expiration time for root.json

USAGE:
    tuftool root expire <path> <time>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <path>    Path to root.json
    <time>    Expiration of root; can be in full RFC 3339 format, or something like 'in 7 days'

And for create:

tuftool-create 0.1.0
Create a TUF repository

USAGE:
    tuftool create [FLAGS] [OPTIONS] <indir> <outdir> --root <root> --snapshot-expires <snapshot-expires> --snapshot-version <snapshot-version> --targets-expires <targets-expires> --targets-version <targets-version> --timestamp-expires <timestamp-expires> --timestamp-version <timestamp-version>

FLAGS:
    -c, --copy        Copy files into `outdir` instead of symlinking them
    -f, --follow      Follow symbolic links in `indir`
    -H, --hardlink    Hardlink files into `outdir` instead of symlinking them
    -h, --help        Prints help information
    -V, --version     Prints version information

OPTIONS:
    -j, --jobs <jobs>                              Number of target hashing threads to run (default: number of cores)
    -k, --key <keys>...                            Key files to sign with
    -r, --root <root>                              Path to root.json file for the repository
        --snapshot-expires <snapshot-expires>
            Expiration of snapshot.json file; can be in full RFC 3339 format, or something like 'in 7 days'

        --snapshot-version <snapshot-version>      Version of snapshot.json file
        --targets-expires <targets-expires>
            Expiration of targets.json file; can be in full RFC 3339 format, or something like 'in 7 days'

        --targets-version <targets-version>        Version of targets.json file
        --timestamp-expires <timestamp-expires>
            Expiration of timestamp.json file; can be in full RFC 3339 format, or something like 'in 7 days'

        --timestamp-version <timestamp-version>    Version of timestamp.json file

ARGS:
    <indir>     Directory of targets
    <outdir>    Repository output directory

Root expire accepts relative:

$ cargo run -- root expire root.json 'in 52 weeks'

$ grep expire root.json
    "expires": "2020-10-19T17:07:33Z",

Create accepts relative:

$ cargo run -- create ./src ./outdir --root root.json --snapshot-expires 'in 2 days' --snapshot-version 42 --targets-expires 'in 1 hour' --targets-version 42 --timestamp-expires 'in 6 weeks' --timestamp-version 42
cargo run -- create ./src ./outdir --root root.json --snapshot-expires   42    6.64s user 1.11s system 102% cpu 7.596 total
 
$ grep expire outdir/metadata/*
grep: outdir/metadata/1.root.json: No such file or directory
outdir/metadata/42.snapshot.json:    "expires": "2019-10-23T17:13:42.305040769Z",
outdir/metadata/42.targets.json:    "expires": "2019-10-21T18:13:42.305052425Z",
outdir/metadata/timestamp.json:    "expires": "2019-12-02T17:13:42.305061253Z",

$ date --rfc-3339=seconds -u
2019-10-21 17:13:49+00:00

You can also see that the timestamp expiration is correct now; before, it showed the same as the snapshot expiration.

RFC 3339 format also works:

$ cargo run -- root expire root.json '2019-10-21T19:13:49+00:00'
$ grep expire root.json
    "expires": "2019-10-21T19:13:49Z",

Or with Z:

$ cargo run -- root expire root.json '2019-10-21T19:13:49Z'
$ grep expire root.json
    "expires": "2019-10-21T19:13:49Z",

@tjkirch tjkirch requested review from iliana and sam-aws October 21, 2019 17:21
Copy link
Contributor

@iliana iliana left a comment

Choose a reason for hiding this comment

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

🎉 🚣‍♀️


let now = Utc::now();
let then = now + duration;
Ok(then)
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, OK then

@tjkirch tjkirch merged commit f6279f7 into develop Oct 21, 2019
@tjkirch tjkirch deleted the tuftool-relative branch October 21, 2019 17:43
iliana added a commit that referenced this pull request Oct 21, 2019
Signed-off-by: iliana destroyer of worlds <iweller@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tuftool: Accept relative date arguments
3 participants