github.com/confluentinc/confluent-kafka-go@v1.9.2/schemaregistry/config.go (about)

     1  /**
     2   * Copyright 2022 Confluent Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   * http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package schemaregistry
    18  
    19  import "fmt"
    20  
    21  // Config is used to pass multiple configuration options to the Schema Registry client.
    22  type Config struct {
    23  	// SchemaRegistryURL determines the URL of Schema Registry.
    24  	SchemaRegistryURL string
    25  
    26  	// BasicAuthUserInfo specifies the user info in the form of {username}:{password}.
    27  	BasicAuthUserInfo string
    28  	// BasicAuthCredentialsSource specifies how to determine the credentials, one of URL, USER_INFO, and SASL_INHERIT.
    29  	BasicAuthCredentialsSource string
    30  
    31  	// SaslMechanism specifies the SASL mechanism used for client connections, which defaults to GSSAPI.
    32  	SaslMechanism string
    33  	// SaslUsername specifies the username for SASL.
    34  	SaslUsername string
    35  	// SaslUsername specifies the password for SASL.
    36  	SaslPassword string
    37  
    38  	// SslCertificateLocation specifies the location of SSL certificates.
    39  	SslCertificateLocation string
    40  	// SslKeyLocation specifies the location of SSL keys.
    41  	SslKeyLocation string
    42  	// SslCaLocation specifies the location of SSL certificate authorities.
    43  	SslCaLocation string
    44  	// SslDisableEndpointVerification determines whether to disable endpoint verification.
    45  	SslDisableEndpointVerification bool
    46  
    47  	// ConnectionTimeoutMs determines the connection timeout in milliseconds.
    48  	ConnectionTimeoutMs int
    49  	// RequestTimeoutMs determines the request timeout in milliseconds.
    50  	RequestTimeoutMs int
    51  	// CacheCapacity positive integer or zero for unbounded capacity
    52  	CacheCapacity int
    53  }
    54  
    55  // NewConfig returns a new configuration instance with sane defaults.
    56  func NewConfig(url string) *Config {
    57  	c := &Config{}
    58  
    59  	c.SchemaRegistryURL = url
    60  
    61  	c.BasicAuthUserInfo = ""
    62  	c.BasicAuthCredentialsSource = "URL"
    63  
    64  	c.SaslMechanism = "GSSAPI"
    65  	c.SaslUsername = ""
    66  	c.SaslPassword = ""
    67  
    68  	c.SslCertificateLocation = ""
    69  	c.SslKeyLocation = ""
    70  	c.SslCaLocation = ""
    71  	c.SslDisableEndpointVerification = false
    72  
    73  	c.ConnectionTimeoutMs = 10000
    74  	c.RequestTimeoutMs = 10000
    75  
    76  	return c
    77  }
    78  
    79  // NewConfigWithAuthentication returns a new configuration instance using basic authentication.
    80  // For Confluent Cloud, use the API key for the username and the API secret for the password.
    81  func NewConfigWithAuthentication(url string, username string, password string) *Config {
    82  	c := NewConfig(url)
    83  
    84  	c.BasicAuthUserInfo = fmt.Sprintf("%s:%s", username, password)
    85  	c.BasicAuthCredentialsSource = "USER_INFO"
    86  
    87  	return c
    88  }