@@ -33,6 +33,12 @@ type MetadataStemcellCriteria struct {
3333 RequiresCPI bool `yaml:"requires_cpi"`
3434}
3535
36+ type BoshRuntimeConfigFields map [string ]interface {}
37+ type BoshRuntimeConfig struct {
38+ Releases []map [string ]string `yaml:",omitempty"`
39+ OtherFields BoshRuntimeConfigFields `yaml:",inline"`
40+ }
41+
3642type releaseManifestReader interface {
3743 Read (path string ) (ReleaseManifest , error )
3844}
@@ -112,42 +118,40 @@ func (m MetadataBuilder) Build(releaseTarballs []string, pathToStemcell, pathToH
112118
113119func (m MetadataBuilder ) updateRuntimeConfigReleaseVersions (handcraft Handcraft , releases []MetadataRelease ) (Handcraft , error ) {
114120 if opsmanRuntimeConfigs , ok := handcraft ["runtime_configs" ]; ok {
115- for _ , opsmanRuntimeConfig := range opsmanRuntimeConfigs .([]interface {}) {
116- runtimeConfig := opsmanRuntimeConfig .(map [interface {}]interface {})
117- var rc map [ string ] interface {}
118- err := yaml .Unmarshal ([]byte (runtimeConfig ["runtime_config" ].(string )), & rc )
121+ for _ , orc := range opsmanRuntimeConfigs .([]interface {}) {
122+ opsmanRuntimeConfig := orc .(map [interface {}]interface {})
123+ var boshRuntimeConfig BoshRuntimeConfig
124+ err := yaml .Unmarshal ([]byte (opsmanRuntimeConfig ["runtime_config" ].(string )), & boshRuntimeConfig )
119125 if err != nil {
120126 return Handcraft {}, fmt .Errorf ("runtime config %s contains malformed yaml: %s" ,
121- runtimeConfig ["name" ], err )
127+ opsmanRuntimeConfig ["name" ], err )
122128 }
123129
124- if runtimeConfigReleases , ok := rc ["releases" ]; ok {
125- for _ , runtimeConfigRelease := range runtimeConfigReleases .([]interface {}) {
126- rcr := runtimeConfigRelease .(map [interface {}]interface {})
127-
130+ if len (boshRuntimeConfig .Releases ) > 0 {
131+ for _ , runtimeConfigRelease := range boshRuntimeConfig .Releases {
128132 found := false
129133
130134 for _ , release := range releases {
131- if release .Name == rcr ["name" ].( string ) {
135+ if release .Name == runtimeConfigRelease ["name" ] {
132136 m .logger .Printf ("Injecting version %s into runtime config release %s" , release .Version , release .Name )
133- rcr ["version" ] = release .Version
137+ runtimeConfigRelease ["version" ] = release .Version
134138 found = true
135139 }
136140 }
137141
138142 if ! found {
139143 return Handcraft {}, fmt .Errorf ("runtime config %s references unknown release %s" ,
140- runtimeConfig ["name" ], rcr ["name" ])
144+ opsmanRuntimeConfig ["name" ], runtimeConfigRelease ["name" ])
141145 }
142146 }
143147 }
144148
145- newYAML , err := yaml .Marshal (rc )
149+ newYAML , err := yaml .Marshal (boshRuntimeConfig )
146150 if err != nil {
147- panic ( err )
151+ return Handcraft {}, err // untested
148152 }
149153
150- runtimeConfig ["runtime_config" ] = string (newYAML )
154+ opsmanRuntimeConfig ["runtime_config" ] = string (newYAML )
151155 }
152156 }
153157
0 commit comments