Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set caller type header #363

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions cli/headers/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ const (
SupportedServerVersionsHeaderName = "supported-server-versions"
SupportedFeaturesHeaderName = "supported-features"
SupportedFeaturesHeaderDelim = ","
CallerTypeHeaderName = "caller-type"
)

const (
ClientNameCLI = "temporal-cli"
CallerTypeCLI = "operator"

CLIVersion = "1.18.0"

Expand All @@ -54,6 +56,7 @@ var (
ClientVersionHeaderName,
SupportedServerVersionsHeaderName,
SupportedFeaturesHeaderName,
CallerTypeHeaderName,
}

internalVersionHeaders = metadata.New(map[string]string{
Expand All @@ -62,6 +65,7 @@ var (

cliVersionHeaders = metadata.New(map[string]string{
ClientNameHeaderName: ClientNameCLI,
CallerTypeHeaderName: CallerTypeCLI,
ClientVersionHeaderName: CLIVersion,
SupportedServerVersionsHeaderName: SupportedServerVersions,
// TODO: This should include SupportedFeaturesHeaderName with a value that's taken
Expand Down
16 changes: 7 additions & 9 deletions cli/headersprovider/headers_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,27 @@ package headersprovider
import (
"context"

"github.com/temporalio/tctl/cli/headers"
"github.com/temporalio/tctl/cli/plugin"
)

type HeadersProvider interface {
GetHeaders(context.Context) (map[string]string, error)
}

var (
headersProvider plugin.HeadersProvider = nil
)

type authHeaderProvider struct {
value string
type headerProvider struct {
authHeaderValue string
}

func (a authHeaderProvider) GetHeaders(ctx context.Context) (map[string]string, error) {
func (a headerProvider) GetHeaders(ctx context.Context) (map[string]string, error) {
return map[string]string{
"Authorization": a.value,
headers.CallerTypeHeaderName: headers.CallerTypeCLI,
"Authorization": a.authHeaderValue,
}, nil
}

func SetAuthorizationHeader(value string) {
headersProvider = &authHeaderProvider{value: value}
headersProvider = &headerProvider{authHeaderValue: value}
}

func SetCurrent(hp plugin.HeadersProvider) {
Expand Down