Skip to content
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
19 changes: 10 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,21 @@ type (
}

S2SProxyConfig struct {
Inbound *ProxyConfig `yaml:"inbound"`
Outbound *ProxyConfig `yaml:"outbound"`
MuxTransports []MuxTransportConfig `yaml:"mux"`
HealthCheck *HealthCheckConfig `yaml:"healthCheck"`
NamespaceNameTranslation NamespaceNameTranslationConfig `yaml:"namespaceNameTranslation"`
Metrics *MetricsConfig `yaml:"metrics"`
ProfilingConfig ProfilingConfig `yaml:"profiling"`
Inbound *ProxyConfig `yaml:"inbound"`
Outbound *ProxyConfig `yaml:"outbound"`
MuxTransports []MuxTransportConfig `yaml:"mux"`
HealthCheck *HealthCheckConfig `yaml:"healthCheck"`
NamespaceNameTranslation NameTranslationConfig `yaml:"namespaceNameTranslation"`
ClusterNameTranslation NameTranslationConfig `yaml:"clusterNameTranslation"`
Metrics *MetricsConfig `yaml:"metrics"`
ProfilingConfig ProfilingConfig `yaml:"profiling"`
}

ProfilingConfig struct {
PProfHTTPAddress string `yaml:"pprofAddress"`
}

