sync acls

This commit is contained in:
Alex Dadgar 2017-09-13 11:38:29 -07:00
parent af60377aad
commit a2363e7583
10 changed files with 69 additions and 32 deletions

View File

@ -122,6 +122,11 @@ func NewACL(management bool, policies []*Policy) (*ACL, error) {
return acl, nil
}
// AllowNsOp is shorthand for AllowNamespaceOperation
func (a *ACL) AllowNsOp(ns string, op string) bool {
return a.AllowNamespaceOperation(ns, op)
}
// AllowNamespaceOperation checks if a given operation is allowed for a namespace
func (a *ACL) AllowNamespaceOperation(ns string, op string) bool {
// Hot path management tokens

View File

@ -106,15 +106,15 @@ type Config struct {
// Region to use. If not provided, the default agent region is used.
Region string
// SecretID to use. This can be overwritten per request.
SecretID string
// Namespace to use. If not provided the default namespace is used.
Namespace string
// httpClient is the client to use. Default will be used if not provided.
httpClient *http.Client
// SecretID to use. This can be overwritten per request.
SecretID string
// HttpAuth is the auth info to use for http access.
HttpAuth *HttpBasicAuth

View File

@ -1239,7 +1239,6 @@ func (s *nomadSnapshot) Persist(sink raft.SnapshotSink) error {
sink.Cancel()
return err
}
return nil
}

View File

@ -205,7 +205,7 @@ func (s *Server) establishLeadership(stopCh chan struct{}) error {
}
// Setup any enterprise systems required.
if err := s.establishEnterpriseLeadership(); err != nil {
if err := s.establishEnterpriseLeadership(stopCh); err != nil {
return err
}

View File

@ -3,7 +3,7 @@
package nomad
// establishEnterpriseLeadership is a no-op on OSS.
func (s *Server) establishEnterpriseLeadership() error {
func (s *Server) establishEnterpriseLeadership(stopCh chan struct{}) error {
return nil
}

View File

@ -17,18 +17,16 @@ import (
// MergeMultierrorWarnings takes job warnings and canonicalize warnings and
// merges them into a returnable string. Both the errors may be nil.
func MergeMultierrorWarnings(warnings, canonicalizeWarnings error) string {
if warnings == nil && canonicalizeWarnings == nil {
func MergeMultierrorWarnings(warnings ...error) string {
if len(warnings) == 0 {
return ""
}
var warningMsg multierror.Error
if canonicalizeWarnings != nil {
multierror.Append(&warningMsg, canonicalizeWarnings)
}
if warnings != nil {
multierror.Append(&warningMsg, warnings)
for _, warn := range warnings {
if warn != nil {
multierror.Append(&warningMsg, warn)
}
}
// Set the formatter

View File

@ -41,7 +41,10 @@ and the plugin can call back into the host process.
**Built-in Logging.** Any plugins that use the `log` standard library
will have log data automatically sent to the host process. The host
process will mirror this output prefixed with the path to the plugin
binary. This makes debugging with plugins simple.
binary. This makes debugging with plugins simple. If the host system
uses [hclog](https://github.com/hashicorp/go-hclog) then the log data
will be structured. If the plugin also uses hclog, logs from the plugin
will be sent to the host hclog and be structured.
**Protocol Versioning.** A very basic "protocol version" is supported that
can be incremented to invalidate any previous plugins. This is useful when

View File

@ -269,8 +269,11 @@ func NewClient(config *ClientConfig) (c *Client) {
}
if config.Logger == nil {
config.Logger = hclog.Default()
config.Logger = config.Logger.ResetNamed("plugin")
config.Logger = hclog.New(&hclog.LoggerOptions{
Output: hclog.DefaultOutput,
Level: hclog.Trace,
Name: "plugin",
})
}
c = &Client{
@ -732,9 +735,31 @@ func (c *Client) logStderr(r io.Reader) {
line, err := bufR.ReadString('\n')
if line != "" {
c.config.Stderr.Write([]byte(line))
line = strings.TrimRightFunc(line, unicode.IsSpace)
c.logger.Named(filepath.Base(c.config.Cmd.Path)).Debug(line)
l := c.logger.Named(filepath.Base(c.config.Cmd.Path))
entry, err := parseJSON(line)
// If output is not JSON format, print directly to Debug
if err != nil {
l.Debug(line)
} else {
out := flattenKVPairs(entry.KVPairs)
l = l.With("timestamp", entry.Timestamp.Format(hclog.TimeFormat))
switch hclog.LevelFromString(entry.Level) {
case hclog.Trace:
l.Trace(entry.Message, out...)
case hclog.Debug:
l.Debug(entry.Message, out...)
case hclog.Info:
l.Info(entry.Message, out...)
case hclog.Warn:
l.Warn(entry.Message, out...)
case hclog.Error:
l.Error(entry.Message, out...)
}
}
}
if err == io.EOF {

View File

@ -14,6 +14,8 @@ import (
"strconv"
"sync/atomic"
"github.com/hashicorp/go-hclog"
"google.golang.org/grpc"
)
@ -55,7 +57,7 @@ type ServeConfig struct {
// Plugins are the plugins that are served.
Plugins map[string]Plugin
// GRPCServer shoudl be non-nil to enable serving the plugins over
// GRPCServer should be non-nil to enable serving the plugins over
// gRPC. This is a function to create the server when needed with the
// given server options. The server options populated by go-plugin will
// be for TLS if set. You may modify the input slice.
@ -79,7 +81,7 @@ func (c *ServeConfig) Protocol() Protocol {
// Serve serves the plugins given by ServeConfig.
//
// Serve doesn't return until the plugin is done being executed. Any
// errors will be outputted to the log.
// errors will be outputted to os.Stderr.
//
// This is the method that plugins should call in their main() functions.
func Serve(opts *ServeConfig) {
@ -104,6 +106,13 @@ func Serve(opts *ServeConfig) {
// Logging goes to the original stderr
log.SetOutput(os.Stderr)
// internal logger to os.Stderr
logger := hclog.New(&hclog.LoggerOptions{
Level: hclog.Trace,
Output: os.Stderr,
JSONFormat: true,
})
// Create our new stdout, stderr files. These will override our built-in
// stdout/stderr so that it works across the stream boundary.
stdout_r, stdout_w, err := os.Pipe()
@ -120,7 +129,7 @@ func Serve(opts *ServeConfig) {
// Register a listener so we can accept a connection
listener, err := serverListener()
if err != nil {
log.Printf("[ERR] plugin: plugin init: %s", err)
logger.Error("plugin init error", "error", err)
return
}
@ -134,7 +143,7 @@ func Serve(opts *ServeConfig) {
if opts.TLSProvider != nil {
tlsConfig, err = opts.TLSProvider()
if err != nil {
log.Printf("[ERR] plugin: plugin tls init: %s", err)
logger.Error("plugin tls init", "error", err)
return
}
}
@ -177,7 +186,7 @@ func Serve(opts *ServeConfig) {
// Initialize the servers
if err := server.Init(); err != nil {
log.Printf("[ERR] plugin: protocol init: %s", err)
logger.Error("protocol init", "error", err)
return
}
@ -190,9 +199,9 @@ func Serve(opts *ServeConfig) {
extra = "|" + extra
}
logger.Debug("plugin address", "network", listener.Addr().Network(), "address", listener.Addr().String())
// Output the address and service name to stdout so that core can bring it up.
log.Printf("[DEBUG] plugin: plugin address: %s %s\n",
listener.Addr().Network(), listener.Addr().String())
fmt.Printf("%d|%d|%s|%s|%s%s\n",
CoreProtocolVersion,
opts.ProtocolVersion,
@ -210,9 +219,7 @@ func Serve(opts *ServeConfig) {
for {
<-ch
newCount := atomic.AddInt32(&count, 1)
log.Printf(
"[DEBUG] plugin: received interrupt signal (count: %d). Ignoring.",
newCount)
logger.Debug("plugin received interrupt signal, ignoring", "count", newCount)
}
}()

6
vendor/vendor.json vendored
View File

@ -788,10 +788,10 @@
"revision": "d30f09973e19c1dfcd120b2d9c4f168e68d6b5d5"
},
{
"checksumSHA1": "n3FFMGGYEdVmtgl7TzGTPkB0VGg=",
"checksumSHA1": "R6me0jVmcT/OPo80Fe0qo5fRwHc=",
"path": "github.com/hashicorp/go-plugin",
"revision": "4e5a3725c607a756be8d35bf3a521c0f9c422666",
"revisionTime": "2017-07-25T21:30:12Z"
"revision": "3e6d191694b5a3a2b99755f31b47fa209e4bcd09",
"revisionTime": "2017-08-28T02:45:49Z"
},
{
"checksumSHA1": "ErJHGU6AVPZM9yoY/xV11TwSjQs=",