github.com/opentofu/opentofu@v1.7.1/internal/encryption/keyprovider/static/config.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package static
     7  
     8  import (
     9  	"encoding/hex"
    10  
    11  	"github.com/opentofu/opentofu/internal/encryption/keyprovider"
    12  )
    13  
    14  // Config contains the configuration for this key provider supplied by the user. This struct must have hcl tags in order
    15  // to function.
    16  type Config struct {
    17  	Key string `hcl:"key"`
    18  }
    19  
    20  // Build will create the usable key provider.
    21  func (c Config) Build() (keyprovider.KeyProvider, keyprovider.KeyMeta, error) {
    22  	if c.Key == "" {
    23  		return nil, nil, &keyprovider.ErrInvalidConfiguration{
    24  			Message: "Missing key",
    25  		}
    26  	}
    27  
    28  	decodedData, err := hex.DecodeString(c.Key)
    29  	if err != nil {
    30  		return nil, nil, &keyprovider.ErrInvalidConfiguration{
    31  			Message: "failed to hex-decode the provided key",
    32  			Cause:   err,
    33  		}
    34  	}
    35  
    36  	return &staticKeyProvider{decodedData}, new(Metadata), nil
    37  }