github.com/opentofu/opentofu@v1.7.1/internal/encryption/registry/errors.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 registry 7 8 import ( 9 "fmt" 10 11 "github.com/opentofu/opentofu/internal/encryption/keyprovider" 12 "github.com/opentofu/opentofu/internal/encryption/method" 13 ) 14 15 // InvalidKeyProviderError indicates that the supplied keyprovider.Descriptor is invalid/misbehaving. Check the error 16 // message for details. 17 type InvalidKeyProviderError struct { 18 KeyProvider keyprovider.Descriptor 19 Cause error 20 } 21 22 func (k InvalidKeyProviderError) Error() string { 23 return fmt.Sprintf("the supplied key provider %T is invalid (%v)", k.KeyProvider, k.Cause) 24 } 25 26 func (k InvalidKeyProviderError) Unwrap() error { 27 return k.Cause 28 } 29 30 // KeyProviderNotFoundError indicates that the requested key provider was not found in the registry. 31 type KeyProviderNotFoundError struct { 32 ID keyprovider.ID 33 } 34 35 func (k KeyProviderNotFoundError) Error() string { 36 return fmt.Sprintf("key provider with ID %s not found", k.ID) 37 } 38 39 // KeyProviderAlreadyRegisteredError indicates that the requested key provider was already registered in the registry. 40 type KeyProviderAlreadyRegisteredError struct { 41 ID keyprovider.ID 42 CurrentProvider keyprovider.Descriptor 43 PreviousProvider keyprovider.Descriptor 44 } 45 46 func (k KeyProviderAlreadyRegisteredError) Error() string { 47 return fmt.Sprintf( 48 "error while registering key provider ID %s to %T, this ID is already registered by %T", 49 k.ID, k.CurrentProvider, k.PreviousProvider, 50 ) 51 } 52 53 // InvalidMethodError indicates that the supplied method.Descriptor is invalid/misbehaving. Check the error message for 54 // details. 55 type InvalidMethodError struct { 56 Method method.Descriptor 57 Cause error 58 } 59 60 func (k InvalidMethodError) Error() string { 61 return fmt.Sprintf("the supplied encryption method %T is invalid (%v)", k.Method, k.Cause) 62 } 63 64 func (k InvalidMethodError) Unwrap() error { 65 return k.Cause 66 } 67 68 // MethodNotFoundError indicates that the requested encryption method was not found in the registry. 69 type MethodNotFoundError struct { 70 ID method.ID 71 } 72 73 func (m MethodNotFoundError) Error() string { 74 return fmt.Sprintf("encryption method with ID %s not found", m.ID) 75 } 76 77 // MethodAlreadyRegisteredError indicates that the requested encryption method was already registered in the registry. 78 type MethodAlreadyRegisteredError struct { 79 ID method.ID 80 CurrentMethod method.Descriptor 81 PreviousMethod method.Descriptor 82 } 83 84 func (m MethodAlreadyRegisteredError) Error() string { 85 return fmt.Sprintf( 86 "error while registering encryption method ID %s to %T, this ID is already registered by %T", 87 m.ID, m.CurrentMethod, m.PreviousMethod, 88 ) 89 }