|
|
@@ -11,11 +11,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
See the License for the specific language governing permissions and
|
|
|
limitations under the License.
|
|
|
*/
|
|
|
+
|
|
|
package chef
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"net/url"
|
|
|
"strings"
|
|
|
@@ -108,7 +110,7 @@ func (providerchef *Providerchef) NewClient(ctx context.Context, store v1beta1.G
|
|
|
|
|
|
if store.GetObjectKind().GroupVersionKind().Kind == v1beta1.ClusterSecretStoreKind {
|
|
|
if chefProvider.Auth.SecretRef.SecretKey.Namespace == nil {
|
|
|
- return nil, fmt.Errorf(errInvalidClusterStoreMissingPKNamespace)
|
|
|
+ return nil, errors.New(errInvalidClusterStoreMissingPKNamespace)
|
|
|
}
|
|
|
objectKey.Namespace = *chefProvider.Auth.SecretRef.SecretKey.Namespace
|
|
|
}
|
|
|
@@ -119,7 +121,7 @@ func (providerchef *Providerchef) NewClient(ctx context.Context, store v1beta1.G
|
|
|
|
|
|
secretKey := credentialsSecret.Data[chefProvider.Auth.SecretRef.SecretKey.Key]
|
|
|
if len(secretKey) == 0 {
|
|
|
- return nil, fmt.Errorf(errMissingSecretKey)
|
|
|
+ return nil, errors.New(errMissingSecretKey)
|
|
|
}
|
|
|
|
|
|
client, err := chef.NewClient(&chef.Config{
|
|
|
@@ -149,20 +151,20 @@ func (providerchef *Providerchef) Validate() (v1beta1.ValidationResult, error) {
|
|
|
_, err := providerchef.userService.Get(providerchef.clientName)
|
|
|
metrics.ObserveAPICall(ProviderChef, CallChefGetUser, err)
|
|
|
if err != nil {
|
|
|
- return v1beta1.ValidationResultError, fmt.Errorf(errStoreValidateFailed)
|
|
|
+ return v1beta1.ValidationResultError, errors.New(errStoreValidateFailed)
|
|
|
}
|
|
|
return v1beta1.ValidationResultReady, nil
|
|
|
}
|
|
|
|
|
|
// GetAllSecrets Retrieves a map[string][]byte with the Databag names as key and the Databag's Items as secrets.
|
|
|
func (providerchef *Providerchef) GetAllSecrets(_ context.Context, _ v1beta1.ExternalSecretFind) (map[string][]byte, error) {
|
|
|
- return nil, fmt.Errorf("dataFrom.find not suppported")
|
|
|
+ return nil, errors.New("dataFrom.find not suppported")
|
|
|
}
|
|
|
|
|
|
// GetSecret returns a databagItem present in the databag. format example: databagName/databagItemName.
|
|
|
func (providerchef *Providerchef) GetSecret(ctx context.Context, ref v1beta1.ExternalSecretDataRemoteRef) ([]byte, error) {
|
|
|
if utils.IsNil(providerchef.databagService) {
|
|
|
- return nil, fmt.Errorf(errUninitalizedChefProvider)
|
|
|
+ return nil, errors.New(errUninitalizedChefProvider)
|
|
|
}
|
|
|
|
|
|
key := ref.Key
|
|
|
@@ -178,7 +180,7 @@ func (providerchef *Providerchef) GetSecret(ctx context.Context, ref v1beta1.Ext
|
|
|
return getSingleDatabagItemWithContext(ctx, providerchef, databagName, databagItem, ref.Property)
|
|
|
}
|
|
|
|
|
|
- return nil, fmt.Errorf(errInvalidFormat)
|
|
|
+ return nil, errors.New(errInvalidFormat)
|
|
|
}
|
|
|
|
|
|
func getSingleDatabagItemWithContext(ctx context.Context, providerchef *Providerchef, dataBagName, databagItemName, propertyName string) ([]byte, error) {
|
|
|
@@ -200,7 +202,7 @@ func getSingleDatabagItemWithContext(ctx context.Context, providerchef *Provider
|
|
|
}
|
|
|
jsonByte, err := json.Marshal(ditem)
|
|
|
if err != nil {
|
|
|
- resultChan <- result{err: fmt.Errorf(errUnableToConvertToJSON)}
|
|
|
+ resultChan <- result{err: errors.New(errUnableToConvertToJSON)}
|
|
|
return
|
|
|
}
|
|
|
if propertyName != "" {
|
|
|
@@ -250,12 +252,12 @@ func getPropertyFromDatabagItem(jsonByte []byte, propertyName string) ([]byte, e
|
|
|
// databagItemName or Property not expected in key.
|
|
|
func (providerchef *Providerchef) GetSecretMap(ctx context.Context, ref v1beta1.ExternalSecretDataRemoteRef) (map[string][]byte, error) {
|
|
|
if utils.IsNil(providerchef.databagService) {
|
|
|
- return nil, fmt.Errorf(errUninitalizedChefProvider)
|
|
|
+ return nil, errors.New(errUninitalizedChefProvider)
|
|
|
}
|
|
|
databagName := ref.Key
|
|
|
|
|
|
if strings.Contains(databagName, "/") {
|
|
|
- return nil, fmt.Errorf(errInvalidDataform)
|
|
|
+ return nil, errors.New(errInvalidDataform)
|
|
|
}
|
|
|
getAllSecrets := make(map[string][]byte)
|
|
|
providerchef.log.Info("fetching all items from", "databag:", databagName)
|
|
|
@@ -291,38 +293,38 @@ func (providerchef *Providerchef) ValidateStore(store v1beta1.GenericStore) (adm
|
|
|
// getChefProvider validates the incoming store and return the chef provider.
|
|
|
func getChefProvider(store v1beta1.GenericStore) (*v1beta1.ChefProvider, error) {
|
|
|
if store == nil {
|
|
|
- return nil, fmt.Errorf(errMissingStore)
|
|
|
+ return nil, errors.New(errMissingStore)
|
|
|
}
|
|
|
storeSpec := store.GetSpec()
|
|
|
if storeSpec == nil {
|
|
|
- return nil, fmt.Errorf(errMissingStoreSpec)
|
|
|
+ return nil, errors.New(errMissingStoreSpec)
|
|
|
}
|
|
|
provider := storeSpec.Provider
|
|
|
if provider == nil {
|
|
|
- return nil, fmt.Errorf(errMissingProvider)
|
|
|
+ return nil, errors.New(errMissingProvider)
|
|
|
}
|
|
|
chefProvider := storeSpec.Provider.Chef
|
|
|
if chefProvider == nil {
|
|
|
- return nil, fmt.Errorf(errMissingChefProvider)
|
|
|
+ return nil, errors.New(errMissingChefProvider)
|
|
|
}
|
|
|
if chefProvider.UserName == "" {
|
|
|
- return chefProvider, fmt.Errorf(errMissingUserName)
|
|
|
+ return chefProvider, errors.New(errMissingUserName)
|
|
|
}
|
|
|
if chefProvider.ServerURL == "" {
|
|
|
- return chefProvider, fmt.Errorf(errMissingServerURL)
|
|
|
+ return chefProvider, errors.New(errMissingServerURL)
|
|
|
}
|
|
|
if !strings.HasSuffix(chefProvider.ServerURL, "/") {
|
|
|
- return chefProvider, fmt.Errorf(errServerURLNoEndSlash)
|
|
|
+ return chefProvider, errors.New(errServerURLNoEndSlash)
|
|
|
}
|
|
|
// check valid URL
|
|
|
if _, err := url.ParseRequestURI(chefProvider.ServerURL); err != nil {
|
|
|
return chefProvider, fmt.Errorf(errInvalidURL, err)
|
|
|
}
|
|
|
if chefProvider.Auth == nil {
|
|
|
- return chefProvider, fmt.Errorf(errMissingAuth)
|
|
|
+ return chefProvider, errors.New(errMissingAuth)
|
|
|
}
|
|
|
if chefProvider.Auth.SecretRef.SecretKey.Key == "" {
|
|
|
- return chefProvider, fmt.Errorf(errMissingSecretKey)
|
|
|
+ return chefProvider, errors.New(errMissingSecretKey)
|
|
|
}
|
|
|
|
|
|
return chefProvider, nil
|
|
|
@@ -330,16 +332,16 @@ func getChefProvider(store v1beta1.GenericStore) (*v1beta1.ChefProvider, error)
|
|
|
|
|
|
// Not Implemented DeleteSecret.
|
|
|
func (providerchef *Providerchef) DeleteSecret(_ context.Context, _ v1beta1.PushSecretRemoteRef) error {
|
|
|
- return fmt.Errorf(errNotImplemented)
|
|
|
+ return errors.New(errNotImplemented)
|
|
|
}
|
|
|
|
|
|
// Not Implemented PushSecret.
|
|
|
func (providerchef *Providerchef) PushSecret(_ context.Context, _ *corev1.Secret, _ v1beta1.PushSecretData) error {
|
|
|
- return fmt.Errorf(errNotImplemented)
|
|
|
+ return errors.New(errNotImplemented)
|
|
|
}
|
|
|
|
|
|
func (providerchef *Providerchef) SecretExists(_ context.Context, _ v1beta1.PushSecretRemoteRef) (bool, error) {
|
|
|
- return false, fmt.Errorf(errNotImplemented)
|
|
|
+ return false, errors.New(errNotImplemented)
|
|
|
}
|
|
|
|
|
|
// Capabilities return the provider supported capabilities (ReadOnly, WriteOnly, ReadWrite).
|