mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
// Licensed under the GNU Affero General Public License (AGPL).
|
|
// See License-AGPL.txt in the project root for license information.
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/golang/protobuf/jsonpb"
|
|
"github.com/golang/protobuf/proto"
|
|
"github.com/spf13/cobra"
|
|
|
|
csapi "github.com/gitpod-io/gitpod/content-service/api"
|
|
)
|
|
|
|
// debugDecodeImageSpec represents the debugHeadlessLog command
|
|
var debugDecodeImageSpec = &cobra.Command{
|
|
Use: "decode-initalizer <str>",
|
|
Short: "Decodes and marshals an image spec to JSON from a base64-encoded protobuf string",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
initializerPB, err := base64.StdEncoding.DecodeString(args[0])
|
|
if err != nil {
|
|
return fmt.Errorf("cannot decode init config: %w", err)
|
|
}
|
|
|
|
var initializer csapi.WorkspaceInitializer
|
|
err = proto.Unmarshal(initializerPB, &initializer)
|
|
if err != nil {
|
|
return fmt.Errorf("cannot unmarshal init config: %w", err)
|
|
}
|
|
|
|
m := &jsonpb.Marshaler{
|
|
EnumsAsInts: false,
|
|
Indent: " ",
|
|
}
|
|
return m.Marshal(os.Stdout, &initializer)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
debugCmd.AddCommand(debugDecodeImageSpec)
|
|
}
|