Files
opentf/internal/encryption/keyprovider/output.go
AbstractionFactory 5a6d2d3e98 Fixes #2022: Running external commands as a key provider (#2023)
Signed-off-by: AbstractionFactory <179820029+abstractionfactory@users.noreply.github.com>
Signed-off-by: ollevche <ollevche@gmail.com>
Co-authored-by: Oleksandr Levchenkov <ollevche@gmail.com>
2025-01-08 12:08:30 -05:00

36 lines
1.2 KiB
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package keyprovider
import "github.com/zclconf/go-cty/cty"
// Output is the standardized structure a key provider must return when providing a key.
// It contains two keys because some key providers may prefer include random data (e.g. salt)
// in the generated keys and this salt will be different for decryption and encryption.
type Output struct {
EncryptionKey []byte `hcl:"encryption_key" cty:"encryption_key" json:"encryption_key,omitempty" yaml:"encryption_key"`
DecryptionKey []byte `hcl:"decryption_key,optional" cty:"decryption_key" json:"decryption_key,omitempty" yaml:"decryption_key"`
}
// Cty turns the Output struct into a CTY value.
func (o *Output) Cty() cty.Value {
return cty.ObjectVal(map[string]cty.Value{
"encryption_key": o.byteToCty(o.EncryptionKey),
"decryption_key": o.byteToCty(o.DecryptionKey),
})
}
func (o *Output) byteToCty(data []byte) cty.Value {
if len(data) == 0 {
return cty.NullVal(cty.List(cty.Number))
}
ctyData := make([]cty.Value, len(data))
for i, d := range data {
ctyData[i] = cty.NumberIntVal(int64(d))
}
return cty.ListVal(ctyData)
}