Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
FROM alpine:latest AS runner
WORKDIR /root
COPY --from=builder /go/src/github.com/superfly/tokenizer/bin/tokenizer /usr/local/bin/tokenizer
CMD ["tokenizer"]
CMD ["tokenizer", "serve", "-use-flysrc=true"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export OPEN_KEY=$(openssl rand -hex 32)
Run the tokenizer server:

```shell
tokenizer
tokenizer serve -use-flysrc=true
```

The output will contain the public (seal) key, which can be used for encrypting secrets.
Expand Down
4 changes: 2 additions & 2 deletions cmd/tokenizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To run a test server locally:
source ./.envrc

# run server
go run .
go run . serve -use-flysrc=true
```

The `github.com/superfly/tokenizer/cmd/curl` package has instructions for sending requests via this server with a test client.
The `github.com/superfly/tokenizer/cmd/curl` package has instructions for sending requests via this server with a test client.
33 changes: 33 additions & 0 deletions cmd/tokenizer/args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"flag"
"fmt"
"os"
"strconv"
"strings"
)

// parseFlags runs the flagset parser.
// It fails if there are any non-flag arguments.
// On error it prints the default usage and moreUsage and exits.
func parseFlags(fs *flag.FlagSet, moreUsage string, args []string) {
err := fs.Parse(args)
if err == nil && len(fs.Args()) > 0 {
err = fmt.Errorf("unknown arguments: %v\n", strings.Join(fs.Args(), " "))
fmt.Fprintf(os.Stderr, "%v\n", err)
fs.Usage()
}

if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", moreUsage)
os.Exit(1)
}
}

// strToBool converts a string to a boolean. If there is an error parsing the string
// it returns a default value of false. Values 1, t, T, TRUE, true, and True return true values.
func strToBool(s string) bool {
b, _ := strconv.ParseBool(s)
return b
}
60 changes: 60 additions & 0 deletions cmd/tokenizer/debug_listener.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"fmt"
"net"
"time"
)

type debugListener struct {
net.Listener
}

func (dl debugListener) Accept() (net.Conn, error) {
c, err := dl.Listener.Accept()
if err == nil {
c = debugConn{c}
}
return c, err
}

type debugConn struct {
c net.Conn
}

func (dc debugConn) Read(b []byte) (int, error) {
n, err := dc.c.Read(b)
if err == nil {
fmt.Printf("<- %#v\n", string(b[:n]))
}
return n, err
}

func (dc debugConn) Write(b []byte) (int, error) {
fmt.Printf("-> %#v\n", string(b))
return dc.c.Write(b)
}

func (dc debugConn) Close() error {
return dc.c.Close()
}

func (dc debugConn) LocalAddr() net.Addr {
return dc.c.LocalAddr()
}

func (dc debugConn) RemoteAddr() net.Addr {
return dc.c.RemoteAddr()
}

func (dc debugConn) SetDeadline(t time.Time) error {
return dc.c.SetDeadline(t)
}

func (dc debugConn) SetReadDeadline(t time.Time) error {
return dc.c.SetReadDeadline(t)
}

func (dc debugConn) SetWriteDeadline(t time.Time) error {
return dc.c.SetWriteDeadline(t)
}
Loading
Loading