-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This command can be used to help automation tooling decide when metadata expirations will be reached. # See if timestamp metadata is expiring in the next hour: $ tuf status --valid-at "$(date -d '+1 hour')" timestamp Signed-off-by: Andy Doan <[email protected]>
- Loading branch information
Showing
5 changed files
with
111 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,47 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/flynn/go-docopt" | ||
"github.com/theupdateframework/go-tuf" | ||
) | ||
|
||
func init() { | ||
register("status", cmdStatus, ` | ||
usage: tuf status --valid-at=<date> <role> | ||
Check if the role's metadata will be expired on the given date. | ||
The command's exit status will be 1 if the role has expired, 0 otherwise. | ||
Example: | ||
# See if timestamp metadata is expiring in the next hour: | ||
tuf status --valid-at "$(date -d '+1 hour')" timestamp || echo "Time to refresh" | ||
Options: | ||
--valid-at=<date> Must be in one of the formats: | ||
* RFC3339 - 2006-01-02T15:04:05Z07:00 | ||
* RFC822 - 02 Jan 06 15:04 MST | ||
* UnixDate - Mon Jan _2 15:04:05 MST 2006 | ||
`) | ||
} | ||
|
||
func cmdStatus(args *docopt.Args, repo *tuf.Repo) error { | ||
role := args.String["<role>"] | ||
validAtStr := args.String["--valid-at"] | ||
|
||
formats := []string{ | ||
time.RFC3339, | ||
time.RFC822, | ||
time.UnixDate, | ||
} | ||
for _, fmt := range formats { | ||
validAt, err := time.Parse(fmt, validAtStr) | ||
if err == nil { | ||
return repo.CheckRoleUnexpired(role, validAt) | ||
} | ||
} | ||
return fmt.Errorf("failed to parse --valid-at arg") | ||
} |
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