-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
temporal workflow fix-history-json
subcommand. (#504)
## What was changed * New command: `temporal workflow fix-history-json` ## Why? This command reads an event history JSON object using the `client.HistoryFromJSON` API, then serializes it back out using the `protojson` API. `HistoryFromJSON` is backward compatible with both the standard protobuf JSON format and with GoGoProto's format, which differ in their handling of enum values. ## Checklist 1. Closes internal JIRA tickets SDK-1570 and OSS-1658, which do not seem to have equivalent issues in the public GitHub. 2. How was this tested: I downloaded a sample event history JSON from my dev server, then ran it through a few conversions. 3. Any docs updates needed? If there's a manual step in publishing changes to `commands.md`, then it will need to be run.
- Loading branch information
1 parent
f9ac669
commit d764241
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package temporalcli | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
|
||
"go.temporal.io/sdk/client" | ||
"google.golang.org/protobuf/encoding/protojson" | ||
) | ||
|
||
func (c *TemporalWorkflowFixHistoryJsonCommand) run(cctx *CommandContext, args []string) error { | ||
raw, err := os.ReadFile(c.Source) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
hjo := client.HistoryJSONOptions{} | ||
history, err := client.HistoryFromJSON(bytes.NewReader(raw), hjo) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mo := protojson.MarshalOptions{Indent: " "} | ||
raw, err = mo.Marshal(history) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
switch c.Target { | ||
case "", "-": | ||
_, err = cctx.Options.Stdout.Write(raw) | ||
return err | ||
|
||
default: | ||
return os.WriteFile(c.Target, raw, 0o666) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters