← Back to team overview

cloud-init-dev team mailing list archive

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

 


Diff comments:

> 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:]]+\[]*//"\

We could simplify this sed to the following I think.  I'd like to avoid calling python3 from shell because of the potential dependency baggage from shell that Scott mentioned. I'd also like to avoid hoisting/duplicating the 37 lines out of ds-identify here too for this iteration.

Below is the sed that does the following operations:
  1. strips all whitespace 
  2. deletes all lines not unmatching ^key:
  3. strips leading "<key>:[" and trailing "]" and replaces "," with ", "



diff --git a/debian/cloud-init.config b/debian/cloud-init.config
index 4c35e5053..7a8043f05 100644
--- a/debian/cloud-init.config
+++ b/debian/cloud-init.config
@@ -35,10 +35,10 @@ get_yaml_list() {
        # 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:[[[:space:]]+\[]*//"\
-        -e "s,[[:space:]]+\]$,," -e p "$file")
+        # strip all whitespace, delete lines not matching key:,
+        # strip key: and [] and replace ',' with ', '
+       RET=$(sed -e "s/\s//g" -e "/^$key:/"'!'d\
+        -e "s/$key:\[//;s/]//;s/,/, /g" $file)
        [ -n "$RET" ] || RET="$default"
 }

> +        -e "s,[[:space:]]+\]$,," -e p "$file")
>  	[ -n "$RET" ] || RET="$default"
>  }
>  


-- 
https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/371919
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.


References