@@ -13,6 +13,8 @@ import (
1313 "github.com/stackvista/stackstate-cli/internal/printer"
1414)
1515
16+ const UNKNOWN = "unknown"
17+
1618type InspectArgs struct {
1719 ComponentType string
1820 Tags []string
@@ -87,7 +89,6 @@ func RunInspectCommand(
8789 )
8890
8991 request := stackstate_api .NewViewSnapshotRequest (
90- "SnapshotRequest" ,
9192 query ,
9293 "0.0.1" ,
9394 * metadata ,
@@ -155,15 +156,13 @@ type Component struct {
155156 Properties map [string ]interface {} `json:"properties"`
156157 Layer map [string ]interface {} `json:"layer"`
157158 Domain map [string ]interface {} `json:"domain"`
158- Environment map [string ]interface {} `json:"environment,omitempty"`
159159 Link string `json:"link"`
160160}
161161
162162type ComponentMetadata struct {
163- ComponentTypes map [int64 ]string
164- Layers map [int64 ]string
165- Domains map [int64 ]string
166- Environments map [int64 ]string
163+ ComponentTypes map [string ]string
164+ Layers map [string ]string
165+ Domains map [string ]string
167166}
168167
169168// handleSnapshotError checks if the response is a typed error by examining the _type discriminator
@@ -256,22 +255,20 @@ func parseSnapshotResponse(
256255// all metadata categories in a single loop.
257256var metadataFieldMapping = []struct {
258257 field string
259- setter func (* ComponentMetadata ) * map [ int64 ] string
258+ setter func (* ComponentMetadata , interface {})
260259}{
261- {"componentTypes" , func (m * ComponentMetadata ) * map [int64 ]string { return & m .ComponentTypes }},
262- {"layers" , func (m * ComponentMetadata ) * map [int64 ]string { return & m .Layers }},
263- {"domains" , func (m * ComponentMetadata ) * map [int64 ]string { return & m .Domains }},
264- {"environments" , func (m * ComponentMetadata ) * map [int64 ]string { return & m .Environments }},
260+ {"componentTypes" , func (m * ComponentMetadata , val interface {}) { m .ComponentTypes = parseMetadataByIdentifier (val ) }},
261+ {"layers" , func (m * ComponentMetadata , val interface {}) { m .Layers = parseMetadataByIdentifier (val ) }},
262+ {"domains" , func (m * ComponentMetadata , val interface {}) { m .Domains = parseMetadataByIdentifier (val ) }},
265263}
266264
267- // parseMetadata extracts component type, layer, domain, and environment metadata
265+ // parseMetadata extracts component type, layer, and domain metadata
268266// from the opaque Snapshot response using a table-driven approach.
269267func parseMetadata (respMap map [string ]interface {}) ComponentMetadata {
270268 metadata := ComponentMetadata {
271- ComponentTypes : make (map [int64 ]string ),
272- Layers : make (map [int64 ]string ),
273- Domains : make (map [int64 ]string ),
274- Environments : make (map [int64 ]string ),
269+ ComponentTypes : make (map [string ]string ),
270+ Layers : make (map [string ]string ),
271+ Domains : make (map [string ]string ),
275272 }
276273
277274 metadataMap , ok := respMap ["metadata" ].(map [string ]interface {})
@@ -281,34 +278,32 @@ func parseMetadata(respMap map[string]interface{}) ComponentMetadata {
281278
282279 for _ , mapping := range metadataFieldMapping {
283280 if fieldValue , ok := metadataMap [mapping .field ]; ok {
284- * mapping .setter (& metadata ) = parseMetadataField ( fieldValue )
281+ mapping .setter (& metadata , fieldValue )
285282 }
286283 }
287284
288285 return metadata
289286}
290287
291- // parseMetadataField extracts id/name pairs from a metadata field.
292- // Each item in the slice should have "id" and "name" fields.
293- func parseMetadataField (metadataValue interface {}) map [int64 ]string {
294- result := make (map [int64 ]string )
288+ // parseMetadataByIdentifier extracts metadata items by identifier.
289+ func parseMetadataByIdentifier (metadataValue interface {}) map [string ]string {
290+ result := make (map [string ]string )
295291
296292 if metadataValue == nil {
297293 return result
298294 }
299295
300- // The JSON decoder produces []interface{} for arrays
301296 items , ok := metadataValue .([]interface {})
302297 if ! ok {
303298 return result
304299 }
305300
306301 for _ , item := range items {
307302 if itemMap , ok := item .(map [string ]interface {}); ok {
308- id , idOk := itemMap ["id " ].(float64 )
303+ identifier , idOk := itemMap ["identifier " ].(string )
309304 name , nameOk := itemMap ["name" ].(string )
310305 if idOk && nameOk {
311- result [int64 ( id ) ] = name
306+ result [identifier ] = name
312307 }
313308 }
314309 }
@@ -331,12 +326,12 @@ func parseComponentFromMap(compMap map[string]interface{}, metadata ComponentMet
331326 comp .Name = name
332327 }
333328
334- // Parse type (first id and then lookup from component type metadata)
335- if typeID , ok := compMap ["type " ].(float64 ); ok {
336- if typeName , found := metadata .ComponentTypes [int64 ( typeID ) ]; found {
329+ // Parse type from typeIdentifier and lookup from component type metadata
330+ if typeIdentifier , ok := compMap ["typeIdentifier " ].(string ); ok {
331+ if typeName , found := metadata .ComponentTypes [typeIdentifier ]; found {
337332 comp .Type = typeName
338333 } else {
339- comp .Type = fmt . Sprintf ( "Unknown (%d)" , int64 ( typeID ))
334+ comp .Type = UNKNOWN
340335 }
341336 }
342337
@@ -363,10 +358,9 @@ func parseComponentFromMap(compMap map[string]interface{}, metadata ComponentMet
363358 comp .Properties = propertiesRaw
364359 }
365360
366- // Parse layer, domain, and environment references
367- comp .Layer = parseComponentReference (compMap , "layer" , metadata .Layers )
368- comp .Domain = parseComponentReference (compMap , "domain" , metadata .Domains )
369- comp .Environment = parseComponentReference (compMap , "environment" , metadata .Environments )
361+ // Parse layer and domain references
362+ comp .Layer = parseComponentReference (compMap , "layerIdentifier" , metadata .Layers )
363+ comp .Domain = parseComponentReference (compMap , "domainIdentifier" , metadata .Domains )
370364
371365 // Build link
372366 if len (comp .Identifiers ) > 0 {
@@ -376,19 +370,18 @@ func parseComponentFromMap(compMap map[string]interface{}, metadata ComponentMet
376370 return comp
377371}
378372
379- // parseComponentReference extracts a reference field (layer, domain, or environment )
373+ // parseComponentReference extracts a reference field (layer or domain )
380374// from a component and looks up its name in the provided metadata map.
381- // Returns a map with "id" and "name" keys, or nil if the field is not present.
382- func parseComponentReference (compMap map [string ]interface {}, fieldName string , metadataMap map [int64 ]string ) map [string ]interface {} {
383- if refID , ok := compMap [fieldName ].(float64 ); ok {
384- refIDInt := int64 (refID )
385- refName := "Unknown"
386- if name , found := metadataMap [refIDInt ]; found {
375+ // Returns a map with "identifier" and "name" keys, or nil if the field is not present.
376+ func parseComponentReference (compMap map [string ]interface {}, identifierFieldName string , metadataMap map [string ]string ) map [string ]interface {} {
377+ if refIdentifier , ok := compMap [identifierFieldName ].(string ); ok {
378+ refName := UNKNOWN
379+ if name , found := metadataMap [refIdentifier ]; found {
387380 refName = name
388381 }
389382 return map [string ]interface {}{
390- "id " : refIDInt ,
391- "name" : refName ,
383+ "identifier " : refIdentifier ,
384+ "name" : refName ,
392385 }
393386 }
394387 return nil
0 commit comments