forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
argo-server-client.go
77 lines (63 loc) · 2.64 KB
/
argo-server-client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package apiclient
import (
"context"
"crypto/tls"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
clusterworkflowtmplpkg "github.com/argoproj/argo/pkg/apiclient/clusterworkflowtemplate"
cronworkflowpkg "github.com/argoproj/argo/pkg/apiclient/cronworkflow"
infopkg "github.com/argoproj/argo/pkg/apiclient/info"
workflowpkg "github.com/argoproj/argo/pkg/apiclient/workflow"
workflowarchivepkg "github.com/argoproj/argo/pkg/apiclient/workflowarchive"
workflowtemplatepkg "github.com/argoproj/argo/pkg/apiclient/workflowtemplate"
)
const (
// MaxGRPCMessageSize contains max grpc message size supported by the client
MaxClientGRPCMessageSize = 100 * 1024 * 1024
)
type argoServerClient struct {
*grpc.ClientConn
}
func newArgoServerClient(opts ArgoServerOpts, auth string) (context.Context, Client, error) {
conn, err := newClientConn(opts)
if err != nil {
return nil, nil, err
}
return newContext(auth), &argoServerClient{conn}, nil
}
func (a *argoServerClient) NewWorkflowServiceClient() workflowpkg.WorkflowServiceClient {
return workflowpkg.NewWorkflowServiceClient(a.ClientConn)
}
func (a *argoServerClient) NewCronWorkflowServiceClient() cronworkflowpkg.CronWorkflowServiceClient {
return cronworkflowpkg.NewCronWorkflowServiceClient(a.ClientConn)
}
func (a *argoServerClient) NewWorkflowTemplateServiceClient() workflowtemplatepkg.WorkflowTemplateServiceClient {
return workflowtemplatepkg.NewWorkflowTemplateServiceClient(a.ClientConn)
}
func (a *argoServerClient) NewArchivedWorkflowServiceClient() (workflowarchivepkg.ArchivedWorkflowServiceClient, error) {
return workflowarchivepkg.NewArchivedWorkflowServiceClient(a.ClientConn), nil
}
func (a *argoServerClient) NewClusterWorkflowTemplateServiceClient() clusterworkflowtmplpkg.ClusterWorkflowTemplateServiceClient {
return clusterworkflowtmplpkg.NewClusterWorkflowTemplateServiceClient(a.ClientConn)
}
func (a *argoServerClient) NewInfoServiceClient() (infopkg.InfoServiceClient, error) {
return infopkg.NewInfoServiceClient(a.ClientConn), nil
}
func newClientConn(opts ArgoServerOpts) (*grpc.ClientConn, error) {
creds := grpc.WithInsecure()
if opts.Secure {
creds = grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: opts.InsecureSkipVerify}))
}
conn, err := grpc.Dial(opts.URL, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxClientGRPCMessageSize)), creds)
if err != nil {
return nil, err
}
return conn, nil
}
func newContext(auth string) context.Context {
if auth == "" {
return context.Background()
}
return metadata.NewOutgoingContext(context.Background(), metadata.Pairs("authorization", auth))
}