-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
41 lines (34 loc) · 1.06 KB
/
client.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
package teleport
import (
"context"
tc "github.com/gravitational/teleport/api/client"
"github.com/gravitational/teleport/api/client/proto"
"github.com/gravitational/teleport/api/types"
"github.com/giantswarm/microerror"
)
type Client interface {
Ping(ctx context.Context) (proto.PingResponse, error)
GetToken(ctx context.Context, name string) (types.ProvisionToken, error)
GetTokens(ctx context.Context) ([]types.ProvisionToken, error)
CreateToken(ctx context.Context, token types.ProvisionToken) error
UpsertToken(ctx context.Context, token types.ProvisionToken) error
DeleteToken(ctx context.Context, name string) error
}
var NewClient = func(ctx context.Context, proxyAddr, identityFile string) (Client, error) {
teleportClient, err := tc.New(ctx, tc.Config{
Addrs: []string{
proxyAddr,
},
Credentials: []tc.Credentials{
tc.LoadIdentityFileFromString(identityFile),
},
})
if err != nil {
return nil, microerror.Mask(err)
}
_, err = teleportClient.Ping(ctx)
if err != nil {
return nil, microerror.Mask(err)
}
return teleportClient, nil
}