Exemple #1
0
func cmdList(args *docopt.Args, client *tuf.Client) error {
	if _, err := client.Update(); err != nil && !tuf.IsLatestSnapshot(err) {
		return err
	}
	targets, err := client.Targets()
	if err != nil {
		return err
	}
	w := tabwriter.NewWriter(os.Stdout, 1, 2, 2, ' ', 0)
	defer w.Flush()
	fmt.Fprintln(w, "PATH\tSIZE")
	for path, meta := range targets {
		fmt.Fprintf(w, "%s\t%s\n", path, humanize.Bytes(uint64(meta.Length)))
	}
	return nil
}
Exemple #2
0
// GetVersion returns the given target's version from custom metadata
func GetVersion(client *tuf.Client, name string) (string, error) {
	targets, err := client.Targets()
	if err != nil {
		return "", err
	}
	target, ok := targets[name]
	if !ok {
		return "", fmt.Errorf("missing %q in tuf targets", name)
	}
	if target.Custom == nil || len(*target.Custom) == 0 {
		return "", errors.New("missing custom metadata in tuf target")
	}
	var data struct {
		Version string
	}
	json.Unmarshal(*target.Custom, &data)
	if data.Version == "" {
		return "", errors.New("missing version in tuf target")
	}
	return data.Version, nil
}