File size: 1,789 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
package permission

//go:generate go tool stringer -type SourceType

// SourceType describes a type of authentication used to authorize a context.
type SourceType int

const (
	// SourceTypeNotificationCallback is set when a context is authenticated via the response to an outgoing notification.
	SourceTypeNotificationCallback SourceType = iota

	// SourceTypeIntegrationKey is set when an integration key is used to provide permission on a context.
	SourceTypeIntegrationKey

	// SourceTypeAuthProvider is set when a provider from the auth package is used (e.g. the web UI).
	SourceTypeAuthProvider

	// SourceTypeContactMethod is set when a context is authorized for use of a user's contact method.
	SourceTypeContactMethod

	// SourceTypeHeartbeat is set when a context is authorized for use of a service's heartbeat.
	SourceTypeHeartbeat

	// SourceTypeNotificationChannel is set when a context is authorized for use of a notification channel.
	SourceTypeNotificationChannel

	// SourceTypeCalendarSubscription is set when a context is authorized for use of a calendar subscription.
	SourceTypeCalendarSubscription

	// SourceTypeGQLAPIKey is set when a context is authorized for use of the GraphQL API.
	SourceTypeGQLAPIKey

	// SourceTypeUIK is set when a context is authorized for use of a universal integration key.
	SourceTypeUIK
)

// SourceInfo provides information about the source of a context's authorization.
type SourceInfo struct {
	Type SourceType
	ID   string
}

func (s SourceInfo) String() string {
	str := s.Type.String()
	if s.ID != "" {
		// using curly-braces so that it doesn't look too confusing
		// if we ever run into an unknown source type
		//
		// unknown will show up as SourceType(n) where n is the int value.
		str += "{" + s.ID + "}"
	}
	return str
}