func NewSecretDescriptorList()

in provider/secret_descriptor.go [227:289]


func NewSecretDescriptorList(mountDir, translate, objectSpec string) (desc map[SecretType][]*SecretDescriptor, e error) {

	// See if we should substitite underscore for slash
	if len(translate) == 0 {
		translate = "_" // Use default
	} else if strings.ToLower(translate) == "false" {
		translate = "" // Turn it off.
	} else if len(translate) != 1 {
		return nil, fmt.Errorf("pathTranslation must be either 'False' or a single character string")
	}

	// Unpack the SecretProviderClass mount specification
	descriptors := make([]*SecretDescriptor, 0)
	err := yaml.Unmarshal([]byte(objectSpec), &descriptors)
	if err != nil {
		return nil, fmt.Errorf("Failed to load SecretProviderClass: %+v", err)
	}

	// Validate each record and check for duplicates
	groups := make(map[SecretType][]*SecretDescriptor, 0)
	names := make(map[string]bool)
	for _, descriptor := range descriptors {

		descriptor.translate = translate
		descriptor.mountDir = mountDir
		err = descriptor.validateSecretDescriptor()
		if err != nil {
			return nil, err
		}

		// Group secrets of the same type together to allow batching requests
		sType := descriptor.GetSecretType()
		groups[sType] = append(groups[sType], descriptor)

		// Check for duplicate names
		if names[descriptor.ObjectName] {
			return nil, fmt.Errorf("Name already in use for objectName: %s", descriptor.ObjectName)
		}
		names[descriptor.ObjectName] = true

		if len(descriptor.ObjectAlias) > 0 {
			if names[descriptor.ObjectAlias] {
				return nil, fmt.Errorf("Name already in use for objectAlias: %s", descriptor.ObjectAlias)
			}
			names[descriptor.ObjectAlias] = true
		}

		if len(descriptor.JMESPath) == 0 { //jmesPath not used. No more checks
			continue
		}

		for _, jmesPathEntry := range descriptor.JMESPath {
			if names[jmesPathEntry.ObjectAlias] {
				return nil, fmt.Errorf("Name already in use for objectAlias: %s", jmesPathEntry.ObjectAlias)
			}

			names[jmesPathEntry.ObjectAlias] = true
		}

	}

	return groups, nil
}