func (e *EndorsementStore) GetHwIDFromDB(platformID string, hwID *HardwareIdentity) error {
	var hardwareInstance HardwareIdentityWrapper
	ctx := context.Background()
	if err := e.store.Connect(ctx); err != nil {
		return err
	}
	queryArgs := map[string]interface{}{
		"platformId": platformID,
	}
	hwCollection, _ := e.store.GetQueryParam(HW)
	query := "FOR d IN " + hwCollection
	query += " FILTER d.HardwareIdentity.`psa-hardware-rot`.`implementation-id` == @platformId RETURN d"
	log.Printf("input query = %s", query)
	resultList, err := e.store.RunQuery(ctx, query, queryArgs, &hardwareInstance)
	if err != nil {
		return fmt.Errorf("query failed: %w", err)
	}
	for _, resultValue := range resultList {
		hardwareInstance = resultValue.(HardwareIdentityWrapper)
		break
	}
	*hwID = hardwareInstance.ID
	return nil
}
GetHwIDFromDB queries the DB to get the correct HWID Container for a given platform id
package main
import (
	"context"
	"encoding/json"
	"fmt"
	"log"
	"github.com/hashicorp/go-plugin"
	"github.com/veraison/common"
)
const (
	HW = "HW"
	SW = "SW"
	Edge = "Edge"
	Rel = "Rel"
)
const (
	mindepth      = "1"
	maxdepth      = "10"
	to            = ".."
	space         = " "
	newline       = "\n"
	filterPatches = "FILTER link.rel == 'patches' "
	filterUpdates = "FILTER link.rel == 'updates' "
)
type EndorsementStore struct {
	common.BaseEndorsementStore
	store Store
}
type Resource struct {
	Type             string `json:"type"`
	MeasType         string `json:"arm.com-PSAMeasurementType"`
	Description      string `json:"arm.com-PSADescription"`
	MeasurementValue string `json:"arm.com-PSAMeasurementValue"`
	SignerID         string `json:"arm.com-PSASignerId"`
}
type ResourceCollection struct {
	Resources []Resource `json:"resource"`
}
type PsaEntity struct {
	Name  string   `json:"entity-name"`
	RegID string   `json:"reg-id"`
	Role  []string `json:"role"`
}
type PsaHardwareRot struct {
	ImplementationID string `json:"implementation-id"`
	HwVer            string `json:"hw-ver"`
}
type SoftwareIdentity struct {
	TagID           string               `json:"tag-id"`
	TagVersion      int                  `json:"tag-version"`
	SoftwareName    string               `json:"software-name"`
	SoftwareVersion string               `json:"software-version"`
	Entity          []PsaEntity          `json:"entity"`
	Payload         []ResourceCollection `json:"payload"`
}
type HardwareIdentity struct {
	TagID       string         `json:"tag-id"`
	Entity      []PsaEntity    `json:"entity"`
	HardwareRot PsaHardwareRot `json:"psa-hardware-rot"`
}
type HardwareIdentityWrapper struct {
	ID      HardwareIdentity `json:"HardwareIdentity"`
	RawData json.RawMessage
}
type SoftwareIdentityWrapper struct {
	ID      SoftwareIdentity `json:"SoftwareIdentity"`
	Rawdata json.RawMessage
}
const FirstIndex = 0
func (e *EndorsementStore) GetName() string {
	return "arangodb"
}
func (e *EndorsementStore) Init(args common.EndorsementStoreParams) error {
	e.Queries = map[string]common.Query{
		"hardware_id":           e.GetHardwareID,
		"software_components":   e.GetSoftwareComponents,           
		"all_sw_components":     e.GetAllSoftwareComponents,        
		"linked_sw_comp_latest": e.GetMostRecentSwVerOfLinkedComp,  
		"sw_component_latest":   e.GetMostRecentSwVerOfAnySWComp,   
	}
	_, found := args["AltAlgorithm"]
	if found {
		e.Queries["software_components"] = e.GetAltSoftwareComponents
	}
	store, found := args["storeInstance"]
	if !found {
		return fmt.Errorf("DB store instance is not provided inside FetcherParams")
	}
	e.store = store.(Store)
	if !e.store.IsInitialised() {
		return fmt.Errorf("uninitialized DB store provided in FetcherParams")
	}
	ctx := context.Background()
	if err := e.store.Connect(ctx); err != nil {
		return fmt.Errorf("DB connection failed: %w", err)
	}
	return nil
}
func (e *EndorsementStore) Close() error {
	ctx := context.Background()
	if err := e.store.Connect(ctx); err != nil {
		return err
	}
	if err := e.store.Close(ctx); err != nil {
		return err
	}
	return nil
}