wip fs endpoint

This commit is contained in:
Alex Dadgar 2018-01-17 10:07:26 -08:00
parent 993727c28f
commit fea0e69d4f
1 changed files with 34 additions and 0 deletions

34
client/fs_endpoint.go Normal file
View File

@ -0,0 +1,34 @@
package client
import (
"time"
metrics "github.com/armon/go-metrics"
"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/client/structs"
nstructs "github.com/hashicorp/nomad/nomad/structs"
)
// FileSystem endpoint is used for accessing the logs and filesystem of
// allocations.
type FileSystem struct {
c *Client
}
// Stats is used to retrieve the Clients stats.
func (fs *FileSystem) Logs(args *structs.ClientStatsRequest, reply *structs.ClientStatsResponse) error {
defer metrics.MeasureSince([]string{"client", "client_stats", "stats"}, time.Now())
// Check node read permissions
if aclObj, err := fs.c.ResolveToken(args.AuthToken); err != nil {
return err
} else if aclObj != nil {
readfs := aclObj.AllowNsOp(args.Namespace, acl.NamespaceCapabilityReadFS)
logs := aclObj.AllowNsOp(args.Namespace, acl.NamespaceCapabilityReadLogs)
if !readfs && !logs {
return nstructs.ErrPermissionDenied
}
}
return nil
}