Example #1
0
func (cmd CmdKey) Execute(args []string) error {
	if len(args) < 1 || (args[0] == "rm" && len(args) != 2) {
		return fmt.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
	}

	s, err := cmd.global.OpenRepository()
	if err != nil {
		return err
	}

	switch args[0] {
	case "list":
		return cmd.listKeys(s)
	case "add":
		return cmd.addKey(s)
	case "rm":
		id, err := backend.Find(s.Backend(), backend.Key, args[1])
		if err != nil {
			return err
		}

		return cmd.deleteKey(s, id)
	case "passwd":
		return cmd.changePassword(s)
	}

	return nil
}
Example #2
0
// FindSnapshot takes a string and tries to find a snapshot whose ID matches
// the string as closely as possible.
func FindSnapshot(repo *repository.Repository, s string) (backend.ID, error) {
	// find snapshot id with prefix
	name, err := backend.Find(repo.Backend(), backend.Snapshot, s)
	if err != nil {
		return nil, err
	}

	return backend.ParseID(name)
}
Example #3
0
// Find loads the list of all blobs of type t and searches for names which start
// with prefix. If none is found, nil and ErrNoIDPrefixFound is returned. If
// more than one is found, nil and ErrMultipleIDMatches is returned.
func (r *Repository) Find(t backend.Type, prefix string) (string, error) {
	return backend.Find(r.be, t, prefix)
}