github.com/blend/go-sdk@v1.20220411.3/vault/tracer.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package vault
     9  
    10  import (
    11  	"context"
    12  
    13  	"github.com/blend/go-sdk/ex"
    14  )
    15  
    16  const errNilConfig ex.Class = "config cannot be nil"
    17  
    18  // SecretTraceConfig are the options for sending trace messages for the secrets package
    19  type SecretTraceConfig struct {
    20  	VaultOperation string
    21  	KeyName        string
    22  }
    23  
    24  // TraceOption is an option type for secret trace
    25  type TraceOption func(config *SecretTraceConfig) error
    26  
    27  // OptTraceConfig allows you to provide the entire secret trace configuration
    28  func OptTraceConfig(providedConfig SecretTraceConfig) TraceOption {
    29  	return func(config *SecretTraceConfig) error {
    30  		*config = providedConfig
    31  		return nil
    32  	}
    33  }
    34  
    35  // OptTraceVaultOperation allows you to set the VaultOperation being hit
    36  func OptTraceVaultOperation(path string) TraceOption {
    37  	return func(config *SecretTraceConfig) error {
    38  		if config == nil {
    39  			return errNilConfig
    40  		}
    41  		config.VaultOperation = path
    42  		return nil
    43  	}
    44  }
    45  
    46  // OptTraceKeyName allows you to specify the name of the key being interacted with
    47  func OptTraceKeyName(keyName string) TraceOption {
    48  	return func(config *SecretTraceConfig) error {
    49  		if config == nil {
    50  			return errNilConfig
    51  		}
    52  		config.KeyName = keyName
    53  		return nil
    54  	}
    55  }
    56  
    57  // Tracer is a tracer for requests.
    58  type Tracer interface {
    59  	Start(ctx context.Context, options ...TraceOption) (TraceFinisher, error)
    60  }
    61  
    62  // TraceFinisher is a finisher for traces.
    63  type TraceFinisher interface {
    64  	Finish(ctx context.Context, statusCode int, vaultError error)
    65  }