@@ -62,10 +62,7 @@ func (s *Server) Authenticate(ctx context.Context, req *protos.AuthenticateReque
62
62
63
63
// CreateInstance will create a gomote instance for the authenticated user.
64
64
func (s * Server ) CreateInstance (req * protos.CreateInstanceRequest , stream protos.GomoteService_CreateInstanceServer ) error {
65
- ctx , cancel := context .WithTimeout (stream .Context (), 5 * time .Minute )
66
- defer cancel ()
67
-
68
- creds , err := access .IAPFromContext (ctx )
65
+ creds , err := access .IAPFromContext (stream .Context ())
69
66
if err != nil {
70
67
log .Printf ("CreateInstance access.IAPFromContext(ctx) = nil, %s" , err )
71
68
return status .Errorf (codes .Unauthenticated , "request does not contain the required authentication" )
@@ -90,14 +87,14 @@ func (s *Server) CreateInstance(req *protos.CreateInstanceRequest, stream protos
90
87
}
91
88
rc := make (chan result , 1 )
92
89
go func () {
93
- bc , err := s .scheduler .GetBuildlet (ctx , si )
90
+ bc , err := s .scheduler .GetBuildlet (stream . Context () , si )
94
91
rc <- result {bc , err }
95
92
}()
96
93
ticker := time .NewTicker (5 * time .Second )
97
94
defer ticker .Stop ()
98
95
for {
99
96
select {
100
- case <- ctx .Done ():
97
+ case <- stream . Context () .Done ():
101
98
return status .Errorf (codes .DeadlineExceeded , "timed out waiting for gomote instance to be created" )
102
99
case <- ticker .C :
103
100
st := s .scheduler .WaiterState (si )
@@ -149,21 +146,19 @@ func (s *Server) ListInstances(ctx context.Context, req *protos.ListInstancesReq
149
146
log .Printf ("ListInstances access.IAPFromContext(ctx) = nil, %s" , err )
150
147
return nil , status .Errorf (codes .Unauthenticated , "request does not contain the required authentication" )
151
148
}
152
- var instances [] * protos.Instance
149
+ res := & protos.ListInstancesResponse {}
153
150
for _ , s := range s .buildlets .List () {
154
151
if s .OwnerID != creds .ID {
155
152
continue
156
153
}
157
- instances = append (instances , & protos.Instance {
154
+ res . Instances = append (res . Instances , & protos.Instance {
158
155
GomoteId : s .ID ,
159
156
BuilderType : s .BuilderType ,
160
157
HostType : s .HostType ,
161
158
Expires : s .Expires .Unix (),
162
159
})
163
160
}
164
- return & protos.ListInstancesResponse {
165
- Instances : instances ,
166
- }, nil
161
+ return res , nil
167
162
}
168
163
169
164
// DestroyInstance will destroy a gomote instance. It will ensure that the caller is authenticated and is the owner of the instance
0 commit comments