open-consul/agent/agentpb/common.go

82 lines
2.0 KiB
Go
Raw Normal View History

Add support for implementing new requests with protobufs instea… (#6502) * Add build system support for protobuf generation This is done generically so that we don’t have to keep updating the makefile to add another proto generation. Note: anything not in the vendor directory and with a .proto extension will be run through protoc if the corresponding namespace.pb.go file is not up to date. If you want to rebuild just a single proto file you can do so with: make proto-rebuild PROTOFILES=<list of proto files to rebuild> Providing the PROTOFILES var will override the default behavior of finding all the .proto files. * Start adding types to the agent/proto package These will be needed for some other work and are by no means comprehensive. * Add ability to resolve/fixup the agentpb.ACLLinks structure in the state store. * Use protobuf marshalling of raft requests instead of msgpack for protoc generated types. This does not change any encoding of existing types. * Removed structs package automatically encoding with protobuf marshalling Instead the caller of raftApply that wants to opt-in to protobuf encoding will have to call `raftApplyProtobuf` * Run update-vendor to fixup modules.txt Nothing changed as far as dependencies go but the ordering of modules in that file depends on the time they are first seen and its not alphabetical. * Rename some things and implement the structs.RPCInfo interface bits agentpb.QueryOptions and agentpb.WriteRequest implement 3 of the 4 RPCInfo funcs and the new TargetDatacenter message type implements the fourth. * Use the right encoding function. * Renamed agent/proto package to agent/agentpb to prevent package name conflicts * Update modules.txt to fix ordering * Change blockingQuery to take in interfaces for the query options and meta * Add %T to error output. * Add/Update some comments
2019-09-20 18:37:22 +00:00
package agentpb
import (
"time"
)
// IsRead is always true for QueryOption
func (q *QueryOptions) IsRead() bool {
return true
}
// AllowStaleRead returns whether a stale read should be allowed
func (q *QueryOptions) AllowStaleRead() bool {
return q.AllowStale
}
// TokenSecret returns the token to be used to authorize the request
func (q *QueryOptions) TokenSecret() string {
return q.Token
}
// GetMinQueryIndex implements the interface necessary to be used
// in a blocking query
func (q *QueryOptions) GetMinQueryIndex() uint64 {
return q.MinQueryIndex
}
// GetMaxQueryTime implements the interface necessary to be used
// in a blocking query
func (q *QueryOptions) GetMaxQueryTime() time.Duration {
return q.MaxQueryTime
}
// GetRequireConsistent implements the interface necessary to be used
// in a blocking query
func (q *QueryOptions) GetRequireConsistent() bool {
return q.RequireConsistent
}
// SetLastContact implements the interface necessary to be used
// in a blocking query
func (q *QueryMeta) SetLastContact(lastContact time.Duration) {
q.LastContact = lastContact
}
// SetKnownLeader implements the interface necessary to be used
// in a blocking query
func (q *QueryMeta) SetKnownLeader(knownLeader bool) {
q.KnownLeader = knownLeader
}
// GetIndex implements the interface necessary to be used
// in a blocking query
func (q *QueryMeta) GetIndex() uint64 {
return q.Index
}
// SetIndex implements the interface necessary to be used
// in a blocking query
func (q *QueryMeta) SetIndex(index uint64) {
q.Index = index
}
// WriteRequest only applies to writes, always false
func (w WriteRequest) IsRead() bool {
return false
}
// AllowStaleRead returns whether a stale read should be allowed
func (w WriteRequest) AllowStaleRead() bool {
return false
}
// TokenSecret returns the token to be used to authorize the request
func (w WriteRequest) TokenSecret() string {
return w.Token
}
func (td TargetDatacenter) RequestDatacenter() string {
return td.Datacenter
}