forked from confluentinc/confluent-kafka-go
/
config.go
129 lines (104 loc) · 4.4 KB
/
config.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Copyright 2022 Confluent Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package schemaregistry
import (
"fmt"
"net/http"
)
// Config is used to pass multiple configuration options to the Schema Registry client.
type Config struct {
// SchemaRegistryURL determines the URL of Schema Registry.
SchemaRegistryURL string
// BasicAuthUserInfo specifies the user info in the form of {username}:{password}.
BasicAuthUserInfo string
// BasicAuthCredentialsSource specifies how to determine the credentials, one of URL, USER_INFO, and SASL_INHERIT.
BasicAuthCredentialsSource string
// SaslMechanism specifies the SASL mechanism used for client connections, which defaults to GSSAPI.
SaslMechanism string
// SaslUsername specifies the username for SASL.
SaslUsername string
// SaslUsername specifies the password for SASL.
SaslPassword string
// BearerAuthToken specifies the token for authentication.
BearerAuthToken string
// BearerAuthCredentialsSource specifies how to determine the credentials.
BearerAuthCredentialsSource string
// BearerAuthLogicalCluster specifies the target SR logical cluster id. It is required for Confluent Cloud Schema Registry
BearerAuthLogicalCluster string
// BearerAuthIdentityPoolID specifies the identity pool ID. It is required for Confluent Cloud Schema Registry
BearerAuthIdentityPoolID string
// SslCertificateLocation specifies the location of SSL certificates.
SslCertificateLocation string
// SslKeyLocation specifies the location of SSL keys.
SslKeyLocation string
// SslCaLocation specifies the location of SSL certificate authorities.
SslCaLocation string
// SslDisableEndpointVerification determines whether to disable endpoint verification.
SslDisableEndpointVerification bool
// ConnectionTimeoutMs determines the connection timeout in milliseconds.
ConnectionTimeoutMs int
// RequestTimeoutMs determines the request timeout in milliseconds.
RequestTimeoutMs int
// CacheCapacity positive integer or zero for unbounded capacity
CacheCapacity int
// CacheLatestTTLSecs ttl in secs for caching the latest schema
CacheLatestTTLSecs int
// HTTP client
HTTPClient *http.Client
}
// NewConfig returns a new configuration instance with sane defaults.
func NewConfig(url string) *Config {
c := &Config{}
c.SchemaRegistryURL = url
c.SaslMechanism = "GSSAPI"
c.SaslUsername = ""
c.SaslPassword = ""
c.SslCertificateLocation = ""
c.SslKeyLocation = ""
c.SslCaLocation = ""
c.SslDisableEndpointVerification = false
c.ConnectionTimeoutMs = 10000
c.RequestTimeoutMs = 10000
return c
}
// NewConfigWithAuthentication returns a new configuration instance using basic authentication.
// For Confluent Cloud, use the API key for the username and the API secret for the password.
// This method is deprecated.
func NewConfigWithAuthentication(url string, username string, password string) *Config {
c := NewConfig(url)
c.BasicAuthUserInfo = fmt.Sprintf("%s:%s", username, password)
c.BasicAuthCredentialsSource = "USER_INFO"
return c
}
// NewConfigWithBasicAuthentication returns a new configuration instance using basic authentication.
// For Confluent Cloud, use the API key for the username and the API secret for the password.
func NewConfigWithBasicAuthentication(url string, username string, password string) *Config {
c := NewConfig(url)
c.BasicAuthUserInfo = fmt.Sprintf("%s:%s", username, password)
c.BasicAuthCredentialsSource = "USER_INFO"
return c
}
// NewConfigWithBearerAuthentication returns a new configuration instance using bearer authentication.
// For Confluent Cloud, targetSr(`bearer.auth.logical.cluster` and
// identityPoolID(`bearer.auth.identity.pool.id`) is required
func NewConfigWithBearerAuthentication(url, token, targetSr, identityPoolID string) *Config {
c := NewConfig(url)
c.BearerAuthToken = token
c.BearerAuthCredentialsSource = "STATIC_TOKEN"
c.BearerAuthLogicalCluster = targetSr
c.BearerAuthIdentityPoolID = identityPoolID
return c
}