NamespaceNameTranslationConfig struct {
NameTranslationConfig struct {
Mappings []NameMappingConfig `yaml:"mappings"`
}

Expand Down Expand Up @@ -283,7 +284,7 @@ func (mc *MockConfigProvider) GetS2SProxyConfig() S2SProxyConfig {
}

// ToMaps returns request and response mappings.
func (n NamespaceNameTranslationConfig) ToMaps(inBound bool) (map[string]string, map[string]string) {
func (n NameTranslationConfig) ToMaps(inBound bool) (map[string]string, map[string]string) {
reqMap := make(map[string]string)
respMap := make(map[string]string)
if inBound {
Expand Down
2 changes: 1 addition & 1 deletion interceptor/access_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func testNamespaceAccessControl(t *testing.T, objCases []objCase) {
require.ErrorContains(t, err, c.expError)
} else {
require.NoError(t, err)
if c.containsNamespace {
if c.containsObjName {
require.Equal(t, ts.expAllowed, allowed)
} else {
require.True(t, allowed)
Expand Down
65 changes: 65 additions & 0 deletions interceptor/cluster_translator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package interceptor

import (
"testing"

"go.temporal.io/api/namespace/v1"
"go.temporal.io/api/replication/v1"
"go.temporal.io/server/api/adminservice/v1"
)

func generateClusterNameObjs() []objCase {
return []objCase{
{
objName: "nil",
makeType: func(clusterName string) any {
return nil
},
},
{
objName: "DescribeClusterResponse",
makeType: func(clusterName string) any {
return &adminservice.DescribeClusterResponse{
ServerVersion: "1.2.3",
ClusterId: "abc123",
ClusterName: clusterName,
HistoryShardCount: 1234,
}
},
},
{
objName: "GetNamespaceResponse",
containsObjName: false,
makeType: func(name string) any {
return &adminservice.GetNamespaceResponse{
Info: &namespace.NamespaceInfo{
Name: "namespace-name",
},
Config: &namespace.NamespaceConfig{},
ReplicationConfig: &replication.NamespaceReplicationConfig{
ActiveClusterName: name,
Clusters: []*replication.ClusterReplicationConfig{
{
ClusterName: name,
},
{

ClusterName: "some-other-name",
},
},
},
ConfigVersion: 1,
FailoverVersion: 2,
FailoverHistory: []*replication.FailoverStatus{},
IsGlobalNamespace: true,
}

},
expError: "",
},
}
}

func TestTranslateClusterName(t *testing.T) {
testTranslateObjects(t, generateClusterNameObjs())
}
74 changes: 37 additions & 37 deletions interceptor/namespace_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@ type (
}

objCase struct {
objName string
containsNamespace bool
makeType func(ns string) any
expError string
objName string
containsObjName bool
makeType func(name string) any
expError string
}
)

func generateNamespaceObjCases() []objCase {
return []objCase{
{
objName: "Namespace field",
containsNamespace: true,
objName: "Namespace field",
containsObjName: true,
makeType: func(ns string) any {
return &StructWithNamespaceField{Namespace: ns}
},
},
{
objName: "WorkflowNamespace field",
containsNamespace: true,
objName: "WorkflowNamespace field",
containsObjName: true,
makeType: func(ns string) any {
return &StructWithWorkflowNamespaceField{WorkflowNamespace: ns}
},
},
{
objName: "Nested Namespace field",
containsNamespace: true,
objName: "Nested Namespace field",
containsObjName: true,
makeType: func(ns string) any {
return &StructWithNestedNamespaceField{
Other: "do not change",
Expand All @@ -79,8 +79,8 @@ func generateNamespaceObjCases() []objCase {
},
},
{
objName: "list of structs",
containsNamespace: true,
objName: "list of structs",
containsObjName: true,
makeType: func(ns string) any {
return &StructWithListOfNestedNamespaceField{
Other: "do not change",
Expand All @@ -93,8 +93,8 @@ func generateNamespaceObjCases() []objCase {
},
},
{
objName: "list of ptrs",
containsNamespace: true,
objName: "list of ptrs",
containsObjName: true,
makeType: func(ns string) any {
return &StructWithListOfNestedPtrs{
Other: "do not change",
Expand All @@ -107,8 +107,8 @@ func generateNamespaceObjCases() []objCase {
},
},
{
objName: "RespondWorkflowTaskCompletedRequest",
containsNamespace: true,
objName: "RespondWorkflowTaskCompletedRequest",
containsObjName: true,
makeType: func(ns string) any {
return &workflowservice.RespondWorkflowTaskCompletedRequest{
TaskToken: []byte{},
Expand Down Expand Up @@ -138,8 +138,8 @@ func generateNamespaceObjCases() []objCase {
},
},
{
objName: "PollWorkflowTaskQueueResponse",
containsNamespace: true,
objName: "PollWorkflowTaskQueueResponse",
containsObjName: true,
makeType: func(ns string) any {
return &workflowservice.PollWorkflowTaskQueueResponse{
TaskToken: []byte{},
Expand Down Expand Up @@ -168,8 +168,8 @@ func generateNamespaceObjCases() []objCase {
},
},
{
objName: "GetWorkflowExecutionRawHistoryV2Response",
containsNamespace: true,
objName: "GetWorkflowExecutionRawHistoryV2Response",
containsObjName: true,
makeType: func(ns string) any {
return &adminservice.GetWorkflowExecutionRawHistoryV2Response{
NextPageToken: []byte("some-token"),
Expand All @@ -182,8 +182,8 @@ func generateNamespaceObjCases() []objCase {
},
},
{
objName: "DescribeNamespaceResponse",
containsNamespace: true,
objName: "DescribeNamespaceResponse",
containsObjName: true,
makeType: func(ns string) any {
return workflowservice.DescribeNamespaceResponse{
NamespaceInfo: &namespace.NamespaceInfo{
Expand All @@ -194,8 +194,8 @@ func generateNamespaceObjCases() []objCase {
expError: "",
},
{
objName: "UpdateNamespaceResponse",
containsNamespace: true,
objName: "UpdateNamespaceResponse",
containsObjName: true,
makeType: func(ns string) any {
return workflowservice.UpdateNamespaceResponse{
NamespaceInfo: &namespace.NamespaceInfo{
Expand All @@ -217,8 +217,8 @@ func generateNamespaceObjCases() []objCase {
expError: "",
},
{
objName: "ListNamespacesResponse",
containsNamespace: true,
objName: "ListNamespacesResponse",
containsObjName: true,
makeType: func(ns string) any {
return &workflowservice.ListNamespacesResponse{
Namespaces: []*workflowservice.DescribeNamespaceResponse{
Expand All @@ -232,8 +232,8 @@ func generateNamespaceObjCases() []objCase {
expError: "",
},
{
objName: "StreamWorkflowReplicationMessagesResponse",
containsNamespace: true,
objName: "StreamWorkflowReplicationMessagesResponse",
containsObjName: true,
makeType: func(ns string) any {
return &adminservice.StreamWorkflowReplicationMessagesResponse{
Attributes: &adminservice.StreamWorkflowReplicationMessagesResponse_Messages{
Expand Down Expand Up @@ -331,8 +331,8 @@ func generateNamespaceObjCases() []objCase {
},
},
{
objName: "circular pointer",
containsNamespace: true,
objName: "circular pointer",
containsObjName: true,
makeType: func(ns string) any {
a := &StructWithCircularPointer{
Namespace: ns,
Expand Down Expand Up @@ -473,14 +473,14 @@ func generateNamespaceReplicationMessages() []objCase {
},
},
{
objName: "full type",
makeType: makeFullType,
containsNamespace: true,
objName: "full type",
makeType: makeFullType,
containsObjName: true,
},
}
}

func testTranslateNamespace(t *testing.T, objCases []objCase) {
func testTranslateObjects(t *testing.T, objCases []objCase) {
testcases := []struct {
testName string
inputNSName string
Expand Down Expand Up @@ -525,7 +525,7 @@ func testTranslateNamespace(t *testing.T, objCases []objCase) {
require.ErrorContains(t, err, c.expError)
} else {
require.NoError(t, err)
if c.containsNamespace {
if c.containsObjName {
require.Equal(t, expOutput, input)
require.Equal(t, expChanged, changed)
} else {
Expand Down Expand Up @@ -575,9 +575,9 @@ func makeHistoryEventsBlob(ns string) *common.DataBlob {
}

func TestTranslateNamespaceName(t *testing.T) {
testTranslateNamespace(t, generateNamespaceObjCases())
testTranslateObjects(t, generateNamespaceObjCases())
}

func TestTranslateNamespaceReplicationMessages(t *testing.T) {
testTranslateNamespace(t, generateNamespaceReplicationMessages())
testTranslateObjects(t, generateNamespaceReplicationMessages())
}
Loading