Skip to content

Commit bf5364b

Browse files
authored
Final fixes before release (#16)
* Fixes to DB * Add WithTeamDirectory() option to client/servers * Fix version printing and add method to team.Client interface. * Move transports to example directory * Print daemon listening status * Fix log level not printed in status * Add some stuff to README * Add more to README * README * Add code examples to readme * README * README Examples * README * Differences with Hashicorp plugins * Add README to example * README * README * Update ncruces/sqlite dependencies * Use go1.21 in actions * Fix cgo build * Try to fix actions CodeQL * Tidy comments * Tidy comments * Cleanup and comments tidying * Fix actions * Remove logging of cleartext credentials * Fix imports * Fix client imports * Fix and restructure imports * Fix windows action * Finish server examples code * Fix imports and update survey version * Fix imports AGAIN * Fix wrong server configs directory usage * Fixes to security alerts
1 parent bf208c2 commit bf5364b

File tree

10 files changed

+38
-31
lines changed

10 files changed

+38
-31
lines changed

example/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ number of transport/RPC listener/server backends to your core application teamse
5858
RPC backend. This file is good in that it shows you clearly how to use the teamserver as a core
5959
driver for any application-specific teamserving process. For example it shows how to query the
6060
teamserver users, request their connection/token credentials, authenticate them, and log all steps
61-
with the teamserver loggers.
61+
with the teamserver loggers.
6262
4) `transports/grpc/server/middleware.go` shows a quite complex but secure use of gRPC middleware using
6363
the teamserver authentication and logging toolset. Note that gRPC is a quite beefy stack, and not
6464
very idiomatic for Go. Don't be too scared at this code if you don't understand it at first, since

internal/certs/certs.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ import (
3636
"path/filepath"
3737
"time"
3838

39-
"github.com/sirupsen/logrus"
40-
"gorm.io/gorm"
41-
4239
"github.com/reeflective/team/internal/assets"
4340
"github.com/reeflective/team/internal/db"
41+
"github.com/sirupsen/logrus"
42+
"gorm.io/gorm"
4443
)
4544

