← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~raharper/cloud-init:fix/debian-config-yaml-spaces into cloud-init:ubuntu/devel


Ryan Harper has proposed merging ~raharper/cloud-init:fix/debian-config-yaml-spaces into cloud-init:ubuntu/devel.

Commit message:
debian/cloud-init.config: fix yaml parsing with whitespace
Users may rewrite valid yaml adding or omitting additional white space
when defining the 'datasources_list' variable.  If the yaml did not include
a space between the start of the list '[' and the members and the end ']' then
this would break the shell yaml parsing and produce invalid yaml on
dpkg-reconfigure cloud-init.  Fix this issue by updating the sed matching
expression to allow for zero or more spaces after the leading bracket and
before the trailing bracket.  For example, this branch now accepts:
  datasources_list: [NoCloud, None]
LP: #1841697

Requested reviews:
  cloud-init commiters (cloud-init-dev)
Related bugs:
  Bug #1841697 in cloud-init (Ubuntu): "Upgrade corrupts 90_dpkg.cfg"

For more details, see:
Your team cloud-init commiters is requested to review the proposed merge of ~raharper/cloud-init:fix/debian-config-yaml-spaces into cloud-init:ubuntu/devel.
diff --git a/debian/cloud-init.config b/debian/cloud-init.config
index 6e9c6f7..4c35e50 100644
--- a/debian/cloud-init.config
+++ b/debian/cloud-init.config
@@ -32,13 +32,13 @@ hasEc2Md() {
 get_yaml_list() {
 	# get_yaml_list(file, key, def): return a comma delimited list with the value
 	# for the yaml array defined in 'key' from 'file'. if not found , return 'def'
-	# only really supports 'key: [en1, en2 ]' format.
+	# only really supports 'key: [ en1, en2 ]' or 'key: [en1, en2]' formats.
 	local file="$1" key="$2" default="$3"
 	[ -f "$file" ] || return 1
 	# any thing that didn't match the key is deleted so the final 'p' only
 	# prints things that matched.
-	RET=$(sed -n -e "/^$key:/"'!'d -e "s/$key:[ \[]*//"\
-		-e "s, \]$,," -e p "$file")
+	RET=$(sed -n -e "/^$key:/"'!'d -e "s/$key:[[[:space:]]+\[]*//"\
+        -e "s,[[:space:]]+\]$,," -e p "$file")
 	[ -n "$RET" ] || RET="$default"

Follow ups