mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
119 lines
2.9 KiB
Go
119 lines
2.9 KiB
Go
package tdbg
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
"go.temporal.io/server/common/codec"
|
|
"google.golang.org/protobuf/encoding/prototext"
|
|
"google.golang.org/protobuf/proto"
|
|
"google.golang.org/protobuf/reflect/protoreflect"
|
|
"google.golang.org/protobuf/reflect/protoregistry"
|
|
)
|
|
|
|
func AdminDecodeProto(c *cli.Context) error {
|
|
protoType := c.String(FlagProtoType)
|
|
|
|
var protoData []byte
|
|
var err error
|
|
|
|
binaryFile := c.String(FlagBinaryFile)
|
|
if binaryFile != "" {
|
|
protoData, err = os.ReadFile(binaryFile)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to read binary file %s: %s", binaryFile, err)
|
|
}
|
|
}
|
|
|
|
if protoData == nil {
|
|
hexData := c.String(FlagHexData)
|
|
hexFile := c.String(FlagHexFile)
|
|
if hexData == "" && hexFile != "" {
|
|
hexBytes, err := os.ReadFile(hexFile)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to read hex file %s: %s", hexFile, err)
|
|
}
|
|
hexData = string(hexBytes)
|
|
}
|
|
|
|
hexData = strings.TrimPrefix(hexData, "0x")
|
|
|
|
if hexData != "" {
|
|
protoData, err = hex.DecodeString(hexData)
|
|
if err != nil {
|
|
cutLen := 10
|
|
dots := "..."
|
|
if len(hexData) <= cutLen {
|
|
cutLen = len(hexData)
|
|
dots = ""
|
|
}
|
|
return fmt.Errorf("unable to decode hex data %s%s: %s", hexData[:cutLen], dots, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
if protoData == nil {
|
|
return fmt.Errorf("missing required parameter data flag")
|
|
}
|
|
|
|
messageType, err := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(protoType))
|
|
if err != nil {
|
|
return fmt.Errorf("unable to find %s type: %w", protoType, err)
|
|
}
|
|
|
|
message := messageType.New().Interface()
|
|
if err = proto.Unmarshal(protoData, message); err != nil {
|
|
return fmt.Errorf("unable to unmarshal to %s", protoType)
|
|
}
|
|
|
|
encoder := codec.NewJSONPBIndentEncoder(" ")
|
|
json, err := encoder.Encode(message)
|
|
if err != nil {
|
|
err := fmt.Errorf("unable to encode to JSON: %s", err)
|
|
text, terr := prototext.Marshal(message)
|
|
if terr != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintln(c.App.Writer, err)
|
|
fmt.Fprintln(c.App.Writer, "marshal to text:")
|
|
json = text
|
|
}
|
|
fmt.Fprintln(c.App.Writer, string(json))
|
|
return nil
|
|
}
|
|
|
|
func AdminDecodeBase64(c *cli.Context) error {
|
|
base64Data := c.String(FlagBase64Data)
|
|
base64File := c.String(FlagBase64File)
|
|
if base64Data == "" && base64File != "" {
|
|
base64Bytes, err := os.ReadFile(base64File)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to read base64 file %s: %s", base64File, err)
|
|
}
|
|
base64Data = string(base64Bytes)
|
|
}
|
|
|
|
if base64Data == "" {
|
|
return fmt.Errorf("no data flag is specified")
|
|
}
|
|
|
|
data, err := base64.StdEncoding.DecodeString(base64Data)
|
|
if err != nil {
|
|
cutLen := 10
|
|
dots := "..."
|
|
if len(base64Data) <= cutLen {
|
|
cutLen = len(base64Data)
|
|
dots = ""
|
|
}
|
|
return fmt.Errorf("unable to decode base64 data %s%s: %s", base64Data[:cutLen], dots, err)
|
|
}
|
|
|
|
fmt.Fprintln(c.App.Writer)
|
|
fmt.Fprintln(c.App.Writer, string(data))
|
|
return nil
|
|
}
|