-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This command is helpful for users that would like to have automation tooling keep the timestamp and snapshot metadata fresh. Signed-off-by: Andy Doan <[email protected]>
- Loading branch information
Showing
5 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/flynn/go-docopt" | ||
"github.com/theupdateframework/go-tuf" | ||
) | ||
|
||
func init() { | ||
register("refresh", cmdRefresh, ` | ||
usage: tuf refresh [--snapshot-threshold=<hours> --timestamp-threshold=<hours>] | ||
Resign the snapshot and/or timestamp metadata if needed. If either metadata | ||
is expiring in less than the number of hours given by the threshold, its | ||
metadata will expiration will be refreshed and the change(s) will be committed. | ||
Alternatively, passphrases can be set via environment variables in the | ||
form of TUF_{{ROLE}}_PASSPHRASE | ||
Options: | ||
--snapshot-threshold=<hours> Set the threshold for when to resign expiring | ||
snapshot metadata. | ||
--timestamp-threshold=<hours> Set the threshold for when to resign expiring | ||
timestamp metadata | ||
`) | ||
} | ||
|
||
func cmdRefresh(args *docopt.Args, repo *tuf.Repo) error { | ||
ssThreshold := time.Now().Add(time.Hour * -1) | ||
tsThreshold := time.Now().Add(time.Hour * -1) | ||
|
||
if arg := args.String["--snapshot-threshold"]; arg != "" { | ||
hours, err := strconv.Atoi(arg) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse --snapshot-threshold arg: %s", err) | ||
} | ||
ssThreshold = time.Now().Add(time.Hour * time.Duration(hours) * -1) | ||
} | ||
if arg := args.String["--timestamp-threshold"]; arg != "" { | ||
hours, err := strconv.Atoi(arg) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse --timestamp-threshold arg: %s", err) | ||
} | ||
tsThreshold = time.Now().Add(time.Hour * time.Duration(hours) * -1) | ||
} | ||
return repo.RefreshExpires(ssThreshold, tsThreshold) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters