1// Copyright 2022 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14// 15//////////////////////////////////////////////////////////////////////////////// 16 17package keyset 18 19import "fmt" 20 21// Option is used to pass options for a keyset handle. 22type Option interface { 23 set(k *Handle) error 24} 25 26type option func(*Handle) error 27 28func (o option) set(h *Handle) error { return o(h) } 29 30// WithAnnotations adds monitoring annotations to a keyset handle. 31func WithAnnotations(annotations map[string]string) Option { 32 return option(func(h *Handle) error { 33 if h.annotations != nil { 34 return fmt.Errorf("keyset already contains annotations") 35 } 36 h.annotations = annotations 37 return nil 38 }) 39} 40 41func applyOptions(h *Handle, opts ...Option) error { 42 for _, opt := range opts { 43 if err := opt.set(h); err != nil { 44 return err 45 } 46 } 47 return nil 48} 49