-
Notifications
You must be signed in to change notification settings - Fork 307
/
auth.go
51 lines (45 loc) · 1.43 KB
/
auth.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
package controlplane
import (
"context"
proto "github.com/rudderlabs/rudder-server/proto/common"
)
type AuthInfo struct {
Service string
ConnectionToken string
InstanceID string
TokenType string
Labels map[string]string
}
type authService struct {
authInfo AuthInfo
proto.UnimplementedDPAuthServiceServer
}
func (a *authService) GetConnectionToken(_ context.Context, _ *proto.GetConnectionTokenRequest) (*proto.GetConnectionTokenResponse, error) {
if a.authInfo.ConnectionToken == "" {
return &proto.GetConnectionTokenResponse{
Response: &proto.GetConnectionTokenResponse_ErrorResponse{
ErrorResponse: &proto.ErrorResponse{
Error: "connection token is empty",
},
},
}, nil
}
return &proto.GetConnectionTokenResponse{
Response: &proto.GetConnectionTokenResponse_SuccessResponse{
SuccessResponse: &proto.GetConnectionTokenSuccessResponse{
ConnectionToken: a.authInfo.ConnectionToken,
Service: a.authInfo.Service,
InstanceID: a.authInfo.InstanceID,
TokenType: a.authInfo.TokenType,
Labels: a.authInfo.Labels,
},
},
}, nil
}
func (a *authService) GetWorkspaceToken(_ context.Context, _ *proto.GetWorkspaceTokenRequest) (*proto.GetWorkspaceTokenResponse, error) {
return &proto.GetWorkspaceTokenResponse{
WorkspaceToken: a.authInfo.ConnectionToken,
Service: a.authInfo.Service,
InstanceID: a.authInfo.InstanceID,
}, nil
}