Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Support HTTPS for Consul KV #1047

Merged
merged 3 commits into from
Feb 10, 2020
Merged
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
2 changes: 2 additions & 0 deletions go/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ type Configuration struct {
DiscoveryIgnoreMasterHostnameFilters []string // Regexp filters to apply to prevent auto-discovering a master. Usage: pointing your master temporarily to replicate seom data from external host
DiscoveryIgnoreHostnameFilters []string // Regexp filters to apply to prevent discovering instances of any kind
ConsulAddress string // Address where Consul HTTP api is found. Example: 127.0.0.1:8500
ConsulScheme string // Scheme (http or https) for Consul
ConsulAclToken string // ACL token used to write to Consul KV
ConsulCrossDataCenterDistribution bool // should orchestrator automatically auto-deduce all consul DCs and write KVs in all DCs
ZkAddress string // UNSUPPERTED YET. Address where (single or multiple) ZooKeeper servers are found, in `srv1[:port1][,srv2[:port2]...]` format. Default port is 2181. Example: srv-a,srv-b:12181,srv-c
Expand Down Expand Up @@ -421,6 +422,7 @@ func newConfiguration() *Configuration {
URLPrefix: "",
DiscoveryIgnoreReplicaHostnameFilters: []string{},
ConsulAddress: "",
ConsulScheme: "http",
ConsulAclToken: "",
ConsulCrossDataCenterDistribution: false,
ZkAddress: "",
Expand Down
10 changes: 9 additions & 1 deletion go/kv/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package kv

import (
"crypto/tls"
"fmt"
"net/http"
"sync"
"sync/atomic"

Expand All @@ -29,7 +31,7 @@ import (
"github.com/openark/golib/log"
)

// A Consul store based on config's `ConsulAddress` and `ConsulKVPrefix`
// A Consul store based on config's `ConsulAddress`, `ConsulScheme`, and `ConsulKVPrefix`
type consulStore struct {
client *consulapi.Client
kvCache *cache.Cache
Expand All @@ -47,6 +49,12 @@ func NewConsulStore() KVStore {
if config.Config.ConsulAddress != "" {
consulConfig := consulapi.DefaultConfig()
consulConfig.Address = config.Config.ConsulAddress
consulConfig.Scheme = config.Config.ConsulScheme
if config.Config.ConsulScheme == "https" {
consulConfig.HttpClient = &http.Client{
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}},
}
}
// ConsulAclToken defaults to ""
consulConfig.Token = config.Config.ConsulAclToken
if client, err := consulapi.NewClient(consulConfig); err != nil {
Expand Down