mirror of https://github.com/status-im/consul.git
KV refactoring, part 2 (#11512)
* add partition to the kv get pretty print * fix failing test * add test for kvs RPC endpoint
This commit is contained in:
parent
520cb5858c
commit
98735a6d12
|
@ -5248,14 +5248,18 @@ func TestValidateBindingRuleBindName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// upsertTestToken creates a token for testing purposes
|
// upsertTestToken creates a token for testing purposes
|
||||||
func upsertTestToken(codec rpc.ClientCodec, masterToken string, datacenter string,
|
func upsertTestTokenInEntMeta(codec rpc.ClientCodec, masterToken string, datacenter string,
|
||||||
tokenModificationFn func(token *structs.ACLToken)) (*structs.ACLToken, error) {
|
tokenModificationFn func(token *structs.ACLToken), entMeta *structs.EnterpriseMeta) (*structs.ACLToken, error) {
|
||||||
|
if entMeta == nil {
|
||||||
|
entMeta = structs.DefaultEnterpriseMetaInDefaultPartition()
|
||||||
|
}
|
||||||
arg := structs.ACLTokenSetRequest{
|
arg := structs.ACLTokenSetRequest{
|
||||||
Datacenter: datacenter,
|
Datacenter: datacenter,
|
||||||
ACLToken: structs.ACLToken{
|
ACLToken: structs.ACLToken{
|
||||||
Description: "User token",
|
Description: "User token",
|
||||||
Local: false,
|
Local: false,
|
||||||
Policies: nil,
|
Policies: nil,
|
||||||
|
EnterpriseMeta: *entMeta,
|
||||||
},
|
},
|
||||||
WriteRequest: structs.WriteRequest{Token: masterToken},
|
WriteRequest: structs.WriteRequest{Token: masterToken},
|
||||||
}
|
}
|
||||||
|
@ -5279,15 +5283,21 @@ func upsertTestToken(codec rpc.ClientCodec, masterToken string, datacenter strin
|
||||||
return &out, nil
|
return &out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func upsertTestTokenWithPolicyRules(codec rpc.ClientCodec, masterToken string, datacenter string, rules string) (*structs.ACLToken, error) {
|
func upsertTestToken(codec rpc.ClientCodec, masterToken string, datacenter string,
|
||||||
policy, err := upsertTestPolicyWithRules(codec, masterToken, datacenter, rules)
|
tokenModificationFn func(token *structs.ACLToken)) (*structs.ACLToken, error) {
|
||||||
|
return upsertTestTokenInEntMeta(codec, masterToken, datacenter,
|
||||||
|
tokenModificationFn, structs.DefaultEnterpriseMetaInDefaultPartition())
|
||||||
|
}
|
||||||
|
|
||||||
|
func upsertTestTokenWithPolicyRulesInEntMeta(codec rpc.ClientCodec, masterToken string, datacenter string, rules string, entMeta *structs.EnterpriseMeta) (*structs.ACLToken, error) {
|
||||||
|
policy, err := upsertTestPolicyWithRulesInEntMeta(codec, masterToken, datacenter, rules, entMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := upsertTestToken(codec, masterToken, datacenter, func(token *structs.ACLToken) {
|
token, err := upsertTestTokenInEntMeta(codec, masterToken, datacenter, func(token *structs.ACLToken) {
|
||||||
token.Policies = []structs.ACLTokenPolicyLink{{ID: policy.ID}}
|
token.Policies = []structs.ACLTokenPolicyLink{{ID: policy.ID}}
|
||||||
})
|
}, entMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -5295,6 +5305,10 @@ func upsertTestTokenWithPolicyRules(codec rpc.ClientCodec, masterToken string, d
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func upsertTestTokenWithPolicyRules(codec rpc.ClientCodec, masterToken string, datacenter string, rules string) (*structs.ACLToken, error) {
|
||||||
|
return upsertTestTokenWithPolicyRulesInEntMeta(codec, masterToken, datacenter, rules, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func retrieveTestTokenAccessorForSecret(codec rpc.ClientCodec, masterToken string, datacenter string, id string) (string, error) {
|
func retrieveTestTokenAccessorForSecret(codec rpc.ClientCodec, masterToken string, datacenter string, id string) (string, error) {
|
||||||
arg := structs.ACLTokenGetRequest{
|
arg := structs.ACLTokenGetRequest{
|
||||||
TokenID: id,
|
TokenID: id,
|
||||||
|
@ -5402,8 +5416,16 @@ func upsertTestPolicy(codec rpc.ClientCodec, masterToken string, datacenter stri
|
||||||
}
|
}
|
||||||
|
|
||||||
func upsertTestPolicyWithRules(codec rpc.ClientCodec, masterToken string, datacenter string, rules string) (*structs.ACLPolicy, error) {
|
func upsertTestPolicyWithRules(codec rpc.ClientCodec, masterToken string, datacenter string, rules string) (*structs.ACLPolicy, error) {
|
||||||
|
return upsertTestPolicyWithRulesInEntMeta(codec, masterToken, datacenter, rules, structs.DefaultEnterpriseMetaInDefaultPartition())
|
||||||
|
}
|
||||||
|
|
||||||
|
func upsertTestPolicyWithRulesInEntMeta(codec rpc.ClientCodec, masterToken string, datacenter string, rules string, entMeta *structs.EnterpriseMeta) (*structs.ACLPolicy, error) {
|
||||||
return upsertTestCustomizedPolicy(codec, masterToken, datacenter, func(policy *structs.ACLPolicy) {
|
return upsertTestCustomizedPolicy(codec, masterToken, datacenter, func(policy *structs.ACLPolicy) {
|
||||||
|
if entMeta == nil {
|
||||||
|
entMeta = structs.DefaultEnterpriseMetaInDefaultPartition()
|
||||||
|
}
|
||||||
policy.Rules = rules
|
policy.Rules = rules
|
||||||
|
policy.EnterpriseMeta = *entMeta
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,10 @@ type KVPair struct {
|
||||||
// Namespace is the namespace the KVPair is associated with
|
// Namespace is the namespace the KVPair is associated with
|
||||||
// Namespacing is a Consul Enterprise feature.
|
// Namespacing is a Consul Enterprise feature.
|
||||||
Namespace string `json:",omitempty"`
|
Namespace string `json:",omitempty"`
|
||||||
|
|
||||||
|
// Partition is the partition the KVPair is associated with
|
||||||
|
// Admin Partition is a Consul Enterprise feature.
|
||||||
|
Partition string `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// KVPairs is a list of KVPair objects
|
// KVPairs is a list of KVPair objects
|
||||||
|
|
|
@ -153,6 +153,7 @@ func TestAPI_ClientTxn(t *testing.T) {
|
||||||
CreateIndex: ret.Results[0].KV.CreateIndex,
|
CreateIndex: ret.Results[0].KV.CreateIndex,
|
||||||
ModifyIndex: ret.Results[0].KV.ModifyIndex,
|
ModifyIndex: ret.Results[0].KV.ModifyIndex,
|
||||||
Namespace: ret.Results[0].KV.Namespace,
|
Namespace: ret.Results[0].KV.Namespace,
|
||||||
|
Partition: defaultPartition,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&TxnResult{
|
&TxnResult{
|
||||||
|
@ -164,6 +165,7 @@ func TestAPI_ClientTxn(t *testing.T) {
|
||||||
CreateIndex: ret.Results[1].KV.CreateIndex,
|
CreateIndex: ret.Results[1].KV.CreateIndex,
|
||||||
ModifyIndex: ret.Results[1].KV.ModifyIndex,
|
ModifyIndex: ret.Results[1].KV.ModifyIndex,
|
||||||
Namespace: ret.Results[0].KV.Namespace,
|
Namespace: ret.Results[0].KV.Namespace,
|
||||||
|
Partition: defaultPartition,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&TxnResult{
|
&TxnResult{
|
||||||
|
@ -264,6 +266,7 @@ func TestAPI_ClientTxn(t *testing.T) {
|
||||||
CreateIndex: ret.Results[0].KV.CreateIndex,
|
CreateIndex: ret.Results[0].KV.CreateIndex,
|
||||||
ModifyIndex: ret.Results[0].KV.ModifyIndex,
|
ModifyIndex: ret.Results[0].KV.ModifyIndex,
|
||||||
Namespace: ret.Results[0].KV.Namespace,
|
Namespace: ret.Results[0].KV.Namespace,
|
||||||
|
Partition: defaultPartition,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&TxnResult{
|
&TxnResult{
|
||||||
|
|
|
@ -199,6 +199,9 @@ func prettyKVPair(w io.Writer, pair *api.KVPair, base64EncodeValue bool) error {
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(tw, "Session\t%s\n", pair.Session)
|
fmt.Fprintf(tw, "Session\t%s\n", pair.Session)
|
||||||
}
|
}
|
||||||
|
if pair.Partition != "" {
|
||||||
|
fmt.Fprintf(tw, "Partition\t%s\n", pair.Partition)
|
||||||
|
}
|
||||||
if pair.Namespace != "" {
|
if pair.Namespace != "" {
|
||||||
fmt.Fprintf(tw, "Namespace\t%s\n", pair.Namespace)
|
fmt.Fprintf(tw, "Namespace\t%s\n", pair.Namespace)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ type Entry struct {
|
||||||
Flags uint64 `json:"flags"`
|
Flags uint64 `json:"flags"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
Namespace string `json:"namespace,omitempty"`
|
Namespace string `json:"namespace,omitempty"`
|
||||||
|
Partition string `json:"partition,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToEntry(pair *api.KVPair) *Entry {
|
func ToEntry(pair *api.KVPair) *Entry {
|
||||||
|
@ -19,5 +20,6 @@ func ToEntry(pair *api.KVPair) *Entry {
|
||||||
Flags: pair.Flags,
|
Flags: pair.Flags,
|
||||||
Value: base64.StdEncoding.EncodeToString(pair.Value),
|
Value: base64.StdEncoding.EncodeToString(pair.Value),
|
||||||
Namespace: pair.Namespace,
|
Namespace: pair.Namespace,
|
||||||
|
Partition: pair.Partition,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue