summaryrefslogtreecommitdiff
path: root/store/misc.go
blob: b72fa66de57293797eeacc73b8fae7069d69144d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package store

import (
	"errors"
	"net/url"
	"regexp"
)

const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

var (
	nameRegex   = regexp.MustCompile(`^[a-z0-9()_-]{3,}$`)
	sha256Regex = regexp.MustCompile(`\b[A-Fa-f0-9]{64}\b`)
	secretRegex = regexp.MustCompile(`\b[A-Za-z]{64}\b`)
)

var (
	// AlreadyExists is returned when store already exists.
	AlreadyExists = errors.New("store path already exists")
)

// These two really shouldn't be methods... Maybe change that for v2.

// MatchName determines if str is a valid name.
func (s *Store) MatchName(str string) bool {
	return nameRegex.MatchString(str)
}

// MatchURL determines if str is a valid URL.
func (s *Store) MatchURL(str string) bool {
	u, err := url.Parse(str)
	return err == nil && u.Scheme != "" && u.Host != ""
}