mirror of
https://github.com/status-im/consul.git
synced 2025-02-23 02:48:19 +00:00
add cas
field and wire it from API to backend
This commit is contained in:
parent
37ee7a77a5
commit
733fa10e3c
@ -89,6 +89,15 @@ func (s *HTTPHandlers) ConnectCAConfigurationSet(req *http.Request) (interface{}
|
||||
var args structs.CARequest
|
||||
s.parseDC(req, &args.Datacenter)
|
||||
s.parseToken(req, &args.Token)
|
||||
if casStr := req.URL.Query().Get("cas"); casStr != "" {
|
||||
casVal, err := strconv.ParseUint(casStr, 10, 64)
|
||||
if err != nil {
|
||||
return nil, BadRequestError{
|
||||
Reason: fmt.Sprintf("Request decode failed: %v", err),
|
||||
}
|
||||
}
|
||||
args.Cas = casVal
|
||||
}
|
||||
if err := decodeBody(req.Body, &args.Config); err != nil {
|
||||
return nil, BadRequestError{
|
||||
Reason: fmt.Sprintf("Request decode failed: %v", err),
|
||||
|
@ -423,9 +423,9 @@ func (c *FSM) applyConnectCAOperation(buf []byte, index uint64) interface{} {
|
||||
[]metrics.Label{{Name: "op", Value: string(req.Op)}})
|
||||
switch req.Op {
|
||||
case structs.CAOpSetConfig:
|
||||
if req.Config.ModifyIndex != 0 {
|
||||
if req.Cas != 0 {
|
||||
var emptyResp interface{}
|
||||
err := c.state.CACheckAndSetConfig(index, req.Config.ModifyIndex, req.Config)
|
||||
err := c.state.CACheckAndSetConfig(index, req.Cas, req.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -463,7 +463,7 @@ func (c *FSM) applyConnectCAOperation(buf []byte, index uint64) interface{} {
|
||||
return act
|
||||
}
|
||||
var emptyResp interface{}
|
||||
err = c.state.CACheckAndSetConfig(index+1, req.Config.ModifyIndex, req.Config)
|
||||
err = c.state.CACheckAndSetConfig(index+1, req.Cas, req.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -217,6 +217,7 @@ func (c *CAManager) initializeCAConfig() (*structs.CAConfiguration, error) {
|
||||
req := structs.CARequest{
|
||||
Op: structs.CAOpSetConfig,
|
||||
Config: config,
|
||||
Cas: config.ModifyIndex,
|
||||
}
|
||||
if resp, err := c.delegate.ApplyCARequest(&req); err != nil {
|
||||
return nil, err
|
||||
@ -503,6 +504,7 @@ func (c *CAManager) initializeRootCA(provider ca.Provider, conf *structs.CAConfi
|
||||
req := structs.CARequest{
|
||||
Op: structs.CAOpSetConfig,
|
||||
Config: conf,
|
||||
Cas: conf.ModifyIndex,
|
||||
}
|
||||
if _, err = c.delegate.ApplyCARequest(&req); err != nil {
|
||||
return fmt.Errorf("error persisting provider state: %v", err)
|
||||
@ -760,6 +762,7 @@ func (c *CAManager) persistNewRootAndConfig(provider ca.Provider, newActiveRoot
|
||||
Index: idx,
|
||||
Roots: newRoots,
|
||||
Config: &newConf,
|
||||
Cas: newConf.ModifyIndex,
|
||||
}
|
||||
resp, err := c.delegate.ApplyCARequest(args)
|
||||
if err != nil {
|
||||
@ -1004,6 +1007,7 @@ func (c *CAManager) UpdateConfiguration(args *structs.CARequest) (reterr error)
|
||||
args.Op = structs.CAOpSetRootsAndConfig
|
||||
args.Index = idx
|
||||
args.Config.ModifyIndex = confIdx
|
||||
args.Cas = confIdx
|
||||
args.Roots = newRoots
|
||||
resp, err := c.delegate.ApplyCARequest(args)
|
||||
if err != nil {
|
||||
|
@ -221,6 +221,11 @@ type CARequest struct {
|
||||
// ProviderState is the state for the builtin CA provider.
|
||||
ProviderState *CAConsulProviderState
|
||||
|
||||
// Cas is an int, Specifies to use a Check-And-Set operation.
|
||||
// If the index is 0, Consul will only store the entry if it does not already exist.
|
||||
// If the index is non-zero, the entry is only set if the current index matches the ModifyIndex of that entry
|
||||
Cas uint64
|
||||
|
||||
// WriteRequest is a common struct containing ACL tokens and other
|
||||
// write-related common elements for requests.
|
||||
WriteRequest
|
||||
|
Loading…
x
Reference in New Issue
Block a user