aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/util/status.go
blob: 23ae16528ea9dda156b56a65c107a0054b91ac52 (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package util

import "fmt"

// CachingStatus represents the api server's perspective
// on whether remote caching should be allowed
type CachingStatus int

const (
	// CachingStatusDisabled indicates that the server will not accept or serve artifacts
	CachingStatusDisabled CachingStatus = iota
	// CachingStatusEnabled indicates that the server will accept and serve artifacts
	CachingStatusEnabled
	// CachingStatusOverLimit indicates that a usage limit has been hit and the
	// server will temporarily not accept or serve artifacts
	CachingStatusOverLimit
	// CachingStatusPaused indicates that a customer's spending has been paused and the
	// server will temporarily not accept or serve artifacts
	CachingStatusPaused
)

// CachingStatusFromString parses a raw string to a caching status enum value
func CachingStatusFromString(raw string) (CachingStatus, error) {
	switch raw {
	case "disabled":
		return CachingStatusDisabled, nil
	case "enabled":
		return CachingStatusEnabled, nil
	case "over_limit":
		return CachingStatusOverLimit, nil
	case "paused":
		return CachingStatusPaused, nil
	default:
		return CachingStatusDisabled, fmt.Errorf("unknown caching status: %v", raw)
	}
}

// CacheDisabledError is an error used to indicate that remote caching
// is not available.
type CacheDisabledError struct {
	Status  CachingStatus
	Message string
}

func (cd *CacheDisabledError) Error() string {
	return cd.Message
}