4645
const (
@@ -90,8 +89,8 @@ func NewManager(filesystem *assets.FS, db *gorm.DB, logger *logrus.Entry, appNam
9089
return certs
9190
}
9291

93-
func (m *Manager) db() *gorm.DB {
94-
return m.database.Session(&gorm.Session{
92+
func (c *Manager) db() *gorm.DB {
93+
return c.database.Session(&gorm.Session{
9594
FullSaveAssociations: true,
9695
})
9796
}

internal/log/cli.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ const (
4141
fieldPackage = "logger"
4242
fieldMessage = "message"
4343

44-
PackageFieldKey = "teamserver_pkg"
45-
4644
minimumPackagePad = 11
4745
)
4846

47+
// PackageFieldKey is used to identify the name of the package
48+
// specified by teamclients and teamservers named loggers.
49+
const PackageFieldKey = "teamserver_pkg"
50+
4951
// stdioHook combines a stdout hook (info/debug/trace),
5052
// and a stderr hook (warn/error/fatal/panic).
5153
type stdioHook struct {

internal/log/log.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ import (
2323
"io"
2424
"path/filepath"
2525

26-
"github.com/sirupsen/logrus"
27-
2826
"github.com/reeflective/team/internal/assets"
27+
"github.com/sirupsen/logrus"
2928
)
3029

3130
const (

server/config.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ import (
2727
"path/filepath"
2828
"time"
2929

30-
"github.com/sirupsen/logrus"
31-
3230
"github.com/reeflective/team/internal/assets"
3331
"github.com/reeflective/team/internal/command"
32+
"github.com/sirupsen/logrus"
3433
)
3534

3635
const (
@@ -78,15 +77,14 @@ type Config struct {
7877

7978
// ConfigPath returns the path to the server config.json file, on disk or in-memory.
8079
func (ts *Server) ConfigPath() string {
81-
appDir := ts.TeamDir()
82-
configDir := filepath.Join(appDir, "configs")
80+
appDir := ts.ConfigsDir()
8381

84-
err := ts.fs.MkdirAll(configDir, assets.DirPerm)
82+
err := ts.fs.MkdirAll(appDir, assets.DirPerm)
8583
if err != nil {
86-
ts.log().Errorf("cannot write to %s config dir: %s", configDir, err)
84+
ts.log().Errorf("cannot write to %s config dir: %s", appDir, err)
8785
}
8886

89-
serverConfigPath := filepath.Join(configDir, fmt.Sprintf("%s.%s", ts.Name(), command.ServerConfigExt))
87+
serverConfigPath := filepath.Join(appDir, fmt.Sprintf("%s.%s", ts.Name(), command.ServerConfigExt))
9088

9189
return serverConfigPath
9290
}

server/core.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ import (
2424
"runtime"
2525
"sync"
2626

27-
"github.com/sirupsen/logrus"
28-
"gorm.io/gorm"
29-
3027
"github.com/reeflective/team"
3128
"github.com/reeflective/team/client"
3229
"github.com/reeflective/team/internal/assets"
3330
"github.com/reeflective/team/internal/certs"
3431
"github.com/reeflective/team/internal/db"
3532
"github.com/reeflective/team/internal/version"
33+
"github.com/sirupsen/logrus"
34+
"gorm.io/gorm"
3635
)
3736

3837
// Server is the core driver of an application teamserver.
@@ -160,14 +159,14 @@ func (ts *Server) Self(opts ...client.Options) *client.Client {
160159
return teamclient
161160
}
162161

163-
// Version implements team.Client.VersionClient() interface
162+
// VersionClient implements team.Client.VersionClient() interface
164163
// method, so that the teamserver can be a teamclient of itself.
165164
// This simply returns the server.VersionServer() output.
166165
func (ts *Server) VersionClient() (team.Version, error) {
167166
return ts.VersionServer()
168167
}
169168

170-
// Version returns the teamserver binary version information.
169+
// VersionServe returns the teamserver binary version information.
171170
func (ts *Server) VersionServer() (team.Version, error) {
172171
semVer := version.Semantic()
173172
compiled, _ := version.Compiled()

server/db.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ import (
2525
"path"
2626
"path/filepath"
2727

28-
"gorm.io/gorm"
29-
3028
"github.com/reeflective/team/internal/assets"
3129
"github.com/reeflective/team/internal/command"
3230
"github.com/reeflective/team/internal/db"
31+
"gorm.io/gorm"
3332
)
3433

3534
const (
@@ -62,7 +61,7 @@ func (ts *Server) DatabaseConfig() *db.Config {
6261

6362
// GetDatabaseConfigPath - File path to config.json.
6463
func (ts *Server) dbConfigPath() string {
65-
appDir := ts.ConfigPath()
64+
appDir := ts.ConfigsDir()
6665
log := ts.NamedLogger("config", "database")
6766
dbFileName := fmt.Sprintf("%s.%s", ts.Name()+"_database", command.ServerConfigExt)
6867
databaseConfigPath := filepath.Join(appDir, dbFileName)

server/directories.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (ts *Server) TeamDir() string {
6767
return dir
6868
}
6969

70-
// LogsDir returns the directory of the client (~/.app-server/logs), creating
70+
// LogsDir returns the log directory of the server (~/.app-server/logs), creating
7171
// the directory if needed, or logging a fatal event if failing to create it.
7272
func (ts *Server) LogsDir() string {
7373
logDir := path.Join(ts.TeamDir(), assets.DirLogs)
@@ -80,6 +80,19 @@ func (ts *Server) LogsDir() string {
8080
return logDir
8181
}
8282

83+
// Configs returns the configs directory of the server (~/.app-server/logs), creating
84+
// the directory if needed, or logging a fatal event if failing to create it.
85+
func (ts *Server) ConfigsDir() string {
86+
logDir := path.Join(ts.TeamDir(), assets.DirConfigs)
87+
88+
err := ts.fs.MkdirAll(logDir, assets.DirPerm)
89+
if err != nil {
90+
ts.log().Errorf("cannot write to %s root dir: %s", logDir, err)
91+
}
92+
93+
return logDir
94+
}
95+
8396
// CertificatesDir returns the directory storing users CA PEM files as backup,
8497
// (~/.app/teamserver/certs), either on-disk or in-memory if the teamserver is.
8598
func (ts *Server) CertificatesDir() string {

server/log.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ import (
2222
"fmt"
2323
"path/filepath"
2424

25-
"github.com/sirupsen/logrus"
26-
2725
"github.com/reeflective/team/internal/log"
26+
"github.com/sirupsen/logrus"
2827
)
2928

3029
// NamedLogger returns a new logging "thread" with two fields (optional)

server/options.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ import (
2323
"os"
2424
"strings"
2525

26-
"github.com/sirupsen/logrus"
27-
"gorm.io/gorm"
28-
2926
"github.com/reeflective/team/internal/assets"
3027
"github.com/reeflective/team/internal/db"
28+
"github.com/sirupsen/logrus"
29+
"gorm.io/gorm"
3130
)
3231

3332
const noTeamdir = "no team subdirectory"

0 commit comments

Comments
 (0)