forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authprovider.go
45 lines (37 loc) · 1.21 KB
/
authprovider.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
package mocktc
import (
"net/http"
"github.com/gorilla/mux"
"github.com/taskcluster/taskcluster/v54/clients/client-go/tcauth"
"github.com/taskcluster/taskcluster/v54/internal/mocktc/tc"
)
type AuthProvider struct {
auth tc.Auth
}
func NewAuthProvider(auth tc.Auth) *AuthProvider {
return &AuthProvider{
auth: auth,
}
}
func (ap *AuthProvider) RegisterService(r *mux.Router) {
s := r.PathPrefix("/api/auth/v1").Subrouter()
s.HandleFunc("/scopes/expand", ap.ExpandScopes).Methods("POST")
s.HandleFunc("/sentry/{project}/dsn", ap.SentryDSN).Methods("GET")
s.HandleFunc("/websocktunnel/{wstAudience}/{wstClient}", ap.WebsocktunnelToken).Methods("GET")
}
func (ap *AuthProvider) ExpandScopes(w http.ResponseWriter, r *http.Request) {
var payload tcauth.SetOfScopes
Marshal(r, &payload)
out, err := ap.auth.ExpandScopes(&payload)
JSON(w, out, err)
}
func (ap *AuthProvider) SentryDSN(w http.ResponseWriter, r *http.Request) {
vars := Vars(r)
out, err := ap.auth.SentryDSN(vars["project"])
JSON(w, out, err)
}
func (ap *AuthProvider) WebsocktunnelToken(w http.ResponseWriter, r *http.Request) {
vars := Vars(r)
out, err := ap.auth.WebsocktunnelToken(vars["wstAudience"], vars["wstClient"])
JSON(w, out, err)
}