github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/types/presence.go (about) 1 /* 2 Copyright 2020 Gravitational, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package types 18 19 import ( 20 "time" 21 22 "github.com/gravitational/trace" 23 24 "github.com/gravitational/teleport/api/constants" 25 "github.com/gravitational/teleport/api/defaults" 26 ) 27 28 // Site represents a cluster of teleport nodes who collectively trust the same 29 // certificate authority (CA) and have a common name. 30 // 31 // The CA is represented by an auth server (or multiple auth servers, if running 32 // in HA mode) 33 type Site struct { 34 Name string `json:"name"` 35 LastConnected time.Time `json:"lastconnected"` 36 Status string `json:"status"` 37 } 38 39 // IsEmpty returns true if keepalive is empty, 40 // used to indicate that keepalive is not supported 41 func (s *KeepAlive) IsEmpty() bool { 42 return s.Name == "" 43 } 44 45 // GetType return the type of keep alive: either application or server. 46 func (s *KeepAlive) GetType() string { 47 switch s.Type { 48 case KeepAlive_NODE: 49 return constants.KeepAliveNode 50 case KeepAlive_APP: 51 return constants.KeepAliveApp 52 case KeepAlive_DATABASE: 53 return constants.KeepAliveDatabase 54 case KeepAlive_WINDOWS_DESKTOP: 55 return constants.KeepAliveWindowsDesktopService 56 case KeepAlive_KUBERNETES: 57 return constants.KeepAliveKube 58 case KeepAlive_DATABASE_SERVICE: 59 return constants.KeepAliveDatabaseService 60 default: 61 return constants.KeepAliveNode 62 } 63 } 64 65 // CheckAndSetDefaults validates this KeepAlive value and sets default values 66 func (s *KeepAlive) CheckAndSetDefaults() error { 67 if s.IsEmpty() { 68 return trace.BadParameter("missing resource name") 69 } 70 if s.Namespace == "" { 71 s.Namespace = defaults.Namespace 72 } 73 74 return nil 75 } 76 77 // KeepAliver keeps object alive 78 type KeepAliver interface { 79 // KeepAlives allows to receive keep alives 80 KeepAlives() chan<- KeepAlive 81 82 // Done returns the channel signaling the closure 83 Done() <-chan struct{} 84 85 // Close closes the watcher and releases 86 // all associated resources 87 Close() error 88 89 // Error returns error associated with keep aliver if any 90 Error() error 91 }