github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/client/proto/types.go (about) 1 /* 2 Copyright 2021 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 proto provides the protobuf API specification for Teleport. 18 package proto 19 20 import ( 21 "time" 22 23 "github.com/gravitational/trace" 24 25 apidefaults "github.com/gravitational/teleport/api/defaults" 26 "github.com/gravitational/teleport/api/types" 27 ) 28 29 // Duration is a wrapper around duration 30 type Duration time.Duration 31 32 // Get returns time.Duration value 33 func (d Duration) Get() time.Duration { 34 return time.Duration(d) 35 } 36 37 // Set sets time.Duration value 38 func (d *Duration) Set(value time.Duration) { 39 *d = Duration(value) 40 } 41 42 // CheckAndSetDefaults checks and sets default values 43 func (req *HostCertsRequest) CheckAndSetDefaults() error { 44 if req.HostID == "" { 45 return trace.BadParameter("missing parameter HostID") 46 } 47 48 return req.Role.Check() 49 } 50 51 // CheckAndSetDefaults checks and sets default values. 52 func (req *ListResourcesRequest) CheckAndSetDefaults() error { 53 if req.Namespace == "" { 54 req.Namespace = apidefaults.Namespace 55 } 56 // If the Limit parameter was not provided instead of returning an error fallback to the default limit. 57 if req.Limit == 0 { 58 req.Limit = apidefaults.DefaultChunkSize 59 } 60 61 if req.Limit < 0 { 62 return trace.BadParameter("negative parameter limit") 63 } 64 65 return nil 66 } 67 68 // CheckAndSetDefaults checks and sets default values. 69 func (req *ListUnifiedResourcesRequest) CheckAndSetDefaults() error { 70 // If the Limit parameter was not provided instead of returning an error fallback to the default limit. 71 if req.Limit == 0 { 72 req.Limit = apidefaults.DefaultChunkSize 73 } 74 75 if req.Limit < 0 { 76 return trace.BadParameter("negative parameter: limit") 77 } 78 79 return nil 80 } 81 82 // RequiresFakePagination checks if we need to fallback to GetXXX calls 83 // that retrieves entire resources upfront rather than working with subsets. 84 func (req *ListResourcesRequest) RequiresFakePagination() bool { 85 return req.SortBy.Field != "" || 86 req.NeedTotalCount || 87 req.ResourceType == types.KindKubernetesCluster || 88 req.ResourceType == types.KindAppOrSAMLIdPServiceProvider 89 } 90 91 // UpstreamInventoryMessage is a sealed interface representing the possible 92 // upstream messages of the inventory control stream after the initial hello. 93 type UpstreamInventoryMessage interface { 94 sealedUpstreamInventoryMessage() 95 } 96 97 func (h UpstreamInventoryHello) sealedUpstreamInventoryMessage() {} 98 99 func (h InventoryHeartbeat) sealedUpstreamInventoryMessage() {} 100 101 func (p UpstreamInventoryPong) sealedUpstreamInventoryMessage() {} 102 103 func (a UpstreamInventoryAgentMetadata) sealedUpstreamInventoryMessage() {} 104 105 // DownstreamInventoryMessage is a sealed interface representing the possible 106 // downstream messages of the inventory controls stream after initial hello. 107 type DownstreamInventoryMessage interface { 108 sealedDownstreamInventoryMessage() 109 } 110 111 func (h DownstreamInventoryHello) sealedDownstreamInventoryMessage() {} 112 113 func (p DownstreamInventoryPing) sealedDownstreamInventoryMessage() {} 114 115 func (u DownstreamInventoryUpdateLabels) sealedDownstreamInventoryMessage() {}