Skip to content

Commit

Permalink
add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
gertd committed Nov 27, 2024
1 parent 0d01414 commit 088cf75
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/topaz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func run() (exitCode int) {
"no_color": strconv.FormatBool(cc.NoColor()),
"active_config": c.Config.Active.Config,
"cwd": cwd,
"timeout": cc.Timeout().String(),
},
)
zerolog.SetGlobalLevel(logLevel(cli.LogLevel))
Expand Down
11 changes: 11 additions & 0 deletions pkg/cli/cc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cc
import (
"os"
"strconv"
"time"
)

const (
Expand All @@ -15,6 +16,7 @@ const (
defaultTenantID = ""
defaultInsecure = false
defaultPlaintext = false
defaultTimeout = 5 * time.Second
defaultNoCheck = false
defaultNoColor = false
)
Expand Down Expand Up @@ -86,6 +88,15 @@ func Plaintext() bool {
return defaultPlaintext
}

func Timeout() time.Duration {
if timeout := os.Getenv("TOPAZ_TIMEOUT"); timeout != "" {
if dur, err := time.ParseDuration(timeout); err == nil {
return dur
}
}
return defaultTimeout
}

func NoCheck() bool {
if noCheck := os.Getenv("TOPAZ_NO_CHECK"); noCheck != "" {
if b, err := strconv.ParseBool(noCheck); err == nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/clients/authorizer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package authorizer

import (
"context"
"time"

client "github.com/aserto-dev/go-aserto"
"github.com/fullstorydev/grpcurl"
Expand All @@ -23,6 +24,7 @@ type Config struct {
Plaintext bool `flag:"plaintext" short:"P" default:"${plaintext}" env:"TOPAZ_PLAINTEXT" help:"use plain-text HTTP/2 (no TLS)"`
TenantID string `flag:"tenant-id" help:"" default:"${tenant_id}" env:"ASERTO_TENANT_ID" `
Headers map[string]string `flag:"headers" env:"TOPAZ_AUTHORIZER_HEADERS" help:"additional headers to send to the authorizer service"`
Timeout time.Duration `flag:"timeout" short:"T" default:"${timeout}" env:"TOPAZ_TIMEOUT" help:"command timeout"`
}

type Client struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cli/clients/directory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package directory

import (
"context"
"time"

client "github.com/aserto-dev/go-aserto"
dsa3 "github.com/aserto-dev/go-directory/aserto/directory/assertion/v3"
Expand All @@ -28,6 +29,7 @@ type Config struct {
Plaintext bool `flag:"plaintext" short:"P" default:"${plaintext}" env:"TOPAZ_PLAINTEXT" help:"use plain-text HTTP/2 (no TLS)"`
TenantID string `flag:"tenant-id" help:"" default:"${tenant_id}" env:"ASERTO_TENANT_ID" `
Headers map[string]string `flag:"headers" env:"TOPAZ_DIRECTORY_HEADERS" help:"additional headers to send to the directory service"`
Timeout time.Duration `flag:"timeout" short:"T" default:"${timeout}" env:"TOPAZ_TIMEOUT" help:"command timeout"`
}

type Client struct {
Expand Down

0 comments on commit 088cf75

Please sign in to comment.