github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/internal/validator/rules/externalsecrets.go (about)

     1  package rules
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  )
     6  
     7  type externalSecretsValidator struct {
     8  }
     9  
    10  func NewExternalSecretsRule() Rule {
    11  	return &externalSecretsValidator{}
    12  }
    13  
    14  func (s *externalSecretsValidator) Collect(parent string, key string, value interface{}) {
    15  }
    16  
    17  func (s *externalSecretsValidator) Accept(parent string, key string) bool {
    18  	return key == "secrets"
    19  }
    20  
    21  func (s *externalSecretsValidator) Validate(cfgMap interface{}) []error {
    22  	errs := []error{}
    23  	if value, ok := cfgMap.(map[string]interface{}); ok {
    24  		for secretName, secret := range value {
    25  			if secretMap, ok := secret.(map[string]interface{}); ok {
    26  				var hasExternal = false
    27  				for key := range secretMap {
    28  					if key == "external" {
    29  						hasExternal = true
    30  					}
    31  				}
    32  				if !hasExternal {
    33  					errs = append(errs, errors.Errorf(`secret %q must be external`, secretName))
    34  				}
    35  			}
    36  		}
    37  	}
    38  	return errs
    39  }