func (s CredentialSchema) Finalize(
	attrs map[string]string,
	readFile func(string) ([]byte, error),
) (map[string]string, error) {
	checker, err := s.schemaChecker()
	if err != nil {
		return nil, errors.Trace(err)
	}
	m := make(map[string]interface{})
	for k, v := range attrs {
		m[k] = v
	}
	result, err := checker.Coerce(m, nil)
	if err != nil {
		return nil, errors.Trace(err)
	}

	resultMap := result.(map[string]interface{})
	newAttrs := make(map[string]string)

	// Construct the final credential attributes map, reading values from files as necessary.
	for _, field := range s {
		if field.FileAttr != "" {
			if err := s.processFileAttrValue(field, resultMap, newAttrs, readFile); err != nil {
				return nil, errors.Trace(err)
			}
			continue
		}
		name := field.Name
		if field.FilePath {
			pathValue, ok := resultMap[name]
			if ok && pathValue != "" {
				absPath, err := ValidateFileAttrValue(pathValue.(string))
				if err != nil {
					return nil, errors.Trace(err)
				}
				data, err := readFile(absPath)
				if err != nil {
					return nil, errors.Annotatef(err, "reading file for %q", name)
				}
				if len(data) == 0 {
					return nil, errors.NotValidf("empty file for %q", name)
				}
				newAttrs[name] = string(data)
				continue
			}
		}
		if val, ok := resultMap[name]; ok {
			newAttrs[name] = val.(string)
		}
	}
	return newAttrs, nil
}
// Finalize finalizes the given credential attributes against the credential
// schema. If the attributes are invalid, Finalize will return an error.
//
// An updated attribute map will be returned, having any file attributes
// deleted, and replaced by their non-file counterparts with the values set
// to the contents of the files.
Finalize finalizes the given credential attributes against the credential
schema. If the attributes are invalid, Finalize will return an error.

An updated attribute map will be returned, having any file attributes
deleted, and replaced by their non-file counterparts with the values set
to the contents of the files.
// Finalize finalizes the given credential attributes against the credential // schema . If the attributes are invalid Finalize will return an error . // // An updated attribute map will be returned having any file attributes // deleted and replaced by their non - file counterparts with the values set // to the contents of the files .
func (s CredentialSchema) Finalize(
	attrs map[string]string,
	readFile func(string) ([]byte, error),
) (map[string]string, error) {
	checker, err := s.schemaChecker()
	if err != nil {
		return nil, errors.Trace(err)
	}
	m := make(map[string]interface{})
	for k, v := range attrs {
		m[k] = v
	}
	result, err := checker.Coerce(m, nil)
	if err != nil {
		return nil, errors.Trace(err)
	}
	resultMap := result.(map[string]interface{})
	newAttrs := make(map[string]string)
	for _, field := range s {
		if field.FileAttr != "" {
			if err := s.processFileAttrValue(field, resultMap, newAttrs, readFile); err != nil {
				return nil, errors.Trace(err)
			}
			continue
		}
		name := field.Name
		if field.FilePath {
			pathValue, ok := resultMap[name]
			if ok && pathValue != "" {
				absPath, err := ValidateFileAttrValue(pathValue.(string))
				if err != nil {
					return nil, errors.Trace(err)
				}
				data, err := readFile(absPath)
				if err != nil {
					return nil, errors.Annotatef(err, "reading file for %q", name)
				}
				if len(data) == 0 {
					return nil, errors.NotValidf("empty file for %q", name)
				}
				newAttrs[name] = string(data)
				continue
			}
		}
		if val, ok := resultMap[name]; ok {
			newAttrs[name] = val.(string)
		}
	}
	return newAttrs, nil
}
func ( s CredentialSchema ) Finalize ( attrs map [ string ] string , readFile func ( string ) ( [ ] byte , error ) , ) ( map [ string ] string , error ) { checker , err := s . schemaChecker ( ) if err != nil { return nil , errors . Trace ( err ) } m := make ( map [ string ] interface { } ) for k , v := range attrs { m [ k ] = v } result , err := checker . Coerce ( m , nil ) if err != nil { return nil , errors . Trace ( err ) } resultMap := result . ( map [ string ] interface { } ) newAttrs := make ( map [ string ] string ) for _ , field := range s { if field . FileAttr != " " { if err := s . processFileAttrValue ( field , resultMap , newAttrs , readFile ) ; err != nil { return nil , errors . Trace ( err ) } continue } name := field . Name if field . FilePath { pathValue , ok := resultMap [ name ] if ok && pathValue != " " { absPath , err := ValidateFileAttrValue ( pathValue . ( string ) ) if err != nil { return nil , errors . Trace ( err ) } data , err := readFile ( absPath ) if err != nil { return nil , errors . Annotatef ( err , " " , name ) } if len ( data ) == 0 { return nil , errors . NotValidf ( " " , name ) } newAttrs [ name ] = string ( data ) continue } } if val , ok := resultMap [ name ] ; ok { newAttrs [ name ] = val . ( string ) } } return newAttrs , nil }
Finalize finalizes the given credential attributes against the credential
schema.
Finalize finalizes the given credential attributes against the credential schema .
// Construct the final credential attributes map, reading values from files as necessary.