-
Notifications
You must be signed in to change notification settings - Fork 87
/
interfaces.go
151 lines (126 loc) · 5.57 KB
/
interfaces.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package interfaces
import (
"context"
"io"
"net/http"
"time"
"github.com/buildbuddy-io/buildbuddy/server/tables"
inpb "github.com/buildbuddy-io/buildbuddy/proto/invocation"
)
// An interface representing the user info gleaned from an authorization header.
type UserToken interface {
GetIssuer() string
GetSubscriber() string
// Returns a fq string usable as an ID for this issuer + subscriber.
GetSubID() string
}
// An interface representing the user info gleaned from http basic auth, which is
// often set for GRPC requests.
type BasicAuthToken interface {
GetUser() string
GetPassword() string
}
type Authenticator interface {
// Redirect to configured authentication provider.
Login(w http.ResponseWriter, r *http.Request)
// Clear any logout state.
Logout(w http.ResponseWriter, r *http.Request)
// Handle a callback from authentication provider.
Auth(w http.ResponseWriter, r *http.Request)
// Called by the authentication handler to authenticate a request. If a
// user was authenticated, a new context will be returned that contains
// a UserToken.
AuthenticateHTTPRequest(w http.ResponseWriter, r *http.Request) context.Context
// Called by the authentication handler to authenticate a request. If a
// user was authenticated, a new context will be returned that contains
// a BasicAuthToken.
AuthenticateGRPCRequest(ctx context.Context) context.Context
// Returns the UserToken extracted from any authorization headers
// present in the request. This does not guarantee the user has been
// registered -- it only indicates they were authenticated using some
// auth provider.
//
// To check if a user is registered, use UserDB!
GetUserToken(ctx context.Context) (UserToken, error)
// Returns the BasicAuthToken extracted from any user/password set on
// the RPC request. This does not guarantee the user has been
// registered -- it only indicates they were authenticated using the
// BASIC auth provider.
//
// To check if a user or group registered, use UserDB!
GetBasicAuthToken(ctx context.Context) (BasicAuthToken, error)
// FillUser may be used to construct an initial tables.User object. It
// is filled based on information from the authenticator's JWT.
FillUser(ctx context.Context, user *tables.User) error
}
// A Blobstore must allow for reading, writing, and deleting blobs.
// Implementations should return "os"-compatible package type errors, for
// example, if a file does not exist on Read, the blobstore should return an
// "os.ErrNotExist" error.
type Blobstore interface {
BlobExists(ctx context.Context, blobName string) (bool, error)
ReadBlob(ctx context.Context, blobName string) ([]byte, error)
WriteBlob(ctx context.Context, blobName string, data []byte) (int, error)
DeleteBlob(ctx context.Context, blobName string) error
}
// Similar to a blobstore, a cache allows for reading and writing data, but
// additionally it is responsible for deleting data that is past TTL to keep to
// a manageable size.
type Cache interface {
// Normal cache-like operations.
Contains(ctx context.Context, key string) (bool, error)
Get(ctx context.Context, key string) ([]byte, error)
Set(ctx context.Context, key string, data []byte) error
Delete(ctx context.Context, key string) error
// Low level interface used for seeking and stream-writing.
Reader(ctx context.Context, key string, offset, length int64) (io.Reader, error)
Writer(ctx context.Context, key string) (io.WriteCloser, error)
// Begin garbage collection and any other necessary background tasks.
Start() error
// Stop garbage collection etc.
Stop() error
}
type InvocationDB interface {
// Invocations API
InsertOrUpdateInvocation(ctx context.Context, in *tables.Invocation) error
LookupInvocation(ctx context.Context, invocationID string) (*tables.Invocation, error)
LookupExpiredInvocations(ctx context.Context, cutoffTime time.Time, limit int) ([]*tables.Invocation, error)
DeleteInvocation(ctx context.Context, invocationID string) error
}
type AuthDB interface {
InsertOrUpdateUserToken(ctx context.Context, subID string, token *tables.Token) error
ReadToken(ctx context.Context, subID string) (*tables.Token, error)
}
type UserDB interface {
// User API
InsertUser(ctx context.Context, u *tables.User) error
// GetUser will return the registered user's information or
// an error if no registered user was found. It requires that a
// valid authenticator is present in the environment and will return
// a UserToken given the provided context.
GetUser(ctx context.Context) (*tables.User, error)
DeleteUser(ctx context.Context, userID string) error
// Creates the DEFAULT group, for on-prem usage where there is only
// one group and all users are implicitly a part of it.
CreateDefaultGroup(ctx context.Context) error
// Groups API
InsertOrUpdateGroup(ctx context.Context, g *tables.Group) error
GetBasicAuthGroup(ctx context.Context) (*tables.Group, error)
DeleteGroup(ctx context.Context, groupID string) error
}
// A webhook can be called when a build is completed.
type Webhook interface {
NotifyComplete(ctx context.Context, invocation *inpb.Invocation) error
}
// Allows aggregating invocation statistics.
type InvocationStatService interface {
GetInvocationStat(ctx context.Context, req *inpb.GetInvocationStatRequest) (*inpb.GetInvocationStatResponse, error)
}
// Allows searching invocations.
type InvocationSearchService interface {
IndexInvocation(ctx context.Context, invocation *inpb.Invocation) error
QueryInvocations(ctx context.Context, req *inpb.SearchInvocationRequest) (*inpb.SearchInvocationResponse, error)
}
type SplashPrinter interface {
PrintSplashScreen(port, grpcPort int)
}