forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
144 lines (119 loc) · 4.64 KB
/
config.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Teleport
* Copyright (C) 2023 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package daemon
import (
"context"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"github.com/gravitational/teleport/lib/client"
"github.com/gravitational/teleport/lib/teleterm/api/uri"
"github.com/gravitational/teleport/lib/teleterm/clusters"
"github.com/gravitational/teleport/lib/teleterm/services/connectmycomputer"
)
// Storage defines an interface for cluster profile storage.
type Storage interface {
clusters.Resolver
ReadAll() ([]*clusters.Cluster, error)
Add(ctx context.Context, webProxyAddress string) (*clusters.Cluster, *client.TeleportClient, error)
Remove(ctx context.Context, profileName string) error
GetByResourceURI(resourceURI uri.ResourceURI) (*clusters.Cluster, *client.TeleportClient, error)
}
// Config is the cluster service config
type Config struct {
// Clock is a clock for time-related operations
Clock clockwork.Clock
// Storage is a storage service that reads/writes to tsh profiles
Storage Storage
// Log is a component logger
Log *logrus.Entry
// PrehogAddr is the URL where prehog events should be submitted.
PrehogAddr string
// KubeconfigsDir is the directory containing kubeconfigs for Kubernetes
// Acesss.
KubeconfigsDir string
// AgentsDir contains agent config files and data directories for Connect My Computer.
AgentsDir string
GatewayCreator GatewayCreator
// CreateTshdEventsClientCredsFunc lazily creates creds for the tshd events server ran by the
// Electron app. This is to ensure that the server public key is written to the disk under the
// expected location by the time we get around to creating the client.
CreateTshdEventsClientCredsFunc CreateTshdEventsClientCredsFunc
ConnectMyComputerRoleSetup *connectmycomputer.RoleSetup
ConnectMyComputerTokenProvisioner *connectmycomputer.TokenProvisioner
ConnectMyComputerNodeJoinWait *connectmycomputer.NodeJoinWait
ConnectMyComputerNodeDelete *connectmycomputer.NodeDelete
ConnectMyComputerNodeName *connectmycomputer.NodeName
}
type CreateTshdEventsClientCredsFunc func() (grpc.DialOption, error)
// CheckAndSetDefaults checks the configuration for its validity and sets default values if needed
func (c *Config) CheckAndSetDefaults() error {
if c.Clock == nil {
c.Clock = clockwork.NewRealClock()
}
if c.Storage == nil {
return trace.BadParameter("missing cluster storage")
}
if c.KubeconfigsDir == "" {
return trace.BadParameter("missing kubeconfigs directory")
}
if c.AgentsDir == "" {
return trace.BadParameter("missing agents directory")
}
if c.GatewayCreator == nil {
c.GatewayCreator = clusters.NewGatewayCreator(c.Storage)
}
if c.Log == nil {
c.Log = logrus.NewEntry(logrus.StandardLogger()).WithField(trace.Component, "daemon")
}
if c.ConnectMyComputerRoleSetup == nil {
roleSetup, err := connectmycomputer.NewRoleSetup(&connectmycomputer.RoleSetupConfig{})
if err != nil {
return trace.Wrap(err)
}
c.ConnectMyComputerRoleSetup = roleSetup
}
if c.ConnectMyComputerTokenProvisioner == nil {
c.ConnectMyComputerTokenProvisioner = connectmycomputer.NewTokenProvisioner(&connectmycomputer.TokenProvisionerConfig{Clock: c.Clock})
}
if c.ConnectMyComputerNodeJoinWait == nil {
nodeJoinWait, err := connectmycomputer.NewNodeJoinWait(&connectmycomputer.NodeJoinWaitConfig{
AgentsDir: c.AgentsDir,
})
if err != nil {
return trace.Wrap(err)
}
c.ConnectMyComputerNodeJoinWait = nodeJoinWait
}
if c.ConnectMyComputerNodeDelete == nil {
nodeDelete, err := connectmycomputer.NewNodeDelete(&connectmycomputer.NodeDeleteConfig{AgentsDir: c.AgentsDir})
if err != nil {
return trace.Wrap(err)
}
c.ConnectMyComputerNodeDelete = nodeDelete
}
if c.ConnectMyComputerNodeName == nil {
nodeName, err := connectmycomputer.NewNodeName(&connectmycomputer.NodeNameConfig{AgentsDir: c.AgentsDir})
if err != nil {
return trace.Wrap(err)
}
c.ConnectMyComputerNodeName = nodeName
}
return nil
}