blob: d0191820b22848d435b37de421de3ab151063bbf [file] [log] [blame]
// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// GetMetadata translates the metadata from a file to a local JSON repr
package commands
import (
lacros_metadata "go.chromium.org/chromiumos/test/provision/v2/lacros-provision/lacros-metadata"
"go.chromium.org/chromiumos/test/provision/v2/lacros-provision/service"
"context"
"encoding/json"
"log"
"go.chromium.org/chromiumos/config/go/test/api"
)
type GetMetadataCommand struct {
ctx context.Context
cs *service.LaCrOSService
}
func NewGetMetadataCommand(ctx context.Context, cs *service.LaCrOSService) *GetMetadataCommand {
return &GetMetadataCommand{
ctx: ctx,
cs: cs,
}
}
func (c *GetMetadataCommand) Execute(log *log.Logger) error {
metadataJSONStr, err := c.cs.Connection.RunCmd(c.ctx, "cat", []string{"/tmp/metadata.json"})
if err != nil {
return err
}
metadataJSON := lacros_metadata.LaCrOSMetadata{}
if err := json.Unmarshal([]byte(metadataJSONStr), &metadataJSON); err != nil {
return err
}
if c.cs.OverrideVersion != "" {
metadataJSON.Content.Version = c.cs.OverrideVersion
}
c.cs.LaCrOSMetadata = &metadataJSON
return nil
}
func (c *GetMetadataCommand) Revert() error {
return nil
}
func (c *GetMetadataCommand) GetErrorMessage() string {
return "failed to get metadata"
}
func (c *GetMetadataCommand) GetStatus() api.InstallResponse_Status {
return api.InstallResponse_STATUS_UPDATE_FIRMWARE_FAILED
}