From ac9ab4c0b096963fdb05361e9bfe79673ea12ac1 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 10 Apr 2020 15:22:15 -0700 Subject: [PATCH 1/2] Update to match new configuration structure --- api/api.go | 2 +- config/config.go | 15 +++++++++++---- go.mod | 2 -- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/api/api.go b/api/api.go index fefedda..6e1f5b6 100644 --- a/api/api.go +++ b/api/api.go @@ -32,7 +32,7 @@ func (r *PanelRequest) GetClient() *http.Client { func (r *PanelRequest) SetHeaders(req *http.Request) *http.Request { req.Header.Set("Accept", "application/vnd.pterodactyl.v1+json") req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+config.Get().AuthenticationToken) + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s.%s", config.Get().AuthenticationTokenId, config.Get().AuthenticationToken)) return req } diff --git a/config/config.go b/config/config.go index 0326f8e..4a87b1e 100644 --- a/config/config.go +++ b/config/config.go @@ -21,6 +21,17 @@ type Configuration struct { // if the debug flag is passed through the command line arguments. Debug bool + // A unique identifier for this node in the Panel. + Uuid string + + // An identifier for the token which must be included in any requests to the panel + // so that the token can be looked up correctly. + AuthenticationTokenId string `yaml:"token_id"` + + // The token used when performing operations. Requests to this instance must + // validate against it. + AuthenticationToken string `yaml:"token"` + Api ApiConfiguration System SystemConfiguration Docker DockerConfiguration @@ -55,10 +66,6 @@ type Configuration struct { // The location where the panel is running that this daemon should connect to // to collect data and send events. PanelLocation string `yaml:"remote"` - - // The token used when performing operations. Requests to this instance must - // validate against it. - AuthenticationToken string `yaml:"token"` } // Defines basic system configuration settings. diff --git a/go.mod b/go.mod index 38097cf..5399492 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,6 @@ require ( github.com/gbrlsnchs/jwt/v3 v3.0.0-rc.0 github.com/ghodss/yaml v1.0.0 github.com/gin-gonic/gin v1.6.2 - github.com/gogo/protobuf v1.2.1 // indirect github.com/golang/protobuf v1.3.5 // indirect github.com/google/gofuzz v1.1.0 // indirect github.com/google/uuid v1.1.1 @@ -65,7 +64,6 @@ require ( golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect golang.org/x/sys v0.0.0-20200331124033-c3d80250170d // indirect - golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b // indirect gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect From d3cbf96c57378129e3730897702cf781c8947e27 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 10 Apr 2020 16:14:04 -0700 Subject: [PATCH 2/2] Avoid race condition while calculating directory size of server --- server/filesystem.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/filesystem.go b/server/filesystem.go index 02b6e2b..e597269 100644 --- a/server/filesystem.go +++ b/server/filesystem.go @@ -18,6 +18,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "time" ) @@ -170,10 +171,11 @@ func (fs *Filesystem) DirectorySize(dir string) (int64, error) { defer wg.Done() s, _ := fs.DirectorySize(p) - size += s + + atomic.AddInt64(&size, s) }(filepath.Join(cleaned, f.Name())) } else { - size += f.Size() + atomic.AddInt64(&size, f.Size()) } }