diff --git a/acl/acl.go b/acl/acl.go index a42698e83b5..f2c97d02a45 100644 --- a/acl/acl.go +++ b/acl/acl.go @@ -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 diff --git a/api/api.go b/api/api.go index bd4b9ec3b93..a3d476d64a5 100644 --- a/api/api.go +++ b/api/api.go @@ -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 diff --git a/nomad/fsm.go b/nomad/fsm.go index fe6c3a5d499..46919aa5c2b 100644 --- a/nomad/fsm.go +++ b/nomad/fsm.go @@ -1239,7 +1239,6 @@ func (s *nomadSnapshot) Persist(sink raft.SnapshotSink) error { sink.Cancel() return err } - return nil } diff --git a/nomad/leader.go b/nomad/leader.go index 2f3e42af6ea..814c167ea3f 100644 --- a/nomad/leader.go +++ b/nomad/leader.go @@ -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 } diff --git a/nomad/leader_oss.go b/nomad/leader_oss.go index e1995d23453..bc82e2c8d39 100644 --- a/nomad/leader_oss.go +++ b/nomad/leader_oss.go @@ -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 } diff --git a/nomad/structs/funcs.go b/nomad/structs/funcs.go index b0fe90080fa..bc57c2804d7 100644 --- a/nomad/structs/funcs.go +++ b/nomad/structs/funcs.go @@ -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 diff --git a/vendor/github.com/hashicorp/go-plugin/README.md b/vendor/github.com/hashicorp/go-plugin/README.md index 53ac65fcfd1..78d354ed23f 100644 --- a/vendor/github.com/hashicorp/go-plugin/README.md +++ b/vendor/github.com/hashicorp/go-plugin/README.md @@ -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 diff --git a/vendor/github.com/hashicorp/go-plugin/client.go b/vendor/github.com/hashicorp/go-plugin/client.go index fc9c70d745f..b912826b200 100644 --- a/vendor/github.com/hashicorp/go-plugin/client.go +++ b/vendor/github.com/hashicorp/go-plugin/client.go @@ -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 { diff --git a/vendor/github.com/hashicorp/go-plugin/server.go b/vendor/github.com/hashicorp/go-plugin/server.go index 781d01110b1..e1543214a52 100644 --- a/vendor/github.com/hashicorp/go-plugin/server.go +++ b/vendor/github.com/hashicorp/go-plugin/server.go @@ -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) } }() diff --git a/vendor/vendor.json b/vendor/vendor.json index 8d05d5f424e..6dc13f8939c 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -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=",