Skip to content

Commit

Permalink
Replace deprecated tctl plugin example with codec server. (#238)
Browse files Browse the repository at this point in the history
* Replace deprecated tctl plugin example with codec server.
  • Loading branch information
robholland authored Dec 13, 2022
1 parent cf498e5 commit e7f0746
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 30 deletions.
15 changes: 10 additions & 5 deletions encryption/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### Steps to run this sample:
1) You need a Temporal service running. See details in README.md
2) Compile the encryption plugin for tctl
2) Run the following command to start the remote codec server
```
go build -o ../bin/encryption-plugin plugin/main.go
go run ./codec-server
```
3) Run the following command to start the worker
```
Expand All @@ -12,9 +12,14 @@ go run worker/main.go
```
go run starter/main.go
```
5) Run the following command and see the encrypted payloads
5) Run the following command and see the payloads cannot be decoded
```
export PATH="../bin:$PATH" TEMPORAL_CLI_PLUGIN_DATA_CONVERTER=encryption-plugin
tctl workflow show --wid encryption_workflowID
```
Note: plugins should normally be available in your PATH, we include the current directory in the path here for ease of testing.
6) Run the following command and see the decoded payloads
```
tctl --codec_endpoint 'http://localhost:8081/' workflow show --wid encryption_workflowID
```

Note: The codec server provided in this sample does not support decoding payloads for the Temporal Web UI, only tctl.
Please see the [codec-server](../codec-server/) sample for a more complete example of a codec server which provides UI decoding and oauth.
48 changes: 48 additions & 0 deletions encryption/codec-server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"flag"
"log"
"net/http"
"os"
"os/signal"
"strconv"

"github.com/temporalio/samples-go/encryption"

"go.temporal.io/sdk/converter"
)

var portFlag int

func init() {
flag.IntVar(&portFlag, "port", 8081, "Port to listen on")
}

func main() {
flag.Parse()

// This example codec server does not support varying config per namespace,
// decoding for the Temporal Web UI or oauth.
// For a more complete example of a codec server please see the codec-server sample at:
// ../../codec-server.
handler := converter.NewPayloadCodecHTTPHandler(&encryption.Codec{}, converter.NewZlibCodec(converter.ZlibCodecOptions{AlwaysEncode: true}))

srv := &http.Server{
Addr: "0.0.0.0:" + strconv.Itoa(portFlag),
Handler: handler,
}

errCh := make(chan error, 1)
go func() { errCh <- srv.ListenAndServe() }()

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)

select {
case <-sigCh:
_ = srv.Close()
case err := <-errCh:
log.Fatal(err)
}
}
25 changes: 0 additions & 25 deletions encryption/plugin/main.go

This file was deleted.

0 comments on commit e7f0746

Please sign in to comment.