forked from gravitational/teleport
/
interfaces.go
103 lines (89 loc) · 2.89 KB
/
interfaces.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
/*
* 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 gateway
import (
"github.com/gravitational/trace"
"github.com/sirupsen/logrus"
"github.com/gravitational/teleport/lib/teleterm/api/uri"
"github.com/gravitational/teleport/lib/tlsca"
)
// Gateway is a interface defines all gateway functions.
type Gateway interface {
// Serve starts the underlying ALPN proxy. Blocks until closeContext is
// canceled.
Serve() error
// Close terminates gateway connection.
Close() error
// ReloadCert loads the key pair from cfg.CertPath & cfg.KeyPath and
// updates the cert of the running local proxy.
ReloadCert() error
URI() uri.ResourceURI
TargetURI() uri.ResourceURI
TargetName() string
Protocol() string
TargetUser() string
TargetSubresourceName() string
SetTargetSubresourceName(value string)
Log() *logrus.Entry
LocalAddress() string
LocalPort() string
LocalPortInt() int
}
// AsDatabase converts provided gateway to a database gateway.
func AsDatabase(g Gateway) (Database, error) {
if db, ok := g.(Database); ok {
return db, nil
}
return nil, trace.BadParameter("expecting database gateway but got %T", g)
}
// AsKube converts provided gateway to a kube gateway.
func AsKube(g Gateway) (Kube, error) {
if kube, ok := g.(Kube); ok {
return kube, nil
}
return nil, trace.BadParameter("expecting kube gateway but got %T", g)
}
// AsApp converts provided gateway to a kube gateway.
func AsApp(g Gateway) (App, error) {
if app, ok := g.(App); ok {
return app, nil
}
return nil, trace.BadParameter("expecting app gateway but got %T", g)
}
// Database defines a database gateway.
type Database interface {
Gateway
// RouteToDatabase returns tlsca.RouteToDatabase based on the config of the gateway.
//
// The tlsca.RouteToDatabase.Database field is skipped, as it's an optional field and gateways can
// change their Config.TargetSubresourceName at any moment.
RouteToDatabase() tlsca.RouteToDatabase
}
// Kube defines a kube gateway.
type Kube interface {
Gateway
// KubeconfigPath returns the path to the kubeconfig used to connect the
// local proxy.
KubeconfigPath() string
}
// App defines an app gateway.
type App interface {
Gateway
// LocalProxyURL returns the URL of the local proxy.
LocalProxyURL() string
}