1+ package main
2+
3+ import (
4+ "context"
5+ "crypto/tls"
6+ "fmt"
7+ "log"
8+ "os"
9+ "time"
10+
11+ sdkclient "go.temporal.io/sdk/client"
12+ )
13+
14+ func main () {
15+ // Get values from environment variables (fail if not set)
16+ serverAddr := os .Getenv ("TEMPORAL_HOST_PORT" )
17+ apiKey := os .Getenv ("TEMPORAL_API_KEY" )
18+ temporalNamespace := os .Getenv ("TEMPORAL_NAMESPACE" )
19+
20+ if serverAddr == "" {
21+ log .Fatal ("TEMPORAL_HOST_PORT environment variable is required" )
22+ }
23+ if apiKey == "" {
24+ log .Fatal ("TEMPORAL_API_KEY environment variable is required" )
25+ }
26+ if temporalNamespace == "" {
27+ log .Fatal ("TEMPORAL_NAMESPACE environment variable is required" )
28+ }
29+
30+ fmt .Printf ("Testing Temporal client health check against: %s\n " , serverAddr )
31+ fmt .Printf ("Using temporal namespace: %s\n " , temporalNamespace )
32+ fmt .Printf ("Using API key: %s...\n " , apiKey [:min (10 , len (apiKey ))])
33+
34+ // Test 1: Client without authentication (like original mTLS-only setup)
35+ fmt .Println ("\n === Test 1: Client without authentication ===" )
36+ clientOpts1 := sdkclient.Options {
37+ HostPort : serverAddr ,
38+ Namespace : temporalNamespace ,
39+ ConnectionOptions : sdkclient.ConnectionOptions {
40+ TLS : & tls.Config {}, // Basic TLS, no auth
41+ },
42+ }
43+
44+ c1 , err1 := sdkclient .Dial (clientOpts1 )
45+ if err1 != nil {
46+ fmt .Printf ("❌ Failed to create client: %v\n " , err1 )
47+ } else {
48+ defer c1 .Close ()
49+ ctx1 , cancel1 := context .WithTimeout (context .Background (), 10 * time .Second )
50+ defer cancel1 ()
51+
52+ _ , err1 := c1 .CheckHealth (ctx1 , & sdkclient.CheckHealthRequest {})
53+ if err1 != nil {
54+ fmt .Printf ("❌ Health check failed: %v\n " , err1 )
55+ } else {
56+ fmt .Printf ("✅ Health check succeeded\n " )
57+ }
58+ }
59+
60+ // Test 2: Client with API key authentication (matches our controller)
61+ fmt .Println ("\n === Test 2: Client with API key authentication ===" )
62+ clientOpts2 := sdkclient.Options {
63+ HostPort : serverAddr ,
64+ Namespace : temporalNamespace ,
65+ Credentials : sdkclient .NewAPIKeyStaticCredentials (apiKey ),
66+ ConnectionOptions : sdkclient.ConnectionOptions {
67+ TLS : & tls.Config {}, // Basic TLS + API key
68+ },
69+ }
70+
71+ c2 , err2 := sdkclient .Dial (clientOpts2 )
72+ if err2 != nil {
73+ fmt .Printf ("❌ Failed to create client: %v\n " , err2 )
74+ } else {
75+ defer c2 .Close ()
76+ ctx2 , cancel2 := context .WithTimeout (context .Background (), 10 * time .Second )
77+ defer cancel2 ()
78+
79+ _ , err2 := c2 .CheckHealth (ctx2 , & sdkclient.CheckHealthRequest {})
80+ if err2 != nil {
81+ fmt .Printf ("❌ Health check failed: %v\n " , err2 )
82+ } else {
83+ fmt .Printf ("✅ Health check succeeded\n " )
84+ }
85+ }
86+
87+ // Test 3: Different context for health check
88+ fmt .Println ("\n === Test 3: API key with different context ===" )
89+ if c2 != nil {
90+ ctx3 := context .Background ()
91+ _ , err3 := c2 .CheckHealth (ctx3 , & sdkclient.CheckHealthRequest {})
92+ if err3 != nil {
93+ fmt .Printf ("❌ Health check with background context failed: %v\n " , err3 )
94+ } else {
95+ fmt .Printf ("✅ Health check with background context succeeded\n " )
96+ }
97+ }
98+ }
99+
100+ func min (a , b int ) int {
101+ if a < b {
102+ return a
103+ }
104+ return b
105+ }
0 commit comments