mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-26 17:11:13 +02:00
1. gofmt
2. Change if expr syntax to be consist with the rest of Vault code 3. More details on error message
This commit is contained in:
parent
4b709a7a7a
commit
3886d68de3
@ -26,7 +26,7 @@ const (
|
|||||||
type ZookeeperBackend struct {
|
type ZookeeperBackend struct {
|
||||||
path string
|
path string
|
||||||
client *zk.Conn
|
client *zk.Conn
|
||||||
acl []zk.ACL
|
acl []zk.ACL
|
||||||
}
|
}
|
||||||
|
|
||||||
// newZookeeperBackend constructs a Zookeeper backend using the given API client
|
// newZookeeperBackend constructs a Zookeeper backend using the given API client
|
||||||
@ -53,43 +53,41 @@ func newZookeeperBackend(conf map[string]string) (Backend, error) {
|
|||||||
machines = "localhost:2181"
|
machines = "localhost:2181"
|
||||||
}
|
}
|
||||||
|
|
||||||
// zNode owner and schema.
|
// zNode owner and schema.
|
||||||
var owner string
|
var owner string
|
||||||
var schema string
|
var schema string
|
||||||
var schemaAndOwner string
|
var schemaAndOwner string
|
||||||
schemaAndOwner, ok = conf["znode_owner"]
|
schemaAndOwner, ok = conf["znode_owner"]
|
||||||
if !ok {
|
if !ok {
|
||||||
owner = "anyone"
|
owner = "anyone"
|
||||||
schema = "world"
|
schema = "world"
|
||||||
} else {
|
} else {
|
||||||
parsedSchemaAndOwner := strings.SplitN(schemaAndOwner, ":", 2)
|
parsedSchemaAndOwner := strings.SplitN(schemaAndOwner, ":", 2)
|
||||||
if !(len(parsedSchemaAndOwner)==2) {
|
if len(parsedSchemaAndOwner) != 2 {
|
||||||
return nil, fmt.Errorf("znode_owner expected format is 'schema:owner'")
|
return nil, fmt.Errorf("znode_owner expected format is 'schema:owner'")
|
||||||
} else {
|
} else {
|
||||||
schema = parsedSchemaAndOwner[0]
|
schema = parsedSchemaAndOwner[0]
|
||||||
owner = parsedSchemaAndOwner[1]
|
owner = parsedSchemaAndOwner[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
acl := []zk.ACL{{zk.PermAll, schema, owner}}
|
acl := []zk.ACL{{zk.PermAll, schema, owner}}
|
||||||
|
|
||||||
|
|
||||||
// Authnetication info
|
|
||||||
var schemaAndUser string
|
|
||||||
schemaAndUser, ok = conf["auth_info"]
|
|
||||||
if !ok {
|
|
||||||
owner = ""
|
|
||||||
schema = ""
|
|
||||||
} else {
|
|
||||||
parsedSchemaAndUser := strings.SplitN(schemaAndUser, ":", 2)
|
|
||||||
if !(len(parsedSchemaAndUser)==2) {
|
|
||||||
return nil, fmt.Errorf("auth_info expected format is 'schema:auth'")
|
|
||||||
} else {
|
|
||||||
schema = parsedSchemaAndUser[0]
|
|
||||||
owner = parsedSchemaAndUser[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Authnetication info
|
||||||
|
var schemaAndUser string
|
||||||
|
schemaAndUser, ok = conf["auth_info"]
|
||||||
|
if !ok {
|
||||||
|
owner = ""
|
||||||
|
schema = ""
|
||||||
|
} else {
|
||||||
|
parsedSchemaAndUser := strings.SplitN(schemaAndUser, ":", 2)
|
||||||
|
if len(parsedSchemaAndUser) != 2 {
|
||||||
|
return nil, fmt.Errorf("auth_info expected format is 'schema:auth'")
|
||||||
|
} else {
|
||||||
|
schema = parsedSchemaAndUser[0]
|
||||||
|
owner = parsedSchemaAndUser[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to create the ZK client
|
// Attempt to create the ZK client
|
||||||
client, _, err := zk.Connect(strings.Split(machines, ","), time.Second)
|
client, _, err := zk.Connect(strings.Split(machines, ","), time.Second)
|
||||||
@ -97,19 +95,19 @@ func newZookeeperBackend(conf map[string]string) (Backend, error) {
|
|||||||
return nil, fmt.Errorf("client setup failed: %v", err)
|
return nil, fmt.Errorf("client setup failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If auth_info provided - attempt to authenticate
|
// If auth_info provided - attempt to authenticate
|
||||||
if owner != "" {
|
if owner != "" {
|
||||||
err = client.AddAuth(schema, []byte(owner))
|
err = client.AddAuth(schema, []byte(owner))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Zookeeper rejected authentication information provided at auth_info")
|
return nil, fmt.Errorf("Zookeeper rejected authentication information provided at auth_info: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the backend
|
// Setup the backend
|
||||||
c := &ZookeeperBackend{
|
c := &ZookeeperBackend{
|
||||||
path: path,
|
path: path,
|
||||||
client: client,
|
client: client,
|
||||||
acl: acl,
|
acl: acl,
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user