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
|
||||
func upsertTestToken(codec rpc.ClientCodec, masterToken string, datacenter string,
|
||||
tokenModificationFn func(token *structs.ACLToken)) (*structs.ACLToken, error) {
|
||||
func upsertTestTokenInEntMeta(codec rpc.ClientCodec, masterToken string, datacenter string,
|
||||
tokenModificationFn func(token *structs.ACLToken), entMeta *structs.EnterpriseMeta) (*structs.ACLToken, error) {
|
||||
if entMeta == nil {
|
||||
entMeta = structs.DefaultEnterpriseMetaInDefaultPartition()
|
||||
}
|
||||
arg := structs.ACLTokenSetRequest{
|
||||
Datacenter: datacenter,
|
||||
ACLToken: structs.ACLToken{
|
||||
Description: "User token",
|
||||
Local: false,
|
||||
Policies: nil,
|
||||
Description: "User token",
|
||||
Local: false,
|
||||
Policies: nil,
|
||||
EnterpriseMeta: *entMeta,
|
||||
},
|
||||
WriteRequest: structs.WriteRequest{Token: masterToken},
|
||||
}
|
||||
|
@ -5279,15 +5283,21 @@ func upsertTestToken(codec rpc.ClientCodec, masterToken string, datacenter strin
|
|||
return &out, nil
|
||||
}
|
||||
|
||||
func upsertTestTokenWithPolicyRules(codec rpc.ClientCodec, masterToken string, datacenter string, rules string) (*structs.ACLToken, error) {
|
||||
policy, err := upsertTestPolicyWithRules(codec, masterToken, datacenter, rules)
|
||||
func upsertTestToken(codec rpc.ClientCodec, masterToken string, datacenter string,
|
||||
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 {
|
||||
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}}
|
||||
})
|
||||
}, entMeta)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -5295,6 +5305,10 @@ func upsertTestTokenWithPolicyRules(codec rpc.ClientCodec, masterToken string, d
|
|||
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) {
|
||||
arg := structs.ACLTokenGetRequest{
|
||||
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) {
|
||||
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) {
|
||||
if entMeta == nil {
|
||||
entMeta = structs.DefaultEnterpriseMetaInDefaultPartition()
|
||||
}
|
||||
policy.Rules = rules
|
||||
policy.EnterpriseMeta = *entMeta
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,10 @@ type KVPair struct {
|
|||
// Namespace is the namespace the KVPair is associated with
|
||||
// Namespacing is a Consul Enterprise feature.
|
||||
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
|
||||
|
|
|
@ -153,6 +153,7 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
CreateIndex: ret.Results[0].KV.CreateIndex,
|
||||
ModifyIndex: ret.Results[0].KV.ModifyIndex,
|
||||
Namespace: ret.Results[0].KV.Namespace,
|
||||
Partition: defaultPartition,
|
||||
},
|
||||
},
|
||||
&TxnResult{
|
||||
|
@ -164,6 +165,7 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
CreateIndex: ret.Results[1].KV.CreateIndex,
|
||||
ModifyIndex: ret.Results[1].KV.ModifyIndex,
|
||||
Namespace: ret.Results[0].KV.Namespace,
|
||||
Partition: defaultPartition,
|
||||
},
|
||||
},
|
||||
&TxnResult{
|
||||
|
@ -264,6 +266,7 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
CreateIndex: ret.Results[0].KV.CreateIndex,
|
||||
ModifyIndex: ret.Results[0].KV.ModifyIndex,
|
||||
Namespace: ret.Results[0].KV.Namespace,
|
||||
Partition: defaultPartition,
|
||||
},
|
||||
},
|
||||
&TxnResult{
|
||||
|
|
|
@ -199,6 +199,9 @@ func prettyKVPair(w io.Writer, pair *api.KVPair, base64EncodeValue bool) error {
|
|||
} else {
|
||||
fmt.Fprintf(tw, "Session\t%s\n", pair.Session)
|
||||
}
|
||||
if pair.Partition != "" {
|
||||
fmt.Fprintf(tw, "Partition\t%s\n", pair.Partition)
|
||||
}
|
||||
if pair.Namespace != "" {
|
||||
fmt.Fprintf(tw, "Namespace\t%s\n", pair.Namespace)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ type Entry struct {
|
|||
Flags uint64 `json:"flags"`
|
||||
Value string `json:"value"`
|
||||
Namespace string `json:"namespace,omitempty"`
|
||||
Partition string `json:"partition,omitempty"`
|
||||
}
|
||||
|
||||
func ToEntry(pair *api.KVPair) *Entry {
|
||||
|
@ -19,5 +20,6 @@ func ToEntry(pair *api.KVPair) *Entry {
|
|||
Flags: pair.Flags,
|
||||
Value: base64.StdEncoding.EncodeToString(pair.Value),
|
||||
Namespace: pair.Namespace,
|
||||
Partition: pair.Partition,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue