-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautograder.go
More file actions
40 lines (35 loc) · 1.12 KB
/
autograder.go
File metadata and controls
40 lines (35 loc) · 1.12 KB
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
package helpbot
import (
"context"
"crypto/tls"
"net/http"
"connectrpc.com/connect"
"github.com/quickfeed/quickfeed/qf/qfconnect"
)
type QuickFeed struct {
qf qfconnect.QuickFeedServiceClient
}
func NewQuickFeed(authToken string) (*QuickFeed, error) {
client := http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
qf := qfconnect.NewQuickFeedServiceClient(&client, "https://uis.itest.run", connect.WithInterceptors(tokenAuthClientInterceptor(authToken)))
return &QuickFeed{
qf: qf,
}, nil
}
// NewTokenAuthClientInterceptor returns a client interceptor that will add the given token in the Authorization header.
func tokenAuthClientInterceptor(token string) connect.UnaryInterceptorFunc {
interceptor := func(next connect.UnaryFunc) connect.UnaryFunc {
return connect.UnaryFunc(func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
if req.Spec().IsClient {
// Send a token with client requests.
req.Header().Set("Authorization", token)
}
return next(ctx, req)
})
}
return connect.UnaryInterceptorFunc(interceptor)
}