Skip to content

Commit

Permalink
Merge pull request #4546 from oasisprotocol/yawning/feature/bundle-list
Browse files Browse the repository at this point in the history
go/oasis-node/cmd/debug/bundle: Add info command
  • Loading branch information
Yawning authored Mar 7, 2022
2 parents de8caea + 048ea00 commit 6743e38
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
1 change: 1 addition & 0 deletions .changelog/4546.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/oasis-node/cmd/debug/bundle: Add info command
68 changes: 57 additions & 11 deletions go/oasis-node/cmd/debug/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package bundle

import (
"encoding/json"
"fmt"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -38,13 +40,19 @@ var (
initCmd = &cobra.Command{
Use: "init",
Short: "create a runtime bundle",
Run: doInit,
RunE: doInit,
}

infoCmd = &cobra.Command{
Use: "info",
Short: "inspect a runtime bundle",
RunE: doInfo,
}

logger = logging.GetLogger("cmd/debug/bundle")
)

func doInit(cmd *cobra.Command, args []string) {
func doInit(cmd *cobra.Command, args []string) error {
if err := cmdCommon.Init(); err != nil {
cmdCommon.EarlyLogAndExit(err)
}
Expand All @@ -61,13 +69,13 @@ func doInit(cmd *cobra.Command, args []string) {
logger.Error("failed to parse runtime ID",
"err", err,
)
os.Exit(1)
return err
}
if manifest.Version, err = version.FromString(viper.GetString(CfgRuntimeVersion)); err != nil {
logger.Error("failed to parse runtime version",
"err", err,
)
os.Exit(1)
return err
}

type runtimeFile struct {
Expand Down Expand Up @@ -107,46 +115,84 @@ func doInit(cmd *cobra.Command, args []string) {
logger.Error("missing runtime asset",
"descr", v.descr,
)
os.Exit(1)
return err
}
var b []byte
if b, err = os.ReadFile(v.fn); err != nil {
logger.Error("failed to load runtime asset",
"err", err,
"descr", v.descr,
)
os.Exit(1)
return err
}
_ = bnd.Add(v.dst, b)
}

dstFn := viper.GetString(CfgRuntimeBundle)
if dstFn == "" {
logger.Error("missing runtime bundle name")
os.Exit(1)
return err
}
if err = bnd.Write(dstFn); err != nil {
logger.Error("failed to write runtime bundle",
"err", err,
)
os.Exit(1)
return err
}

return nil
}

func doInfo(cmd *cobra.Command, args []string) error {
if err := cmdCommon.Init(); err != nil {
cmdCommon.EarlyLogAndExit(err)
}

fn := viper.GetString(CfgRuntimeBundle)
bnd, err := bundle.Open(fn)
if err != nil {
logger.Error("failed to open bundle",
"err", err,
"file_name", fn,
)
return err
}

b, err := json.MarshalIndent(bnd.Manifest, "", " ")
if err != nil {
logger.Error("failed to reserialize manifest",
"err", err,
)
return err
}

fmt.Println(string(b))

return nil
}

// Register registers the bundle sub-command and all of it's children.
func Register(parentCmd *cobra.Command) {
commonFlags := flag.NewFlagSet("", flag.ContinueOnError)
commonFlags.String(CfgRuntimeBundle, "runtime.orc", "path to runtime bundle")
_ = viper.BindPFlags(commonFlags)

initFlags := flag.NewFlagSet("", flag.ContinueOnError)
initFlags.String(CfgRuntimeID, "", "runtime ID (Base16-encoded)")
initFlags.String(CfgRuntimeName, "", "runtime name (optional)")
initFlags.String(CfgRuntimeVersion, "0.0.0", "runtime version")
initFlags.String(CfgRuntimeExecutable, "runtime.bin", "path to runtime ELF binary")
initFlags.String(CfgRuntimeSGXExecutable, "", "path to runtime SGX binary")
initFlags.String(CfgRuntimeSGXSignature, "", "path to runtime SGX signature")
initFlags.String(CfgRuntimeBundle, "runtime.orc", "output path to runtime bundle")

_ = viper.BindPFlags(initFlags)
initCmd.Flags().AddFlagSet(initFlags)

bundleCmd.AddCommand(initCmd)
for _, cmd := range []*cobra.Command{
initCmd,
infoCmd,
} {
cmd.Flags().AddFlagSet(commonFlags)
bundleCmd.AddCommand(cmd)
}
parentCmd.AddCommand(bundleCmd)
}

0 comments on commit 6743e38

Please sign in to comment.