k3s/vendor/github.com/rancher/kine/pkg/server/create.go
Darren Shepherd a005219c5b Update vendor
2019-08-22 09:14:47 -07:00

55 lines
1.3 KiB
Go

package server
import (
"context"
"github.com/coreos/etcd/etcdserver/etcdserverpb"
)
func isCreate(txn *etcdserverpb.TxnRequest) *etcdserverpb.PutRequest {
if len(txn.Compare) == 1 &&
txn.Compare[0].Target == etcdserverpb.Compare_MOD &&
txn.Compare[0].Result == etcdserverpb.Compare_EQUAL &&
txn.Compare[0].GetModRevision() == 0 &&
len(txn.Failure) == 0 &&
len(txn.Success) == 1 &&
txn.Success[0].GetRequestPut() != nil {
return txn.Success[0].GetRequestPut()
}
return nil
}
func (l *LimitedServer) create(ctx context.Context, put *etcdserverpb.PutRequest, txn *etcdserverpb.TxnRequest) (*etcdserverpb.TxnResponse, error) {
if put.IgnoreLease {
return nil, unsupported("ignoreLease")
} else if put.IgnoreValue {
return nil, unsupported("ignoreValue")
} else if put.PrevKv {
return nil, unsupported("prevKv")
}
rev, err := l.backend.Create(ctx, string(put.Key), put.Value, put.Lease)
if err == ErrKeyExists {
return &etcdserverpb.TxnResponse{
Header: txnHeader(rev),
Succeeded: false,
}, nil
} else if err != nil {
return nil, err
}
return &etcdserverpb.TxnResponse{
Header: txnHeader(rev),
Responses: []*etcdserverpb.ResponseOp{
{
Response: &etcdserverpb.ResponseOp_ResponsePut{
ResponsePut: &etcdserverpb.PutResponse{
Header: txnHeader(rev),
},
},
},
},
Succeeded: true,
}, nil
}