initial commit
This commit is contained in:
commit
193f302e28
122
client.go
Normal file
122
client.go
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
package etcdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
etcdclient "go.etcd.io/etcd/client/v3"
|
||||||
|
"go.etcd.io/etcd/client/v3/namespace"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClientSpec struct {
|
||||||
|
URLs string
|
||||||
|
Prefix string
|
||||||
|
TLS TLSSpec
|
||||||
|
|
||||||
|
//User string
|
||||||
|
//Password string
|
||||||
|
|
||||||
|
client *etcdclient.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
type TLSSpec struct {
|
||||||
|
CAPath string
|
||||||
|
KeyPath string
|
||||||
|
CertPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec *ClientSpec) BindFlags(name string) {
|
||||||
|
flag.StringVar(&spec.URLs, name+"-etcd-urls", spec.URLs, "comma-separated etcd URLs ("+name+" cluster)")
|
||||||
|
flag.StringVar(&spec.Prefix, name+"-etcd-prefix", spec.Prefix, "etcd prefix ("+name+" cluster)")
|
||||||
|
|
||||||
|
// TLS flags
|
||||||
|
flag.StringVar(&spec.TLS.CAPath, name+"-ca", spec.TLS.CAPath, "etcd CA path ("+name+" cluster)")
|
||||||
|
flag.StringVar(&spec.TLS.KeyPath, name+"-key", spec.TLS.KeyPath, "etcd key path ("+name+" cluster)")
|
||||||
|
flag.StringVar(&spec.TLS.CertPath, name+"-crt", spec.TLS.CertPath, "etcd certificate path ("+name+" cluster)")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec *ClientSpec) MustConnect() {
|
||||||
|
err := spec.Connect()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("etcd failed to connect: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec *ClientSpec) Connect() error {
|
||||||
|
cfg := etcdclient.Config{
|
||||||
|
Endpoints: strings.Split(spec.URLs, ","),
|
||||||
|
}
|
||||||
|
|
||||||
|
if caPath := spec.TLS.CAPath; caPath != "" {
|
||||||
|
if cfg.TLS == nil {
|
||||||
|
cfg.TLS = &tls.Config{}
|
||||||
|
}
|
||||||
|
|
||||||
|
caData, err := ioutil.ReadFile(caPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to read CA file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.TLS.RootCAs = x509.NewCertPool()
|
||||||
|
if !cfg.TLS.RootCAs.AppendCertsFromPEM(caData) {
|
||||||
|
return fmt.Errorf("no certificates found in %s", caPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if spec.TLS.KeyPath != "" || spec.TLS.CertPath != "" {
|
||||||
|
if cfg.TLS == nil {
|
||||||
|
cfg.TLS = &tls.Config{}
|
||||||
|
}
|
||||||
|
|
||||||
|
cert, err := tls.LoadX509KeyPair(spec.TLS.CertPath, spec.TLS.KeyPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to load client key pair: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.TLS.Certificates = []tls.Certificate{cert}
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := etcdclient.New(cfg)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to build client: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix := spec.Prefix
|
||||||
|
if prefix != "" && !strings.HasSuffix(prefix, "/") {
|
||||||
|
prefix += "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
client.KV = namespace.NewKV(client.KV, prefix)
|
||||||
|
client.Watcher = namespace.NewWatcher(client.Watcher, prefix)
|
||||||
|
client.Lease = namespace.NewLease(client.Lease, prefix)
|
||||||
|
|
||||||
|
spec.client = client
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec *ClientSpec) Client() *etcdclient.Client {
|
||||||
|
if spec.client == nil {
|
||||||
|
panic("no client, Connect() no called?")
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &etcdclient.Client{}
|
||||||
|
*client = *spec.client
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec *ClientSpec) Root() EtcdSpec {
|
||||||
|
return EtcdSpec{
|
||||||
|
client: spec,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec *ClientSpec) Sub(prefix string) EtcdSpec {
|
||||||
|
return EtcdSpec{
|
||||||
|
client: spec,
|
||||||
|
}.Sub(prefix)
|
||||||
|
}
|
23
codec.go
Normal file
23
codec.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package etcdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Codec interface {
|
||||||
|
Encode(v any) ([]byte, error)
|
||||||
|
Decode(raw []byte, v any) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type jsonCodec struct{}
|
||||||
|
|
||||||
|
var JSONCodec Codec = jsonCodec{}
|
||||||
|
|
||||||
|
func (_ jsonCodec) Encode(v any) ([]byte, error) {
|
||||||
|
return json.Marshal(v)
|
||||||
|
}
|
||||||
|
func (_ jsonCodec) Decode(raw []byte, v any) error {
|
||||||
|
return json.Unmarshal(raw, v)
|
||||||
|
}
|
73
e2e/e2e.go
Normal file
73
e2e/e2e.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"novit.tech/direktil/etcdb"
|
||||||
|
"novit.tech/direktil/etcdb/leader"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Normal = etcdb.ClientSpec{
|
||||||
|
URLs: "http://127.0.0.1:2379",
|
||||||
|
Prefix: "etcdbl/",
|
||||||
|
}
|
||||||
|
Secure = etcdb.ClientSpec{
|
||||||
|
URLs: "http://127.0.0.1:2379",
|
||||||
|
Prefix: "etcdbs/",
|
||||||
|
}
|
||||||
|
|
||||||
|
data = etcdb.Encrypted(Secure.Sub("encset/"))
|
||||||
|
|
||||||
|
myInt = etcdb.SingletonSpec[int]{Spec: data, Key: "my-int"}
|
||||||
|
myStrings = etcdb.SetSpec[string]{Spec: data.Sub("my-strings")}
|
||||||
|
|
||||||
|
data2 = etcdb.Encrypted(Secure.Sub("encset/"))
|
||||||
|
myStrings2 = etcdb.SetSpec[string]{Spec: data2.Sub("my-strings")}
|
||||||
|
|
||||||
|
myLeader = leader.Spec{
|
||||||
|
Etcd: &Normal,
|
||||||
|
Election: "my-leader",
|
||||||
|
OnLeader: onLeader,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
Normal.MustConnect()
|
||||||
|
Secure.MustConnect()
|
||||||
|
|
||||||
|
myLeader.RunProcess()
|
||||||
|
}
|
||||||
|
|
||||||
|
func onLeader(ctx context.Context) {
|
||||||
|
if err := data.Unlock(ctx, []byte("uifee6ooB")); err != nil {
|
||||||
|
log.Print("failed to unlock: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data.AddKey(ctx, []byte("xish1yaiG"))
|
||||||
|
|
||||||
|
if err := data2.Unlock(ctx, []byte("xish1yaiG")); err != nil {
|
||||||
|
log.Print("failed to unlock 2nd set: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
v := "value"
|
||||||
|
|
||||||
|
if true {
|
||||||
|
d1 := myStrings.In(ctx)
|
||||||
|
err := d1.Put("key", v)
|
||||||
|
log.Printf("d1[key] => err=%v %q", err, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
if true {
|
||||||
|
d2 := myStrings2.In(ctx)
|
||||||
|
v, ok, err := d2.Get("key")
|
||||||
|
log.Printf("d2[key] => ok=%v err=%v value=%q", ok, err, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
<-ctx.Done()
|
||||||
|
log.Print("leader context done")
|
||||||
|
}
|
387
encrypted-set.go
Normal file
387
encrypted-set.go
Normal file
@ -0,0 +1,387 @@
|
|||||||
|
package etcdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/aes"
|
||||||
|
"crypto/cipher"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/sha512"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/binary"
|
||||||
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/argon2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// encrypted key hash -> master key
|
||||||
|
|
||||||
|
func Encrypted(spec EtcdSpec) *EncryptedSpec {
|
||||||
|
v := &EncryptedSpec{
|
||||||
|
keys: spec.Sub("keys/"),
|
||||||
|
data: spec.Sub("data/"),
|
||||||
|
}
|
||||||
|
v.l.Lock()
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
type EncryptedSpec struct {
|
||||||
|
l sync.Mutex
|
||||||
|
|
||||||
|
keys,
|
||||||
|
data EtcdSpec
|
||||||
|
|
||||||
|
masterKey []byte // TODO syscall.MemSecret when kernels are up to date
|
||||||
|
salt1, salt2 []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) keyPairFromPassword(password []byte) (key, pub []byte) {
|
||||||
|
key = argon2.IDKey(password, es.salt1, 1, 64*1024, 4, 32)
|
||||||
|
pub = argon2.IDKey(key, es.salt2, 1, 64*1024, 4, 32)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) keysIn(ctx context.Context) DB {
|
||||||
|
return HexDB{es.keys.In(ctx)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) loadSalts(ctx context.Context) error {
|
||||||
|
if es.salt1 != nil && es.salt2 != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
keySet := es.keysIn(ctx)
|
||||||
|
|
||||||
|
for _, i := range []struct {
|
||||||
|
key string
|
||||||
|
target *[]byte
|
||||||
|
}{
|
||||||
|
{"salt1", &es.salt1},
|
||||||
|
{"salt2", &es.salt2},
|
||||||
|
} {
|
||||||
|
v, ok, err := keySet.Get(i.key)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
v = make([]byte, 64)
|
||||||
|
readRandom(v)
|
||||||
|
keySet.Put(i.key, v)
|
||||||
|
}
|
||||||
|
*i.target = v
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) IsOpen() bool {
|
||||||
|
return len(es.masterKey) != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) WaitOpen() {
|
||||||
|
es.l.Lock()
|
||||||
|
es.l.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) SetMasterKey(key []byte) {
|
||||||
|
if len(key) != 32 {
|
||||||
|
panic("wrong key size")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer memzero(key)
|
||||||
|
|
||||||
|
masterKey := make([]byte, 32)
|
||||||
|
if err := syscall.Mlock(masterKey); err != nil {
|
||||||
|
panic(fmt.Errorf("mlock(masterKey) failed: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range key {
|
||||||
|
masterKey[i] = key[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
es.l.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) Unlock(ctx context.Context, password []byte) (err error) {
|
||||||
|
err = es.loadSalts(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
key, pubKey := es.keyPairFromPassword(password)
|
||||||
|
memzero(password)
|
||||||
|
defer memzero(key)
|
||||||
|
|
||||||
|
keySet := es.keysIn(ctx)
|
||||||
|
|
||||||
|
hasKey := false
|
||||||
|
keySet.ForEach(func(k string, _ []byte) (cont bool) {
|
||||||
|
if strings.HasPrefix(k, "0x") {
|
||||||
|
hasKey = true
|
||||||
|
}
|
||||||
|
return !hasKey
|
||||||
|
})
|
||||||
|
|
||||||
|
masterKey := make([]byte, 32)
|
||||||
|
if err = syscall.Mlock(masterKey); err != nil {
|
||||||
|
return fmt.Errorf("mlock(masterKey) failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hasKey {
|
||||||
|
// no keys, initialize
|
||||||
|
readRandom(masterKey)
|
||||||
|
encryptedMaster := aesEncrypt(masterKey, key)
|
||||||
|
|
||||||
|
err = keySet.Put("0x"+hex.EncodeToString(pubKey), encryptedMaster)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
es.masterKey = masterKey
|
||||||
|
es.l.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// has keys, lookup the key
|
||||||
|
encryptedMaster, ok, err := keySet.Get("0x" + hex.EncodeToString(pubKey))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
err = fmt.Errorf("no such key")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
aesDecryptTo(masterKey, encryptedMaster, key)
|
||||||
|
|
||||||
|
es.masterKey = masterKey
|
||||||
|
es.l.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) Lock() {
|
||||||
|
if !es.l.TryLock() {
|
||||||
|
panic("double lock")
|
||||||
|
}
|
||||||
|
|
||||||
|
memzero(es.masterKey)
|
||||||
|
syscall.Munlock(es.masterKey)
|
||||||
|
|
||||||
|
es.masterKey = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) AddKey(ctx context.Context, password []byte) error {
|
||||||
|
if es.masterKey == nil {
|
||||||
|
panic("no masterKey")
|
||||||
|
}
|
||||||
|
|
||||||
|
key, pubKey := es.keyPairFromPassword(password)
|
||||||
|
memzero(password)
|
||||||
|
|
||||||
|
encryptedMaster := func() []byte {
|
||||||
|
defer memzero(key)
|
||||||
|
return aesEncrypt(es.masterKey, key)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return es.keysIn(ctx).Put("0x"+hex.EncodeToString(pubKey), encryptedMaster)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) In(ctx context.Context) DB {
|
||||||
|
return EncryptedDB{
|
||||||
|
es: es,
|
||||||
|
wrappedDB: es.data.In(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (es *EncryptedSpec) Sub(prefix string) EncryptedSubSpec {
|
||||||
|
return EncryptedSubSpec{
|
||||||
|
es: es,
|
||||||
|
data: es.data.Sub(prefix),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type EncryptedSubSpec struct {
|
||||||
|
es *EncryptedSpec
|
||||||
|
data EtcdSpec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec EncryptedSubSpec) In(ctx context.Context) DB {
|
||||||
|
return EncryptedDB{
|
||||||
|
es: spec.es,
|
||||||
|
wrappedDB: spec.data.In(ctx),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type EncryptedDB struct {
|
||||||
|
es *EncryptedSpec
|
||||||
|
wrappedDB DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e EncryptedDB) obscureKey(keyBytes []byte) string {
|
||||||
|
h := sha512.Sum512(keyBytes)
|
||||||
|
return base64.RawStdEncoding.EncodeToString(h[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e EncryptedDB) encodeKV(key string, value []byte) (outKey string, outValue []byte, err error) {
|
||||||
|
keyBytes := []byte(key)
|
||||||
|
if len(keyBytes) > 0xffff {
|
||||||
|
err = errors.New("key too long")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
outKey = e.obscureKey(keyBytes)
|
||||||
|
|
||||||
|
outValue = make([]byte, 0, 2+len(key)+len(value))
|
||||||
|
outValue = binary.BigEndian.AppendUint16(outValue, uint16(len(key)))
|
||||||
|
outValue = append(outValue, keyBytes...)
|
||||||
|
outValue = append(outValue, value...)
|
||||||
|
|
||||||
|
outValue = aesEncrypt(outValue, e.es.masterKey)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e EncryptedDB) decodeKV(encryptedKV []byte) (key string, value []byte, err error) {
|
||||||
|
kv := aesDecrypt(encryptedKV, e.es.masterKey)
|
||||||
|
|
||||||
|
if len(kv) < 2 {
|
||||||
|
err = errors.New("value too short for key len")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
keyLen := int(binary.BigEndian.Uint16(kv[:2]))
|
||||||
|
kv = kv[2:]
|
||||||
|
|
||||||
|
if len(kv) < keyLen {
|
||||||
|
err = errors.New("value too short for key")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
key = string(kv[:keyLen])
|
||||||
|
value = kv[keyLen:]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e EncryptedDB) Get(key string) (value []byte, ok bool, err error) {
|
||||||
|
encryptedValue, ok, err := e.wrappedDB.Get(e.obscureKey([]byte(key)))
|
||||||
|
if !ok || err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, value, err = e.decodeKV(encryptedValue)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e EncryptedDB) Put(key string, value []byte) error {
|
||||||
|
dbKey, encryptedValue, err := e.encodeKV(key, value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return e.wrappedDB.Put(dbKey, encryptedValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e EncryptedDB) Del(key string) error {
|
||||||
|
return e.wrappedDB.Del(e.obscureKey([]byte(key)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e EncryptedDB) ForEach(callback func(key string, value []byte) (cont bool)) (err error) {
|
||||||
|
forEachErr := e.wrappedDB.ForEach(func(key string, encryptedValue []byte) (cont bool) {
|
||||||
|
realKey, value, decodeErr := e.decodeKV(encryptedValue)
|
||||||
|
if decodeErr != nil {
|
||||||
|
err = fmt.Errorf("failed to decode value under key %q: %w", key, decodeErr)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return callback(realKey, value)
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return forEachErr
|
||||||
|
}
|
||||||
|
func (e EncryptedDB) Watch(rev int64) <-chan WatchEvent {
|
||||||
|
ch := make(chan WatchEvent, 1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer close(ch)
|
||||||
|
|
||||||
|
inCh := e.wrappedDB.Watch(rev)
|
||||||
|
|
||||||
|
for evt := range inCh {
|
||||||
|
encryptedValue := evt.Value
|
||||||
|
evt.Value = nil
|
||||||
|
|
||||||
|
if len(encryptedValue) == 0 {
|
||||||
|
ch <- evt
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
realKey, value, err := e.decodeKV(encryptedValue)
|
||||||
|
if err != nil {
|
||||||
|
evt.Err = fmt.Errorf("failed to decode value: %w", err)
|
||||||
|
ch <- evt
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
evt.Key = realKey
|
||||||
|
evt.Value = value
|
||||||
|
|
||||||
|
ch <- evt
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func aesEncrypt(data, key []byte) []byte {
|
||||||
|
c, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to init AES: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
// output = initialization vector + encrypted data
|
||||||
|
const ivSize = aes.BlockSize
|
||||||
|
output := make([]byte, ivSize+len(data))
|
||||||
|
|
||||||
|
iv := output[:ivSize]
|
||||||
|
readRandom(iv)
|
||||||
|
|
||||||
|
cipher.NewCFBEncrypter(c, iv).XORKeyStream(output[ivSize:], data)
|
||||||
|
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
func aesDecrypt(data, key []byte) []byte {
|
||||||
|
dst := make([]byte, len(data)-aes.BlockSize)
|
||||||
|
aesDecryptTo(dst, data, key)
|
||||||
|
return dst
|
||||||
|
}
|
||||||
|
|
||||||
|
func aesDecryptTo(dst, data, key []byte) {
|
||||||
|
c, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to init AES: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
const ivSize = aes.BlockSize
|
||||||
|
|
||||||
|
iv := data[:ivSize]
|
||||||
|
cipher.NewCFBDecrypter(c, iv).XORKeyStream(dst, data[ivSize:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func readRandom(dst []byte) {
|
||||||
|
if _, err := io.ReadFull(rand.Reader, dst); err != nil {
|
||||||
|
log.Panic("failed to read random bytes: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func memzero(ba []byte) {
|
||||||
|
for i := range ba {
|
||||||
|
ba[i] = 0
|
||||||
|
}
|
||||||
|
}
|
171
etcd-spec.go
Normal file
171
etcd-spec.go
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
package etcdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
etcdclient "go.etcd.io/etcd/client/v3"
|
||||||
|
"go.etcd.io/etcd/client/v3/mirror"
|
||||||
|
"go.etcd.io/etcd/client/v3/namespace"
|
||||||
|
)
|
||||||
|
|
||||||
|
type EtcdSpec struct {
|
||||||
|
client *ClientSpec
|
||||||
|
prefix string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec EtcdSpec) Sub(prefix string) EtcdSpec {
|
||||||
|
p := spec.prefix + prefix
|
||||||
|
if !strings.HasSuffix(p, "/") {
|
||||||
|
p += "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
return EtcdSpec{
|
||||||
|
client: spec.client,
|
||||||
|
prefix: p,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec EtcdSpec) In(ctx context.Context) DB {
|
||||||
|
client := spec.client.Client()
|
||||||
|
|
||||||
|
client.KV = namespace.NewKV(client.KV, spec.prefix)
|
||||||
|
client.Watcher = namespace.NewWatcher(client.Watcher, spec.prefix)
|
||||||
|
client.Lease = namespace.NewLease(client.Lease, spec.prefix)
|
||||||
|
|
||||||
|
return EtcdDB{
|
||||||
|
client: client,
|
||||||
|
ctx: ctx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type EtcdDB struct {
|
||||||
|
client *etcdclient.Client
|
||||||
|
ctx context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db EtcdDB) Get(key string) (value []byte, ok bool, err error) {
|
||||||
|
get, err := db.client.KV.Get(db.ctx, key)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(get.Kvs) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
value = get.Kvs[0].Value
|
||||||
|
ok = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db EtcdDB) Put(key string, val []byte) (err error) {
|
||||||
|
_, err = db.client.KV.Put(db.ctx, key, string(val))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db EtcdDB) Del(key string) (err error) {
|
||||||
|
_, err = db.client.KV.Delete(db.ctx, key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db EtcdDB) ForEach(callback func(key string, value []byte) (cont bool)) (err error) {
|
||||||
|
withSort := etcdclient.WithSort(etcdclient.SortByKey, etcdclient.SortAscend)
|
||||||
|
|
||||||
|
opts := []etcdclient.OpOption{withSort, etcdclient.WithFromKey()}
|
||||||
|
key := "\x00"
|
||||||
|
|
||||||
|
for {
|
||||||
|
get, err := db.client.KV.Get(db.ctx, key, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, kv := range get.Kvs {
|
||||||
|
cont := callback(string(kv.Key), kv.Value)
|
||||||
|
if !cont {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !get.More {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait, there's more!
|
||||||
|
key = string(append(get.Kvs[len(get.Kvs)-1].Key, 0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db EtcdDB) Watch(rev int64) <-chan WatchEvent {
|
||||||
|
ch := make(chan WatchEvent, 1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer close(ch)
|
||||||
|
|
||||||
|
sync := mirror.NewSyncer(db.client, "", rev)
|
||||||
|
|
||||||
|
gets, errs := sync.SyncBase(db.ctx)
|
||||||
|
|
||||||
|
var maxRev int64
|
||||||
|
for get := range gets {
|
||||||
|
for _, kv := range get.Kvs {
|
||||||
|
ch <- WatchEvent{
|
||||||
|
Key: string(kv.Key),
|
||||||
|
Value: kv.Value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if get.Header.Revision > maxRev {
|
||||||
|
maxRev = get.Header.Revision
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err, _ := <-errs
|
||||||
|
if err != nil {
|
||||||
|
ch <- WatchEvent{Err: err}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if maxRev != 0 {
|
||||||
|
ch <- WatchEvent{NewRev: maxRev}
|
||||||
|
}
|
||||||
|
|
||||||
|
watchChan := sync.SyncUpdates(db.ctx)
|
||||||
|
for watchEvent := range watchChan {
|
||||||
|
for _, evt := range watchEvent.Events {
|
||||||
|
switch evt.Type {
|
||||||
|
case etcdclient.EventTypePut:
|
||||||
|
ch <- WatchEvent{
|
||||||
|
Key: string(evt.Kv.Key),
|
||||||
|
Value: evt.Kv.Value,
|
||||||
|
}
|
||||||
|
case etcdclient.EventTypeDelete:
|
||||||
|
ch <- WatchEvent{
|
||||||
|
Key: string(evt.Kv.Key),
|
||||||
|
Delete: true,
|
||||||
|
Value: evt.Kv.Value,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ch <- WatchEvent{
|
||||||
|
Err: fmt.Errorf("unknown event type: %d", evt.Type),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err := watchEvent.Err()
|
||||||
|
if err == nil {
|
||||||
|
ch <- WatchEvent{
|
||||||
|
NewRev: watchEvent.Header.Revision,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ch <- WatchEvent{
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
}
|
186
etcdb.go
Normal file
186
etcdb.go
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
package etcdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Prefix(names ...string) string {
|
||||||
|
return path.Join(names...) + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
type Spec interface {
|
||||||
|
In(ctx context.Context) DB
|
||||||
|
}
|
||||||
|
|
||||||
|
type DB interface {
|
||||||
|
Get(key string) (value []byte, ok bool, err error)
|
||||||
|
Put(key string, value []byte) error
|
||||||
|
Del(key string) error
|
||||||
|
ForEach(callback func(key string, value []byte) (cont bool)) error
|
||||||
|
Watch(rev int64) <-chan WatchEvent
|
||||||
|
}
|
||||||
|
|
||||||
|
type WatchEvent struct {
|
||||||
|
Err error
|
||||||
|
Key string
|
||||||
|
Value []byte
|
||||||
|
Delete bool
|
||||||
|
NewRev int64
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypedDB[T any] struct {
|
||||||
|
DB DB
|
||||||
|
Codec Codec
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypedWatchEvent[T any] struct {
|
||||||
|
Err error
|
||||||
|
Key string
|
||||||
|
Value T
|
||||||
|
Delete bool
|
||||||
|
NewRev int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *TypedWatchEvent[T]) FromEvent(evt WatchEvent) {
|
||||||
|
e.Err = evt.Err
|
||||||
|
e.Key = evt.Key
|
||||||
|
e.Delete = evt.Delete
|
||||||
|
e.NewRev = evt.NewRev
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tdb TypedDB[T]) Get(key string) (v T, ok bool, err error) {
|
||||||
|
raw, ok, err := tdb.DB.Get(key)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tdb.Codec.Decode(raw, &v)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("invalid value: %w", err)
|
||||||
|
ok = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ok = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tdb TypedDB[T]) Put(key string, value T) (err error) {
|
||||||
|
ba, err := tdb.Codec.Encode(value)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("failed to encode value: %w", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return tdb.DB.Put(key, ba)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tdb TypedDB[T]) Del(key string) error {
|
||||||
|
return tdb.DB.Del(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tdb TypedDB[T]) ForEach(callback func(key string, value T) (cont bool)) (err error) {
|
||||||
|
forEachErr := tdb.DB.ForEach(func(key string, encodedValue []byte) (cont bool) {
|
||||||
|
value := new(T)
|
||||||
|
if err := tdb.Codec.Decode(encodedValue, value); err != nil {
|
||||||
|
err = fmt.Errorf("invalid value at %q: %w", key, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(key, *value)
|
||||||
|
})
|
||||||
|
|
||||||
|
if err == nil && forEachErr != nil {
|
||||||
|
err = forEachErr
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tdb TypedDB[T]) Watch(rev int64) <-chan TypedWatchEvent[T] {
|
||||||
|
ch := make(chan TypedWatchEvent[T], 1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer close(ch)
|
||||||
|
|
||||||
|
inCh := tdb.DB.Watch(rev)
|
||||||
|
|
||||||
|
for evt := range inCh {
|
||||||
|
tevt := TypedWatchEvent[T]{}
|
||||||
|
tevt.FromEvent(evt)
|
||||||
|
|
||||||
|
if len(evt.Value) == 0 {
|
||||||
|
ch <- tevt
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
value := new(T)
|
||||||
|
if err := tdb.Codec.Decode(evt.Value, value); err != nil {
|
||||||
|
tevt.Err = fmt.Errorf("invalid value: %w", err)
|
||||||
|
ch <- tevt
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
tevt.Value = *value
|
||||||
|
ch <- tevt
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tdb TypedDB[T]) Sync(allData map[string]T) (err error) {
|
||||||
|
encodedData := map[string][]byte{}
|
||||||
|
|
||||||
|
for k, v := range allData {
|
||||||
|
encodedData[k], err = tdb.Codec.Encode(v)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("failed to encode data[%q]: %w", k, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
seen := make(map[string]bool, len(allData))
|
||||||
|
|
||||||
|
forEachErr := tdb.DB.ForEach(func(key string, v []byte) (cont bool) {
|
||||||
|
seen[key] = true
|
||||||
|
newV, ok := encodedData[key]
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
if !bytes.Equal(newV, v) {
|
||||||
|
err = tdb.DB.Put(key, newV)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = tdb.Del(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err == nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err == nil && forEachErr != nil {
|
||||||
|
err = forEachErr
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// add any missing data
|
||||||
|
for k, v := range encodedData {
|
||||||
|
if seen[k] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = tdb.DB.Put(k, v)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
26
go.mod
Normal file
26
go.mod
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
module novit.tech/direktil/etcdb
|
||||||
|
|
||||||
|
go 1.19
|
||||||
|
|
||||||
|
require (
|
||||||
|
go.etcd.io/etcd/client/v3 v3.5.5
|
||||||
|
golang.org/x/crypto v0.1.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/coreos/go-semver v0.3.0 // indirect
|
||||||
|
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
|
||||||
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
|
go.etcd.io/etcd/api/v3 v3.5.5 // indirect
|
||||||
|
go.etcd.io/etcd/client/pkg/v3 v3.5.5 // indirect
|
||||||
|
go.uber.org/atomic v1.10.0 // indirect
|
||||||
|
go.uber.org/multierr v1.8.0 // indirect
|
||||||
|
go.uber.org/zap v1.23.0 // indirect
|
||||||
|
golang.org/x/net v0.1.0 // indirect
|
||||||
|
golang.org/x/sys v0.1.0 // indirect
|
||||||
|
golang.org/x/text v0.4.0 // indirect
|
||||||
|
google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71 // indirect
|
||||||
|
google.golang.org/grpc v1.50.1 // indirect
|
||||||
|
google.golang.org/protobuf v1.28.1 // indirect
|
||||||
|
)
|
283
go.sum
Normal file
283
go.sum
Normal file
@ -0,0 +1,283 @@
|
|||||||
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
|
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
|
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||||
|
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||||
|
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||||
|
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||||
|
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||||
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
|
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
|
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||||
|
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||||
|
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||||
|
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
|
||||||
|
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||||
|
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
|
github.com/coreos/go-systemd/v22 v22.4.0 h1:y9YHcjnjynCd/DVbg5j9L/33jQM3MxJlbj/zWskzfGU=
|
||||||
|
github.com/coreos/go-systemd/v22 v22.4.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
|
||||||
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
|
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||||
|
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
|
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
|
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
||||||
|
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||||
|
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||||
|
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||||
|
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||||
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
|
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||||
|
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||||
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
|
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||||
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
|
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||||
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
|
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
|
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||||
|
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
||||||
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||||
|
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||||
|
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||||
|
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||||
|
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
|
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
|
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||||
|
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||||
|
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||||
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
|
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
|
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||||
|
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||||
|
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||||
|
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
||||||
|
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
|
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||||
|
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||||
|
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||||
|
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||||
|
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
|
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
|
go.etcd.io/etcd/api/v3 v3.5.5 h1:BX4JIbQ7hl7+jL+g+2j5UAr0o1bctCm6/Ct+ArBGkf0=
|
||||||
|
go.etcd.io/etcd/api/v3 v3.5.5/go.mod h1:KFtNaxGDw4Yx/BA4iPPwevUTAuqcsPxzyX8PHydchN8=
|
||||||
|
go.etcd.io/etcd/client/pkg/v3 v3.5.5 h1:9S0JUVvmrVl7wCF39iTQthdaaNIiAaQbmK75ogO6GU8=
|
||||||
|
go.etcd.io/etcd/client/pkg/v3 v3.5.5/go.mod h1:ggrwbk069qxpKPq8/FKkQ3Xq9y39kbFR4LnKszpRXeQ=
|
||||||
|
go.etcd.io/etcd/client/v3 v3.5.5 h1:q++2WTJbUgpQu4B6hCuT7VkdwaTP7Qz6Daak3WzbrlI=
|
||||||
|
go.etcd.io/etcd/client/v3 v3.5.5/go.mod h1:aApjR4WGlSumpnJ2kloS75h6aHUmAyaPLjHMxpc7E7c=
|
||||||
|
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||||
|
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||||
|
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
|
||||||
|
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||||
|
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||||
|
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||||
|
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
|
||||||
|
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||||
|
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
|
||||||
|
go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY=
|
||||||
|
go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY=
|
||||||
|
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
|
||||||
|
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
|
||||||
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||||
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
|
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
|
||||||
|
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
||||||
|
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
|
||||||
|
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
|
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
|
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||||
|
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||||
|
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||||
|
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
|
||||||
|
google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71 h1:GEgb2jF5zxsFJpJfg9RoDDWm7tiwc/DDSTE2BtLUkXU=
|
||||||
|
google.golang.org/genproto v0.0.0-20221025140454-527a21cfbd71/go.mod h1:9qHF0xnpdSfF6knlcsnpzUu5y+rpwgbvsyGAZPBMg4s=
|
||||||
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
|
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
|
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||||
|
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||||
|
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||||
|
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||||
|
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||||
|
google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k=
|
||||||
|
google.golang.org/grpc v1.50.1 h1:DS/BukOZWp8s6p4Dt/tOaJaTQyPyOoCcrjroHuCeLzY=
|
||||||
|
google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||||
|
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||||
|
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||||
|
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||||
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
|
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||||
|
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
91
hex-db.go
Normal file
91
hex-db.go
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
package etcdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HexDB struct {
|
||||||
|
WrappedDB DB
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ DB = HexDB{}
|
||||||
|
|
||||||
|
func (h HexDB) Get(key string) (value []byte, ok bool, err error) {
|
||||||
|
encodedValue, ok, err := h.WrappedDB.Get(key)
|
||||||
|
if !ok || err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
value = make([]byte, hex.DecodedLen(len(encodedValue)))
|
||||||
|
_, err = hex.Decode(value, encodedValue)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("invalid hex-encoded value: %w", err)
|
||||||
|
ok = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h HexDB) Put(key string, value []byte) (err error) {
|
||||||
|
encodedValue := make([]byte, hex.EncodedLen(len(value)))
|
||||||
|
hex.Encode(encodedValue, value)
|
||||||
|
return h.WrappedDB.Put(key, encodedValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h HexDB) Del(key string) error {
|
||||||
|
return h.WrappedDB.Del(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h HexDB) ForEach(callback func(key string, value []byte) (cont bool)) (err error) {
|
||||||
|
forEachErr := h.WrappedDB.ForEach(func(key string, encodedValue []byte) (cont bool) {
|
||||||
|
value := make([]byte, hex.DecodedLen(len(encodedValue)))
|
||||||
|
_, err = hex.Decode(value, encodedValue)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("invalid hex-encoded value under %q: %w", key, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(key, value)
|
||||||
|
})
|
||||||
|
|
||||||
|
if err == nil && forEachErr != nil {
|
||||||
|
err = forEachErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h HexDB) Watch(rev int64) <-chan WatchEvent {
|
||||||
|
ch := make(chan WatchEvent, 1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer close(ch)
|
||||||
|
|
||||||
|
inCh := h.WrappedDB.Watch(rev)
|
||||||
|
|
||||||
|
for evt := range inCh {
|
||||||
|
if len(evt.Value) == 0 {
|
||||||
|
ch <- evt
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
value := make([]byte, hex.DecodedLen(len(evt.Value)))
|
||||||
|
_, err := hex.Decode(value, evt.Value)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ch <- WatchEvent{
|
||||||
|
Key: evt.Key,
|
||||||
|
Err: fmt.Errorf("invalid hex-encoded value: %w", err),
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
evt.Value = value
|
||||||
|
|
||||||
|
ch <- evt
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
}
|
123
leader/leader.go
Normal file
123
leader/leader.go
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
package leader
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"sync"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.etcd.io/etcd/client/v3/concurrency"
|
||||||
|
|
||||||
|
"novit.tech/direktil/etcdb"
|
||||||
|
)
|
||||||
|
|
||||||
|
var leaderName string
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
panic("failed to get hostname: " + err.Error())
|
||||||
|
}
|
||||||
|
leaderName = hostname
|
||||||
|
|
||||||
|
flag.StringVar(&leaderName, "leader-name", leaderName, "leader name in leader election")
|
||||||
|
}
|
||||||
|
|
||||||
|
type Spec struct {
|
||||||
|
Etcd *etcdb.ClientSpec
|
||||||
|
Election string
|
||||||
|
OnLeader func(ctx context.Context)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunProcess is design for processes that are a single leader. Binds signals to exit gracefully.
|
||||||
|
func (spec *Spec) RunProcess() {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
|
||||||
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
|
s := <-c
|
||||||
|
|
||||||
|
log.Print("got signal ", s)
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
<-c
|
||||||
|
log.Print("2nd signal, forced exit")
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
|
||||||
|
spec.Run(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec *Spec) Run(ctx context.Context) {
|
||||||
|
for {
|
||||||
|
err := spec.runSession(ctx)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Print("leader election: failed: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (spec *Spec) runSession(ctx context.Context) (err error) {
|
||||||
|
cli := spec.Etcd.Client()
|
||||||
|
|
||||||
|
runCtx, runCancel := context.WithCancel(context.Background())
|
||||||
|
defer runCancel()
|
||||||
|
|
||||||
|
s, err := concurrency.NewSession(
|
||||||
|
cli,
|
||||||
|
concurrency.WithTTL(5),
|
||||||
|
concurrency.WithContext(runCtx),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to start leader election: %v", err)
|
||||||
|
}
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
election := concurrency.NewElection(s, spec.Election)
|
||||||
|
|
||||||
|
log.Print("leader election: waiting to become leader")
|
||||||
|
if err := election.Campaign(ctx, leaderName); err != nil {
|
||||||
|
return fmt.Errorf("leader election: campaign failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Print("leader election: got leader status")
|
||||||
|
|
||||||
|
leaderCtx, cancel := context.WithCancel(ctx)
|
||||||
|
|
||||||
|
wg := new(sync.WaitGroup)
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
spec.OnLeader(leaderCtx)
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-s.Done():
|
||||||
|
log.Print("leader election: session done")
|
||||||
|
case <-ctx.Done():
|
||||||
|
log.Print("leader election: context cancelled")
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel()
|
||||||
|
log.Print("leader election: waiting for routine")
|
||||||
|
wg.Wait()
|
||||||
|
log.Print("leader election: routine exited")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
13
set.go
Normal file
13
set.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package etcdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SetSpec[T any] struct {
|
||||||
|
Spec Spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p SetSpec[T]) In(ctx context.Context) TypedDB[T] {
|
||||||
|
return TypedDB[T]{p.Spec.In(ctx), JSONCodec}
|
||||||
|
}
|
27
single.go
Normal file
27
single.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package etcdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SingletonSpec[T any] struct {
|
||||||
|
Spec Spec
|
||||||
|
Key string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p SingletonSpec[T]) In(ctx context.Context) Singleton[T] {
|
||||||
|
return Singleton[T]{TypedDB[T]{p.Spec.In(ctx), JSONCodec}, p.Key}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Singleton[T any] struct {
|
||||||
|
db TypedDB[T]
|
||||||
|
key string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Singleton[T]) Get() (v T, ok bool, err error) {
|
||||||
|
return s.db.Get(s.key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Singleton[T]) Set(value T) error {
|
||||||
|
return s.db.Put(s.key, value)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user