From 66d38a6e78f854a5c6d15b3e5f825c1be61017c8 Mon Sep 17 00:00:00 2001 From: Fabrice Aneche Date: Mon, 16 Sep 2024 23:32:58 -0400 Subject: [PATCH] faster CI --- .github/workflows/go.yml | 10 +++++++--- cmd/sshjump/server.go | 10 ++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f3d112d..863677c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -21,15 +21,19 @@ jobs: with: go-version: '1.23' + - name: download vendor + run: go mod vendor + - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: version: v1.60.3 - + args: --timeout=5m --modules-download-mode=vendor ./... + - name: Test - run: go test -v ./... + run: go test -race -mod=vendor -v ./... - name: Build - run: go build -v ./... + run: go build -mod=vendor -v ./... diff --git a/cmd/sshjump/server.go b/cmd/sshjump/server.go index c3f5e6d..a99ae84 100644 --- a/cmd/sshjump/server.go +++ b/cmd/sshjump/server.go @@ -37,7 +37,7 @@ type Server struct { clientset *kubernetes.Clientset configWatcher *fsnotify.Watcher - mu sync.Mutex + mu sync.RWMutex permissions map[string]Permission } @@ -108,9 +108,11 @@ func (srv *Server) Handler(s ssh.Session) { select {} } +// PermsForUser returns the permissions for a given user. +// It locks the server mutex to ensure safe access to the permissions map. func (srv *Server) PermsForUser(user string) *Permission { - srv.mu.Lock() - defer srv.mu.Unlock() + srv.mu.RLock() + defer srv.mu.RUnlock() // looking for a matching username perm, ok := srv.permissions[user] @@ -326,7 +328,7 @@ func (srv *Server) StartWatchConfig(ctx context.Context, path string) error { if !ok { return } - srv.logger.Error("error watching config file: %v", err) + srv.logger.Error("error watching config file: %v", err.Error()) } } }()