...

Source file src/github.com/theupdateframework/go-tuf/cmd/tuf/status.go

Documentation: github.com/theupdateframework/go-tuf/cmd/tuf

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/flynn/go-docopt"
     8  	"github.com/theupdateframework/go-tuf"
     9  )
    10  
    11  func init() {
    12  	register("status", cmdStatus, `
    13  usage: tuf status --valid-at=<date> <role>
    14  
    15  Check if the role's metadata will be expired on the given date.
    16  
    17  The command's exit status will be 1 if the role has expired, 0 otherwise.
    18  
    19  Example:
    20    # See if timestamp metadata is expiring in the next hour:
    21    tuf status --valid-at "$(date -d '+1 hour')" timestamp || echo "Time to refresh"
    22  
    23  Options:
    24    --valid-at=<date>   Must be in one of the formats:
    25                        * RFC3339  - 2006-01-02T15:04:05Z07:00
    26                        * RFC822   - 02 Jan 06 15:04 MST
    27                        * UnixDate - Mon Jan _2 15:04:05 MST 2006
    28  `)
    29  }
    30  
    31  func cmdStatus(args *docopt.Args, repo *tuf.Repo) error {
    32  	role := args.String["<role>"]
    33  	validAtStr := args.String["--valid-at"]
    34  
    35  	formats := []string{
    36  		time.RFC3339,
    37  		time.RFC822,
    38  		time.UnixDate,
    39  	}
    40  	for _, fmt := range formats {
    41  		validAt, err := time.Parse(fmt, validAtStr)
    42  		if err == nil {
    43  			return repo.CheckRoleUnexpired(role, validAt)
    44  		}
    45  	}
    46  	return fmt.Errorf("failed to parse --valid-at arg")
    47  }
    48  

View as plain text