Skip to content

Commit 0318ad6

Browse files
committed
move readonly types to services/readonly
1 parent c7cd28d commit 0318ad6

File tree

25 files changed

+404
-390
lines changed

25 files changed

+404
-390
lines changed

api/types/app.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -88,55 +88,6 @@ type Application interface {
8888
GetCORS() *CORSPolicy
8989
}
9090

91-
// ReadOnlyApplication is a read only variant of Application.
92-
type ReadOnlyApplication interface {
93-
// ReadOnlyResourceWithLabels provides common resource methods.
94-
ReadOnlyResourceWithLabels
95-
// GetNamespace returns the app namespace.
96-
GetNamespace() string
97-
// GetStaticLabels returns the app static labels.
98-
GetStaticLabels() map[string]string
99-
// GetDynamicLabels returns the app dynamic labels.
100-
GetDynamicLabels() map[string]CommandLabel
101-
// String returns string representation of the app.
102-
String() string
103-
// GetDescription returns the app description.
104-
GetDescription() string
105-
// GetURI returns the app connection endpoint.
106-
GetURI() string
107-
// GetPublicAddr returns the app public address.
108-
GetPublicAddr() string
109-
// GetInsecureSkipVerify returns the app insecure setting.
110-
GetInsecureSkipVerify() bool
111-
// GetRewrite returns the app rewrite configuration.
112-
GetRewrite() *Rewrite
113-
// IsAWSConsole returns true if this app is AWS management console.
114-
IsAWSConsole() bool
115-
// IsAzureCloud returns true if this app represents Azure Cloud instance.
116-
IsAzureCloud() bool
117-
// IsGCP returns true if this app represents GCP instance.
118-
IsGCP() bool
119-
// IsTCP returns true if this app represents a TCP endpoint.
120-
IsTCP() bool
121-
// GetProtocol returns the application protocol.
122-
GetProtocol() string
123-
// GetAWSAccountID returns value of label containing AWS account ID on this app.
124-
GetAWSAccountID() string
125-
// GetAWSExternalID returns the AWS External ID configured for this app.
126-
GetAWSExternalID() string
127-
// GetUserGroups will get the list of user group IDs associated with the application.
128-
GetUserGroups() []string
129-
// Copy returns a copy of this app resource.
130-
Copy() *AppV3
131-
// GetIntegration will return the Integration.
132-
// If present, the Application must use the Integration's credentials instead of ambient credentials to access Cloud APIs.
133-
GetIntegration() string
134-
// GetRequiredAppNames will return a list of required apps names that should be authenticated during this apps authentication process.
135-
GetRequiredAppNames() []string
136-
// GetCORS returns the CORS configuration for the app.
137-
GetCORS() *CORSPolicy
138-
}
139-
14091
// NewAppV3 creates a new app resource.
14192
func NewAppV3(meta Metadata, spec AppSpecV3) (*AppV3, error) {
14293
app := &AppV3{

api/types/database.go

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -147,94 +147,6 @@ type Database interface {
147147
IsUsernameCaseInsensitive() bool
148148
}
149149

150-
// ReadOnlyDatabase is a read only variant of Database.
151-
type ReadOnlyDatabase interface {
152-
// ReadOnlyResourceWithLabels provides common resource methods.
153-
ReadOnlyResourceWithLabels
154-
// GetNamespace returns the database namespace.
155-
GetNamespace() string
156-
// GetStaticLabels returns the database static labels.
157-
GetStaticLabels() map[string]string
158-
// GetDynamicLabels returns the database dynamic labels.
159-
GetDynamicLabels() map[string]CommandLabel
160-
// String returns string representation of the database.
161-
String() string
162-
// GetDescription returns the database description.
163-
GetDescription() string
164-
// GetProtocol returns the database protocol.
165-
GetProtocol() string
166-
// GetURI returns the database connection endpoint.
167-
GetURI() string
168-
// GetCA returns the database CA certificate.
169-
GetCA() string
170-
// GetTLS returns the database TLS configuration.
171-
GetTLS() DatabaseTLS
172-
// GetStatusCA gets the database CA certificate in the status field.
173-
GetStatusCA() string
174-
// GetMySQL returns the database options from spec.
175-
GetMySQL() MySQLOptions
176-
// GetOracle returns the database options from spec.
177-
GetOracle() OracleOptions
178-
// GetMySQLServerVersion returns the MySQL server version either from configuration or
179-
// reported by the database.
180-
GetMySQLServerVersion() string
181-
// GetAWS returns the database AWS metadata.
182-
GetAWS() AWS
183-
// GetGCP returns GCP information for Cloud SQL databases.
184-
GetGCP() GCPCloudSQL
185-
// GetAzure returns Azure database server metadata.
186-
GetAzure() Azure
187-
// GetAD returns Active Directory database configuration.
188-
GetAD() AD
189-
// GetType returns the database authentication type: self-hosted, RDS, Redshift or Cloud SQL.
190-
GetType() string
191-
// GetSecretStore returns secret store configurations.
192-
GetSecretStore() SecretStore
193-
// GetManagedUsers returns a list of database users that are managed by Teleport.
194-
GetManagedUsers() []string
195-
// GetMongoAtlas returns Mongo Atlas database metadata.
196-
GetMongoAtlas() MongoAtlas
197-
// IsRDS returns true if this is an RDS/Aurora database.
198-
IsRDS() bool
199-
// IsRDSProxy returns true if this is an RDS Proxy database.
200-
IsRDSProxy() bool
201-
// IsRedshift returns true if this is a Redshift database.
202-
IsRedshift() bool
203-
// IsCloudSQL returns true if this is a Cloud SQL database.
204-
IsCloudSQL() bool
205-
// IsAzure returns true if this is an Azure database.
206-
IsAzure() bool
207-
// IsElastiCache returns true if this is an AWS ElastiCache database.
208-
IsElastiCache() bool
209-
// IsMemoryDB returns true if this is an AWS MemoryDB database.
210-
IsMemoryDB() bool
211-
// IsAWSHosted returns true if database is hosted by AWS.
212-
IsAWSHosted() bool
213-
// IsCloudHosted returns true if database is hosted in the cloud (AWS, Azure or Cloud SQL).
214-
IsCloudHosted() bool
215-
// RequireAWSIAMRolesAsUsers returns true for database types that require
216-
// AWS IAM roles as database users.
217-
RequireAWSIAMRolesAsUsers() bool
218-
// SupportAWSIAMRoleARNAsUsers returns true for database types that support
219-
// AWS IAM roles as database users.
220-
SupportAWSIAMRoleARNAsUsers() bool
221-
// Copy returns a copy of this database resource.
222-
Copy() *DatabaseV3
223-
// GetAdminUser returns database privileged user information.
224-
GetAdminUser() DatabaseAdminUser
225-
// SupportsAutoUsers returns true if this database supports automatic
226-
// user provisioning.
227-
SupportsAutoUsers() bool
228-
// GetEndpointType returns the endpoint type of the database, if available.
229-
GetEndpointType() string
230-
// GetCloud gets the cloud this database is running on, or an empty string if it
231-
// isn't running on a cloud provider.
232-
GetCloud() string
233-
// IsUsernameCaseInsensitive returns true if the database username is case
234-
// insensitive.
235-
IsUsernameCaseInsensitive() bool
236-
}
237-
238150
// NewDatabaseV3 creates a new database resource.
239151
func NewDatabaseV3(meta Metadata, spec DatabaseSpecV3) (*DatabaseV3, error) {
240152
database := &DatabaseV3{

api/types/kubernetes.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -80,43 +80,6 @@ type KubeCluster interface {
8080
GetCloud() string
8181
}
8282

83-
// ReadOnlyKubeCluster is a read only variant of KubeCluster.
84-
type ReadOnlyKubeCluster interface {
85-
// ReadOnlyResourceWithLabels provides common resource methods.
86-
ReadOnlyResourceWithLabels
87-
// GetNamespace returns the kube cluster namespace.
88-
GetNamespace() string
89-
// GetStaticLabels returns the kube cluster static labels.
90-
GetStaticLabels() map[string]string
91-
// GetDynamicLabels returns the kube cluster dynamic labels.
92-
GetDynamicLabels() map[string]CommandLabel
93-
// GetKubeconfig returns the kubeconfig payload.
94-
GetKubeconfig() []byte
95-
// String returns string representation of the kube cluster.
96-
String() string
97-
// GetDescription returns the kube cluster description.
98-
GetDescription() string
99-
// GetAzureConfig gets the Azure config.
100-
GetAzureConfig() KubeAzure
101-
// GetAWSConfig gets the AWS config.
102-
GetAWSConfig() KubeAWS
103-
// GetGCPConfig gets the GCP config.
104-
GetGCPConfig() KubeGCP
105-
// IsAzure indentifies if the KubeCluster contains Azure details.
106-
IsAzure() bool
107-
// IsAWS indentifies if the KubeCluster contains AWS details.
108-
IsAWS() bool
109-
// IsGCP indentifies if the KubeCluster contains GCP details.
110-
IsGCP() bool
111-
// IsKubeconfig identifies if the KubeCluster contains kubeconfig data.
112-
IsKubeconfig() bool
113-
// Copy returns a copy of this kube cluster resource.
114-
Copy() *KubernetesClusterV3
115-
// GetCloud gets the cloud this kube cluster is running on, or an empty string if it
116-
// isn't running on a cloud provider.
117-
GetCloud() string
118-
}
119-
12083
// DiscoveredEKSCluster represents a server discovered by EKS discovery fetchers.
12184
type DiscoveredEKSCluster interface {
12285
// KubeCluster is base discovered cluster.

api/types/kubernetes_server.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,6 @@ type KubeServer interface {
6060
ProxiedService
6161
}
6262

63-
// ReadOnlyKubeServer is a read only variant of KubeServer.
64-
type ReadOnlyKubeServer interface {
65-
// ReadOnlyResourceWithLabels provides common resource methods.
66-
ReadOnlyResourceWithLabels
67-
// GetNamespace returns server namespace.
68-
GetNamespace() string
69-
// GetTeleportVersion returns the teleport version the server is running on.
70-
GetTeleportVersion() string
71-
// GetHostname returns the server hostname.
72-
GetHostname() string
73-
// GetHostID returns ID of the host the server is running on.
74-
GetHostID() string
75-
// GetRotation gets the state of certificate authority rotation.
76-
GetRotation() Rotation
77-
// String returns string representation of the server.
78-
String() string
79-
// Copy returns a copy of this kube server object.
80-
Copy() KubeServer
81-
// CloneResource returns a copy of the KubeServer as a ResourceWithLabels
82-
CloneResource() ResourceWithLabels
83-
// GetCluster returns the Kubernetes Cluster this kube server proxies.
84-
GetCluster() KubeCluster
85-
// GetProxyIDs returns a list of proxy ids this service is connected to.
86-
GetProxyIDs() []string
87-
}
88-
8963
// NewKubernetesServerV3 creates a new kube server instance.
9064
func NewKubernetesServerV3(meta Metadata, spec KubernetesServerSpecV3) (*KubernetesServerV3, error) {
9165
s := &KubernetesServerV3{

api/types/resource.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,6 @@ type Resource interface {
6666
SetRevision(string)
6767
}
6868

69-
// ReadOnlyResource is a read only variant of Resource.
70-
type ReadOnlyResource interface {
71-
// GetKind returns resource kind
72-
GetKind() string
73-
// GetSubKind returns resource subkind
74-
GetSubKind() string
75-
// GetVersion returns resource version
76-
GetVersion() string
77-
// GetName returns the name of the resource
78-
GetName() string
79-
// Expiry returns object expiry setting
80-
Expiry() time.Time
81-
// GetMetadata returns object metadata
82-
GetMetadata() Metadata
83-
// GetRevision returns the revision
84-
GetRevision() string
85-
}
86-
8769
// IsSystemResource checks to see if the given resource is considered
8870
// part of the teleport system, as opposed to some user created resource
8971
// or preset.
@@ -127,13 +109,6 @@ type ResourceWithOrigin interface {
127109
SetOrigin(string)
128110
}
129111

130-
// ReadOnlyResourceWithOrigin is a read only variant of ResourceWithOrigin.
131-
type ReadOnlyResourceWithOrigin interface {
132-
ReadOnlyResource
133-
// Origin returns the origin value of the resource.
134-
Origin() string
135-
}
136-
137112
// ResourceWithLabels is a common interface for resources that have labels.
138113
type ResourceWithLabels interface {
139114
// ResourceWithOrigin is the base resource interface.
@@ -151,20 +126,6 @@ type ResourceWithLabels interface {
151126
MatchSearch(searchValues []string) bool
152127
}
153128

154-
// ReadOnlyResourceWithLabels is a read only variant of ResourceWithLabels.
155-
type ReadOnlyResourceWithLabels interface {
156-
ReadOnlyResourceWithOrigin
157-
// GetLabel retrieves the label with the provided key.
158-
GetLabel(key string) (value string, ok bool)
159-
// GetAllLabels returns all resource's labels.
160-
GetAllLabels() map[string]string
161-
// GetStaticLabels returns the resource's static labels.
162-
GetStaticLabels() map[string]string
163-
// MatchSearch goes through select field values of a resource
164-
// and tries to match against the list of search values.
165-
MatchSearch(searchValues []string) bool
166-
}
167-
168129
// EnrichedResource is a [ResourceWithLabels] wrapped with
169130
// additional user-specific information.
170131
type EnrichedResource struct {

api/types/server.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -103,62 +103,6 @@ type Server interface {
103103
GetAWSAccountID() string
104104
}
105105

106-
// ReadOnlyServer is a read only variant of Server.
107-
type ReadOnlyServer interface {
108-
// ReadOnlyResourceWithLabels provides common resource headers
109-
ReadOnlyResourceWithLabels
110-
// GetTeleportVersion returns the teleport version the server is running on
111-
GetTeleportVersion() string
112-
// GetAddr return server address
113-
GetAddr() string
114-
// GetHostname returns server hostname
115-
GetHostname() string
116-
// GetNamespace returns server namespace
117-
GetNamespace() string
118-
// GetLabels returns server's static label key pairs
119-
GetLabels() map[string]string
120-
// GetCmdLabels gets command labels
121-
GetCmdLabels() map[string]CommandLabel
122-
// GetPublicAddr returns a public address where this server can be reached.
123-
GetPublicAddr() string
124-
// GetPublicAddrs returns a list of public addresses where this server can be reached.
125-
GetPublicAddrs() []string
126-
// GetRotation gets the state of certificate authority rotation.
127-
GetRotation() Rotation
128-
// GetUseTunnel gets if a reverse tunnel should be used to connect to this node.
129-
GetUseTunnel() bool
130-
// String returns string representation of the server
131-
String() string
132-
// GetPeerAddr returns the peer address of the server.
133-
GetPeerAddr() string
134-
// GetProxyIDs returns a list of proxy ids this service is connected to.
135-
GetProxyIDs() []string
136-
// DeepCopy creates a clone of this server value
137-
DeepCopy() Server
138-
139-
// CloneResource is used to return a clone of the Server and match the CloneAny interface
140-
// This is helpful when interfacing with multiple types at the same time in unified resources
141-
CloneResource() ResourceWithLabels
142-
143-
// GetCloudMetadata gets the cloud metadata for the server.
144-
GetCloudMetadata() *CloudMetadata
145-
// GetAWSInfo returns the AWSInfo for the server.
146-
GetAWSInfo() *AWSInfo
147-
148-
// IsOpenSSHNode returns whether the connection to this Server must use OpenSSH.
149-
// This returns true for SubKindOpenSSHNode and SubKindOpenSSHEICENode.
150-
IsOpenSSHNode() bool
151-
152-
// IsEICE returns whether the Node is an EICE instance.
153-
// Must be `openssh-ec2-ice` subkind and have the AccountID and InstanceID information (AWS Metadata or Labels).
154-
IsEICE() bool
155-
156-
// GetAWSInstanceID returns the AWS Instance ID if this node comes from an EC2 instance.
157-
GetAWSInstanceID() string
158-
// GetAWSAccountID returns the AWS Account ID if this node comes from an EC2 instance.
159-
GetAWSAccountID() string
160-
}
161-
162106
// NewServer creates an instance of Server.
163107
func NewServer(name, kind string, spec ServerSpecV2) (Server, error) {
164108
return NewServerWithLabels(name, kind, spec, map[string]string{})

lib/kube/proxy/server.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import (
4545
"github.com/gravitational/teleport/lib/multiplexer"
4646
"github.com/gravitational/teleport/lib/reversetunnel"
4747
"github.com/gravitational/teleport/lib/services"
48+
"github.com/gravitational/teleport/lib/services/readonly"
4849
"github.com/gravitational/teleport/lib/srv"
4950
"github.com/gravitational/teleport/lib/srv/ingress"
5051
)
@@ -98,7 +99,7 @@ type TLSServerConfig struct {
9899
// kubernetes cluster name. Proxy uses this map to route requests to the correct
99100
// kubernetes_service. The servers are kept in memory to avoid making unnecessary
100101
// unmarshal calls followed by filtering and to improve memory usage.
101-
KubernetesServersWatcher *services.GenericWatcher[types.KubeServer, types.ReadOnlyKubeServer]
102+
KubernetesServersWatcher *services.GenericWatcher[types.KubeServer, readonly.KubeServer]
102103
// PROXYProtocolMode controls behavior related to unsigned PROXY protocol headers.
103104
PROXYProtocolMode multiplexer.PROXYProtocolMode
104105
// InventoryHandle is used to send kube server heartbeats via the inventory control stream.
@@ -170,7 +171,7 @@ type TLSServer struct {
170171
closeContext context.Context
171172
closeFunc context.CancelFunc
172173
// kubeClusterWatcher monitors changes to kube cluster resources.
173-
kubeClusterWatcher *services.GenericWatcher[types.KubeCluster, types.ReadOnlyKubeCluster]
174+
kubeClusterWatcher *services.GenericWatcher[types.KubeCluster, readonly.KubeCluster]
174175
// reconciler reconciles proxied kube clusters with kube_clusters resources.
175176
reconciler *services.Reconciler[types.KubeCluster]
176177
// monitoredKubeClusters contains all kube clusters the proxied kube_clusters are
@@ -620,7 +621,7 @@ func (t *TLSServer) getKubernetesServersForKubeClusterFunc() (getKubeServersByNa
620621
}, nil
621622
case ProxyService:
622623
return func(ctx context.Context, name string) ([]types.KubeServer, error) {
623-
servers, err := t.KubernetesServersWatcher.CurrentResourcesWithFilter(ctx, func(ks types.ReadOnlyKubeServer) bool {
624+
servers, err := t.KubernetesServersWatcher.CurrentResourcesWithFilter(ctx, func(ks readonly.KubeServer) bool {
624625
return ks.GetCluster().GetName() == name
625626
})
626627
return servers, trace.Wrap(err)
@@ -632,7 +633,7 @@ func (t *TLSServer) getKubernetesServersForKubeClusterFunc() (getKubeServersByNa
632633
// and forward the request to the next proxy.
633634
kube, err := t.getKubeClusterWithServiceLabels(name)
634635
if err != nil {
635-
servers, err := t.KubernetesServersWatcher.CurrentResourcesWithFilter(ctx, func(ks types.ReadOnlyKubeServer) bool {
636+
servers, err := t.KubernetesServersWatcher.CurrentResourcesWithFilter(ctx, func(ks readonly.KubeServer) bool {
636637
return ks.GetCluster().GetName() == name
637638
})
638639
return servers, trace.Wrap(err)

0 commit comments

Comments
 (0)