mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-24 01:17:56 +08:00
a90b777ff4
An etcd cluster is not necessarily only dedicated to seaweedfs. This security enhancement adds a customizable key_prefix option to the etcd filer store. This will allow an etcd cluster administrator to limit the seaweedfs etcd user to only read/write a subset of keys under the key_prefix, instead of all keys on the etcd cluster.
45 lines
894 B
Go
45 lines
894 B
Go
package etcd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
)
|
|
|
|
func (store *EtcdStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
|
|
|
|
_, err = store.client.Put(ctx, store.etcdKeyPrefix + string(key), string(value))
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("kv put: %v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (store *EtcdStore) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
|
|
|
|
resp, err := store.client.Get(ctx, store.etcdKeyPrefix + string(key))
|
|
|
|
if err != nil {
|
|
return nil, fmt.Errorf("kv get: %v", err)
|
|
}
|
|
|
|
if len(resp.Kvs) == 0 {
|
|
return nil, filer.ErrKvNotFound
|
|
}
|
|
|
|
return resp.Kvs[0].Value, nil
|
|
}
|
|
|
|
func (store *EtcdStore) KvDelete(ctx context.Context, key []byte) (err error) {
|
|
|
|
_, err = store.client.Delete(ctx, store.etcdKeyPrefix + string(key))
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("kv delete: %v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|