Documentation
¶
Overview ¶
Package keyscmd provides a set of utilities for reading and writing multiple keys stored in a single item in a file system using the format used by keys.InMemoryKeyStore.
Index ¶
- Variables
- func CopyContents(ctx context.Context, srcFS file.ReadFileFS, src string, dstFS file.WriteFileFS, ...) error
- func ExtensionSpec(name string) string
- func IsDstSafe(dst string) error
- func IsStdoutStdin(name string) bool
- func NewKeyInfoExtension(name string, appendFn func(cmd *subcmd.CommandSetYAML) error) subcmd.Extension
- func ReadFSWithStdin(fs file.ReadFileFS, name string) file.ReadFileFS
- func ReadFromLocal(ctx context.Context, filename string, dstFS file.WriteFileFS, dst string, ...) error
- func ReadKeyInfoFromLocal(ctx context.Context, filename string, unmarshal func([]byte, any) error) (keys.Info, error)
- func ReadKeyInfoFromLocalJSON(ctx context.Context, filename string) (keys.Info, error)
- func ReadKeyInfoFromLocalYAML(ctx context.Context, filename string) (keys.Info, error)
- func ReadWriteFSWithStdout(fs file.ReadWriteFileFS, name string) file.ReadWriteFileFS
- func SafeWriteKeyInfoJSON(ctx context.Context, ki keys.Info, dst string, perm fs.FileMode) error
- func SafeWriteKeyInfoToLocal(ctx context.Context, ki keys.Info, marshal func(any) ([]byte, error), ...) error
- func SafeWriteKeyInfoYAML(ctx context.Context, ki keys.Info, dst string, perm fs.FileMode) error
- func SafeWriteToLocal(ctx context.Context, srcFS file.ReadFileFS, src string, filename string, ...) error
- func WriteFSWithStdout(fs file.WriteFileFS, name string) file.WriteFileFS
- type KeyReader
- type KeySpecFlags
- type KeyWriter
- type SecretConfig
- type SecretConfigFlags
- type SecretFormat
Constants ¶
This section is empty.
Variables ¶
var ErrKeyInfoNotFound = errors.New("key info not found")
var ErrUpdateNotAllowed = errors.New("update not allowed")
Functions ¶
func CopyContents ¶
func CopyContents(ctx context.Context, srcFS file.ReadFileFS, src string, dstFS file.WriteFileFS, dst string, perm fs.FileMode) error
CopyContents copies the contents of the source file in srcFS to the destination file in dstFS.
func ExtensionSpec ¶
ExtensionSpec returns the subcmd extension tree for managing key info items in a keychain/secrets store, formatted with the provided name.
func IsDstSafe ¶
SafeStdout checks if the provided name refers to Stdout ("-" or empty) and if so, verifies that Stdout is piped. If Stdout is not piped, it returns an error.
func IsStdoutStdin ¶
IsStdoutStdin returns true if the provided name is "-" or empty, indicating that the operation should read from stdin or write to stdout.
func NewKeyInfoExtension ¶
func NewKeyInfoExtension(name string, appendFn func(cmd *subcmd.CommandSetYAML) error) subcmd.Extension
NewKeyInfoExtension creates a new subcmd.Extension for key info management commands, name specifies the name of the command tree and also the name of the template variable used to include it in the parent command tree.
func ReadFSWithStdin ¶
func ReadFSWithStdin(fs file.ReadFileFS, name string) file.ReadFileFS
ReadFSWithStdin returns a file.ReadFileFS that reads from stdin if the name is "-" or empty.
func ReadFromLocal ¶
func ReadKeyInfoFromLocal ¶
func ReadKeyInfoFromLocal(ctx context.Context, filename string, unmarshal func([]byte, any) error) (keys.Info, error)
ReadKeyInfoFromLocal reads key information from a local file or stdin, unmarshals it using the provided unmarshal function, and returns the resulting keys.Info.
func ReadKeyInfoFromLocalJSON ¶
ReadKeyInfoFromLocalJSON reads key information from a local JSON file or stdin and returns the resulting keys.Info.
func ReadKeyInfoFromLocalYAML ¶
ReadKeyInfoFromLocalYAML reads key information from a local YAML file or stdin and returns the resulting keys.Info.
func ReadWriteFSWithStdout ¶
func ReadWriteFSWithStdout(fs file.ReadWriteFileFS, name string) file.ReadWriteFileFS
ReadWriterFSWithStdout returns a file.ReadWriteFileFS that reads from fs and writes to stdout if the name is "-" or empty.
func SafeWriteKeyInfoJSON ¶
func SafeWriteKeyInfoToLocal ¶
func SafeWriteKeyInfoYAML ¶
func SafeWriteToLocal ¶
func WriteFSWithStdout ¶
func WriteFSWithStdout(fs file.WriteFileFS, name string) file.WriteFileFS
WriteFSWithStdout returns a file.WriteFileFS that writes to stdout if the name is "-" or empty.
Types ¶
type KeyReader ¶
type KeyReader struct {
// contains filtered or unexported fields
}
KeyReader provides methods to read keys from a file system in the InMemoryKeyStore
func NewKeyReader ¶
func NewKeyReader(fs file.ReadFileFS) KeyReader
NewKeyReader creates a new KeyReader that reads keys stored using the InMemoryKeyStore format using the provided file.ReadFileFS.
type KeySpecFlags ¶
type KeySpecFlags struct {
ID string `subcmd:"key-id,,key id"`
User string `subcmd:"key-user,,key user"`
}
KeySpecFlags defines command-line flags for specifying a key's ID and user.
func (KeySpecFlags) KeySpec ¶
func (f KeySpecFlags) KeySpec() keys.KeySpec
KeySpec returns a keys.KeySpec constructed from the KeySpecFlags.
type KeyWriter ¶
type KeyWriter struct {
KeyReader
// contains filtered or unexported fields
}
KeyWriter provides methods to write keys to a file system in the InMemoryKeyStore format.
func NewKeyWriter ¶
func NewKeyWriter(fs file.ReadWriteFileFS) KeyWriter
NewKeyWriter creates a new KeyWriter that writes keys to an InMemoryKeyStore using the provided file.ReadWriteFileFS in the InMemoryKeyStore format.
func (*KeyWriter) DeleteKey ¶
DeleteKey removes a specific key from the specified item in the file system based on the provided keys.KeySpec. It works by reading all of the existing keys, removing the specified key, and then writing the updated list back to the file system.
type SecretConfig ¶
type SecretConfig struct {
Size int `yaml:"key-size" doc:"size of the secret in bytes"`
Format SecretFormat `yaml:"key-format" doc:"format of the secret, one of raw, hex, base64"`
ID string `yaml:"key-id" doc:"id of the key"`
User string `yaml:"key-user" doc:"user/owner associated with the key"`
}
type SecretConfigFlags ¶
type SecretConfigFlags struct {
Size int `subcmd:"size,32,size of the secret in bytes"`
Format flags.Enum[SecretFormat] `subcmd:"format,hex,'format of the secret, one of raw, hex, base64'"`
ID string `subcmd:"id,,id of the key"`
User string `subcmd:"user,,user/owner associated with the key"`
}
func (SecretConfigFlags) SecretConfig ¶
func (sf SecretConfigFlags) SecretConfig() SecretConfig
type SecretFormat ¶
type SecretFormat int
SecretFormat represents the format in which the secret is represented, such as raw bytes, hexadecimal, or base64 encoding.
const ( // SecretFormatRaw indicates that the secret is stored in raw byte format. SecretFormatRaw SecretFormat = iota // SecretFormatHex indicates that the secret is stored in hexadecimal format. SecretFormatHex // SecretFormatBase64 indicates that the secret is stored in base64.StdEncoding format. SecretFormatBase64 )
func (SecretFormat) EnumValues ¶
func (SecretFormat) EnumValues() map[string]SecretFormat
EnumValues implements flags.EnumValues for SecretFormat. A new map is returned on each call so that callers cannot mutate the values shared by every SecretFormat.