func (m Metadata) ResolveInvalidKey() (resolvedMetadata Metadata, err error) {
	resolvedMetadata = make(map[string]string)

	hasCollision := func(name string) bool {
		_, hasCollisionToOrgNames := m[name]
		_, hasCollisionToNewNames := resolvedMetadata[name]

		return hasCollisionToOrgNames || hasCollisionToNewNames
	}

	for k, v := range m {
		if !isValidMetadataKey(k) {
			validKey := metadataKeyInvalidCharRegex.ReplaceAllString(k, "_")
			renamedKey := metadataRenamedKeyPrefix + validKey
			keyForRenamedOriginalKey := metadataKeyForRenamedOriginalKeyPrefix + validKey
			if hasCollision(renamedKey) || hasCollision(keyForRenamedOriginalKey) {
				return nil, fmt.Errorf(metadataKeyRenameErrStr, k)
			}

			resolvedMetadata[renamedKey] = v
			resolvedMetadata[keyForRenamedOriginalKey] = k
		} else {
			resolvedMetadata[k] = v
		}
	}

	return resolvedMetadata, nil
}
// ResolveInvalidKey resolves invalid metadata key with following steps:
// 1. replace all invalid char(i.e. ASCII chars expect [0-9A-Za-z_]) with '_'
// 2. add 'rename_' as prefix for the new valid key, this key will be used to save original metadata's value.
// 3. add 'rename_key_' as prefix for the new valid key, this key will be used to save original metadata's invalid key.
// Example, given invalid metadata for Azure: '123-invalid':'content', it will be resolved as two new k:v pairs:
// 'rename_123_invalid':'content'
// 'rename_key_123_invalid':'123-invalid'
// So user can try to recover the metadata in Azure side.
// Note: To keep first version simple, whenever collision is found during key resolving, error will be returned.
// This can be further improved once any user feedback get.
ResolveInvalidKey resolves invalid metadata key with following steps:
1. replace all invalid char with '_'
2. add 'rename_' as prefix for the new valid key, this key will be used to save original metadata's value.
3. add 'rename_key_' as prefix for the new valid key, this key will be used to save original metadata's invalid key.
Example, given invalid metadata for Azure: '123-invalid':'content', it will be resolved as two new k:v pairs:
'rename_123_invalid':'content'
'rename_key_123_invalid':'123-invalid'
So user can try to recover the metadata in Azure side.
Note: To keep first version simple, whenever collision is found during key resolving, error will be returned.
This can be further improved once any user feedback get.
// ResolveInvalidKey resolves invalid metadata key with following steps : // 1 . replace all invalid char ( i . e . ASCII chars expect [ 0 - 9A - Za - z_ ] ) with ' _ ' // 2 . add ' rename_ ' as prefix for the new valid key this key will be used to save original metadata ' s value . // 3 . add ' rename_key_ ' as prefix for the new valid key this key will be used to save original metadata ' s invalid key . // Example given invalid metadata for Azure : ' 123 - invalid ' : ' content ' it will be resolved as two new k : v pairs : // ' rename_123_invalid ' : ' content ' // ' rename_key_123_invalid ' : ' 123 - invalid ' // So user can try to recover the metadata in Azure side . // Note : To keep first version simple whenever collision is found during key resolving error will be returned . // This can be further improved once any user feedback get .
func (m Metadata) ResolveInvalidKey() (resolvedMetadata Metadata, err error) {
	resolvedMetadata = make(map[string]string)
	hasCollision := func(name string) bool {
		_, hasCollisionToOrgNames := m[name]
		_, hasCollisionToNewNames := resolvedMetadata[name]
		return hasCollisionToOrgNames || hasCollisionToNewNames
	}
	for k, v := range m {
		if !isValidMetadataKey(k) {
			validKey := metadataKeyInvalidCharRegex.ReplaceAllString(k, "_")
			renamedKey := metadataRenamedKeyPrefix + validKey
			keyForRenamedOriginalKey := metadataKeyForRenamedOriginalKeyPrefix + validKey
			if hasCollision(renamedKey) || hasCollision(keyForRenamedOriginalKey) {
				return nil, fmt.Errorf(metadataKeyRenameErrStr, k)
			}
			resolvedMetadata[renamedKey] = v
			resolvedMetadata[keyForRenamedOriginalKey] = k
		} else {
			resolvedMetadata[k] = v
		}
	}
	return resolvedMetadata, nil
}
func ( m Metadata ) ResolveInvalidKey ( ) ( resolvedMetadata Metadata , err error ) { resolvedMetadata = make ( map [ string ] string ) hasCollision := func ( name string ) bool { _ , hasCollisionToOrgNames := m [ name ] _ , hasCollisionToNewNames := resolvedMetadata [ name ] return hasCollisionToOrgNames || hasCollisionToNewNames } for k , v := range m { if ! isValidMetadataKey ( k ) { validKey := metadataKeyInvalidCharRegex . ReplaceAllString ( k , " " ) renamedKey := metadataRenamedKeyPrefix + validKey keyForRenamedOriginalKey := metadataKeyForRenamedOriginalKeyPrefix + validKey if hasCollision ( renamedKey ) || hasCollision ( keyForRenamedOriginalKey ) { return nil , fmt . Errorf ( metadataKeyRenameErrStr , k ) } resolvedMetadata [ renamedKey ] = v resolvedMetadata [ keyForRenamedOriginalKey ] = k } else { resolvedMetadata [ k ] = v } } return resolvedMetadata , nil }
ResolveInvalidKey resolves invalid metadata key with following steps:
1. replace all invalid char with '_'
2. add 'rename_' as prefix for the new valid key, this key will be used to save original metadata's value.
ResolveInvalidKey resolves invalid metadata key with following steps : 1 . replace all invalid char with ' _ ' 2 . add ' rename_ ' as prefix for the new valid key this key will be used to save original metadata ' s value .