github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/types/watch_status.go (about)

     1  /*
     2   * Copyright 2023 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/teleport/api/defaults"
    23  	"github.com/gravitational/teleport/api/utils"
    24  )
    25  
    26  // WatchStatus contains information about a successful Watch request.
    27  type WatchStatus interface {
    28  	Resource
    29  	// GetKinds returns the list of kinds confirmed by the Watch request.
    30  	GetKinds() []WatchKind
    31  	// SetKinds sets the list of kinds confirmed by the Watch request.
    32  	SetKinds([]WatchKind)
    33  	// Clone performs a deep copy of watch status.
    34  	Clone() WatchStatus
    35  }
    36  
    37  // GetKind returns the watch status resource kind.
    38  func (w *WatchStatusV1) GetKind() string {
    39  	return w.Kind
    40  }
    41  
    42  // GetSubKind returns the watch status resource subkind.
    43  func (w *WatchStatusV1) GetSubKind() string {
    44  	return w.SubKind
    45  }
    46  
    47  // SetSubKind sets the watch status resource subkind.
    48  func (w *WatchStatusV1) SetSubKind(k string) {
    49  	w.SubKind = k
    50  }
    51  
    52  // GetVersion returns the watch status resource version.
    53  func (w *WatchStatusV1) GetVersion() string {
    54  	return w.Version
    55  }
    56  
    57  // GetName returns the watch status resource name.
    58  func (w *WatchStatusV1) GetName() string {
    59  	return w.Metadata.Name
    60  }
    61  
    62  // SetName sets the watch status resource name.
    63  func (w *WatchStatusV1) SetName(name string) {
    64  	w.Metadata.Name = name
    65  }
    66  
    67  // Expiry returns the watch status resource expiration time.
    68  func (w *WatchStatusV1) Expiry() time.Time {
    69  	return w.Metadata.Expiry()
    70  }
    71  
    72  // SetExpiry sets the watch status resource expiration time.
    73  func (w *WatchStatusV1) SetExpiry(time time.Time) {
    74  	w.Metadata.SetExpiry(time)
    75  }
    76  
    77  // GetMetadata returns the watch status resource metadata.
    78  func (w *WatchStatusV1) GetMetadata() Metadata {
    79  	return w.Metadata
    80  }
    81  
    82  // GetResourceID returns the watch status resource ID.
    83  func (w *WatchStatusV1) GetResourceID() int64 {
    84  	return w.Metadata.ID
    85  }
    86  
    87  // SetResourceID sets the watch status resource ID.
    88  func (w *WatchStatusV1) SetResourceID(id int64) {
    89  	w.Metadata.ID = id
    90  }
    91  
    92  // GetRevision returns the revision
    93  func (w *WatchStatusV1) GetRevision() string {
    94  	return w.Metadata.GetRevision()
    95  }
    96  
    97  // SetRevision sets the revision
    98  func (w *WatchStatusV1) SetRevision(rev string) {
    99  	w.Metadata.SetRevision(rev)
   100  }
   101  
   102  // CheckAndSetDefaults checks and sets default values for any missing fields.
   103  func (w *WatchStatusV1) CheckAndSetDefaults() error {
   104  	return nil
   105  }
   106  
   107  // GetKinds returns the list of kinds confirmed by the Watch request.
   108  func (w *WatchStatusV1) GetKinds() []WatchKind {
   109  	return w.Spec.Kinds
   110  }
   111  
   112  // SetKinds sets the list of kinds confirmed by the Watch request.
   113  func (w *WatchStatusV1) SetKinds(kinds []WatchKind) {
   114  	w.Spec.Kinds = kinds
   115  }
   116  
   117  // Clone performs a deep-copy of watch status.
   118  func (w *WatchStatusV1) Clone() WatchStatus {
   119  	return utils.CloneProtoMsg(w)
   120  }
   121  
   122  // NewWatchStatus returns a new WatchStatus resource.
   123  func NewWatchStatus(kinds []WatchKind) *WatchStatusV1 {
   124  	return &WatchStatusV1{
   125  		Kind:    KindWatchStatus,
   126  		Version: V1,
   127  		Metadata: Metadata{
   128  			Name:      MetaNameWatchStatus,
   129  			Namespace: defaults.Namespace,
   130  		},
   131  		Spec: WatchStatusSpecV1{
   132  			Kinds: kinds,
   133  		},
   134  	}
   135  }