From cc70182e9ca3ff8e44a336108859b7f33aef7720 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Mon, 5 May 2025 11:02:06 +0200 Subject: [PATCH 1/8] Update README and some dependencies --- README.md | 44 +++++++++++++++++++++++--------------------- client/config.go | 1 - client/options.go | 5 ++--- go.mod | 8 ++++---- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 5c079ca..65d7565 100644 --- a/README.md +++ b/README.md @@ -54,32 +54,14 @@ the library focuses on offering a toolset for "human teaming": that is, treating are either _teamclients_ or _teamservers_ of others, within a defined -generally restricted- team of users, which shall generally be strictly and securely authenticated. ------ -## Components & Terms - -The result consists in 2 Go packages (`client` and `server`) for programs needing to act as: -- A **Team client**: a program, or one of its components, that needs to rely on a "remote" program peer - to serve some functionality that is available to a team of users' tools. The program acting as a - _teamclient_ may do so for things as simple as sending a message to the team, or as complicated as a - compiler backend with which multiple client programs can send data to process and build. -- A **Team server**: The remote, server-side counterpart of the software teamclient. Again, the - teamserver can be doing anything, from simply notifying users' teamclient connections to all the team - all the way to handling very complex and resource-hungry tasks that can only be ran on a server host. - -Throughout this library and its documentation, various words are repeatedly employed: -- _teamclient_ refers to either the client-specific toolset provided by this library - (`team/client.Client` core type) or the software making use of this teamclient code. -- _teamserver_ refers to either the server-specific toolset provided to make a program serve its - functionality remotely, or to the tools embedding this code in order to do so. -- _team tool/s_ might be used to refer to programs using either or all of the library components at - large. - ----- ## CLI (Users) The following extracts assume a program binary named `teamserver`, which is simply the root command of the server-side team code. In this case therefore, the binary program only purpose its to be a -teamserver, with no application-specific logic, (and is therefore quite useless on its own): +teamserver, with no application-specific logic, (and is therefore quite useless on its own). +For example, if your application `cracker` makes use of a teamserver/client, all the following +commands would look like `cracker teamserver daemon`, `cracker teamserver client users`, etc: ``` $ teamserver Manage the application server-side teamserver and users @@ -156,6 +138,26 @@ teamclient users teamclient version ``` +----- +## Components & Terms + +The result consists in 2 Go packages (`client` and `server`) for programs needing to act as: +- A **Team client**: a program, or one of its components, that needs to rely on a "remote" program peer + to serve some functionality that is available to a team of users' tools. The program acting as a + _teamclient_ may do so for things as simple as sending a message to the team, or as complicated as a + compiler backend with which multiple client programs can send data to process and build. +- A **Team server**: The remote, server-side counterpart of the software teamclient. Again, the + teamserver can be doing anything, from simply notifying users' teamclient connections to all the team + all the way to handling very complex and resource-hungry tasks that can only be ran on a server host. + +Throughout this library and its documentation, various words are repeatedly employed: +- _teamclient_ refers to either the client-specific toolset provided by this library + (`team/client.Client` core type) or the software making use of this teamclient code. +- _teamserver_ refers to either the server-specific toolset provided to make a program serve its + functionality remotely, or to the tools embedding this code in order to do so. +- _team tool/s_ might be used to refer to programs using either or all of the library components at + large. + ----- ## API (Developers) diff --git a/client/config.go b/client/config.go index daec0c5..2e6791e 100644 --- a/client/config.go +++ b/client/config.go @@ -30,7 +30,6 @@ import ( "sort" "github.com/AlecAivazis/survey/v2" - "github.com/reeflective/team/internal/assets" "github.com/reeflective/team/internal/certs" "github.com/reeflective/team/internal/command" diff --git a/client/options.go b/client/options.go index 9a321e0..d8cbfd6 100644 --- a/client/options.go +++ b/client/options.go @@ -19,7 +19,6 @@ package client */ import ( - "fmt" "io" "os" "strings" @@ -69,7 +68,7 @@ func (tc *Client) apply(options ...Options) { // set once when created. tc.initOpts.Do(func() { // Application home directory. - homeDir := os.Getenv(fmt.Sprintf("%s_ROOT_DIR", strings.ToUpper(tc.name))) + homeDir := os.Getenv(strings.ToUpper(tc.name) + "_ROOT_DIR") if homeDir != "" { tc.homeDir = homeDir } else { @@ -114,7 +113,7 @@ func WithInMemory() Options { // to connect to, instead of using default on-disk user/application configurations. // This function will be very useful to library users who wish to implement specific // remote teamserver selection & connection strategies, depending on the domains and -// and use cases of these tools. +// use cases of these tools. func WithConfig(config *Config) Options { return func(opts *opts) { opts.config = config diff --git a/go.mod b/go.mod index 2b5d39e..5c890ba 100644 --- a/go.mod +++ b/go.mod @@ -17,10 +17,10 @@ require ( github.com/spf13/pflag v1.0.6 google.golang.org/grpc v1.56.1 google.golang.org/protobuf v1.31.0 - gorm.io/driver/mysql v1.5.1 - gorm.io/driver/postgres v1.5.2 - gorm.io/driver/sqlite v1.5.2 - gorm.io/gorm v1.25.2 + gorm.io/driver/mysql v1.5.7 + gorm.io/driver/postgres v1.5.9 + gorm.io/driver/sqlite v1.5.5 + gorm.io/gorm v1.25.10 modernc.org/sqlite v1.23.1 ) From 4625ebd02068178213b90cf8b59251902f693d93 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Mon, 5 May 2025 14:30:53 +0200 Subject: [PATCH 2/8] Change code to use afero filesystem abstractions --- README.md | 4 +- client/client.go | 8 +-- go.mod | 23 ++++--- go.sum | 64 ++++++++--------- internal/assets/fs.go | 156 +++--------------------------------------- server/core.go | 6 +- server/directories.go | 9 +-- 7 files changed, 67 insertions(+), 203 deletions(-) diff --git a/README.md b/README.md index 65d7565..1f5e09f 100644 --- a/README.md +++ b/README.md @@ -343,8 +343,8 @@ This teamserver library aims to remain small, with a precise behavior and role. Overall, contributions and ideas should revolve around strenghening its core/transport code or around enhancing its interoperability with as much Go code/programs as possible. -- [ ] Use viper for configs. -- [ ] Use afero filesystem. +- [x] Use viper for configs. +- [x] Use afero filesystem. - [ ] Add support for encrypted sqlite by default. - [ ] Encrypt in-memory channels, or add option for it. - [ ] Simpler/different listener/dialer backend interfaces, if it appears needed. diff --git a/client/client.go b/client/client.go index 44be641..23b65a0 100644 --- a/client/client.go +++ b/client/client.go @@ -19,8 +19,6 @@ package client */ import ( - "os/user" - "path/filepath" "runtime" "sync" @@ -122,15 +120,13 @@ func New(app string, client team.Client, options ...Options) (*Client, error) { client: client, connect: &sync.Once{}, mutex: &sync.RWMutex{}, - fs: &assets.FS{}, + // fs: &assets.FS{}, } teamclient.apply(options...) // Filesystem (in-memory or on disk) - user, _ := user.Current() - root := filepath.Join(user.HomeDir, "."+teamclient.name) - teamclient.fs = assets.NewFileSystem(root, teamclient.opts.inMemory) + teamclient.fs = assets.NewFileSystem(teamclient.opts.inMemory) // Logging (if allowed) if err := teamclient.initLogging(); err != nil { diff --git a/go.mod b/go.mod index 5c890ba..fa62d11 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/reeflective/team -go 1.21 +go 1.23.0 + +toolchain go1.24.2 require ( github.com/AlecAivazis/survey/v2 v2.3.7 @@ -13,6 +15,7 @@ require ( github.com/psanford/memfs v0.0.0-20230130182539-4dbf7e3e865e github.com/rsteube/carapace v0.47.4 github.com/sirupsen/logrus v1.9.3 + github.com/spf13/afero v1.14.0 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.6 google.golang.org/grpc v1.56.1 @@ -32,7 +35,8 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/jackc/pgx/v5 v5.3.1 // indirect + github.com/jackc/pgx/v5 v5.5.5 // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect @@ -48,13 +52,14 @@ require ( github.com/rsteube/carapace-shlex v0.1.1 // indirect github.com/stretchr/testify v1.8.2 // indirect github.com/tetratelabs/wazero v1.4.0 // indirect - golang.org/x/crypto v0.8.0 // indirect - golang.org/x/mod v0.11.0 // indirect - golang.org/x/net v0.9.0 // indirect - golang.org/x/sys v0.11.0 // indirect - golang.org/x/term v0.7.0 // indirect - golang.org/x/text v0.12.0 // indirect - golang.org/x/tools v0.6.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.12.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/term v0.20.0 // indirect + golang.org/x/text v0.23.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/uint128 v1.2.0 // indirect diff --git a/go.sum b/go.sum index d3d6811..86e586f 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= @@ -62,8 +62,10 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= -github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= +github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= +github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jedib0t/go-pretty/v6 v6.4.6 h1:v6aG9h6Uby3IusSSEjHaZNXpHFhzqMmjXcPq1Rjl9Jw= github.com/jedib0t/go-pretty/v6 v6.4.6/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= @@ -125,11 +127,11 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA= +github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -160,8 +162,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= -golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -170,8 +172,8 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= -golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -182,8 +184,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= -golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.7.0 h1:qe6s0zUXlPX80/dITx3440hWZ7GwMwgDDyrSGTPJG/g= golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4= @@ -193,8 +195,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= +golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -211,18 +213,18 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= -golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= -golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -233,8 +235,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -269,15 +271,15 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/mysql v1.5.1 h1:WUEH5VF9obL/lTtzjmML/5e6VfFR/788coz2uaVCAZw= -gorm.io/driver/mysql v1.5.1/go.mod h1:Jo3Xu7mMhCyj8dlrb3WoCaRd1FhsVh+yMXb1jUInf5o= -gorm.io/driver/postgres v1.5.2 h1:ytTDxxEv+MplXOfFe3Lzm7SjG09fcdb3Z/c056DTBx0= -gorm.io/driver/postgres v1.5.2/go.mod h1:fmpX0m2I1PKuR7mKZiEluwrP3hbs+ps7JIGMUBpCgl8= -gorm.io/driver/sqlite v1.5.2 h1:TpQ+/dqCY4uCigCFyrfnrJnrW9zjpelWVoEVNy5qJkc= -gorm.io/driver/sqlite v1.5.2/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4= -gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= -gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho= -gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo= +gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= +gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8= +gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= +gorm.io/driver/sqlite v1.5.5 h1:7MDMtUZhV065SilG62E0MquljeArQZNfJnjd9i9gx3E= +gorm.io/driver/sqlite v1.5.5/go.mod h1:6NgQ7sQWAIFsPrJJl1lSNSu2TABh0ZZ/zm5fosATavE= +gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= +gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s= +gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI= diff --git a/internal/assets/fs.go b/internal/assets/fs.go index 8fec1db..e6753a7 100644 --- a/internal/assets/fs.go +++ b/internal/assets/fs.go @@ -19,12 +19,9 @@ package assets */ import ( - "io/fs" "os" - "path/filepath" - "strings" - "github.com/psanford/memfs" + "github.com/spf13/afero" ) const ( @@ -61,151 +58,18 @@ const ( // When either of them are configured to run in memory only, this // filesystem is initialized accordingly, otherwise it will forward // its calls to the on-disk filesystem. -// -// This type currently exists because the stdlib io/fs.FS type is read-only, -// and that in order to provide a unique abstraction to the teamclient/server -// filesystems, this filesystem type adds writing methods. -type FS struct { - mem *memfs.FS - root string -} - -// NewFileSystem returns a new filesystem configured to run on disk or in-memory. -func NewFileSystem(root string, inMemory bool) *FS { - filesystem := &FS{ - root: root, - } +type FS = afero.Afero +// NewFileSystem returns a new filesystem +// configured to run on disk or in-memory. +func NewFileSystem(inMemory bool) *FS { if inMemory { - filesystem.mem = memfs.New() - } - - return filesystem -} - -// MkdirAll creates a directory named path, along with any necessary parents, -// and returns nil, or else returns an error. -// The permission bits perm (before umask) are used for all directories that MkdirAll creates. -// If path is already a directory, MkdirAll does nothing and returns nil. -// -// If the filesystem is in-memory, the teamclient/server application root -// is trimmed from this path, if the latter contains it. -func (f *FS) MkdirAll(path string, perm fs.FileMode) error { - if f.mem == nil { - return os.MkdirAll(path, perm) - } - - path = strings.TrimPrefix(path, f.root) - - return f.mem.MkdirAll(path, perm) -} - -// Sub returns a file system (an fs.FS) for the tree of files rooted at the directory dir, -// or an error if it failed. When the teamclient fs is on disk, os.Stat() and os.DirFS() are used. -// -// If the filesystem is in-memory, the teamclient/server application root -// is trimmed from this path, if the latter contains it. -func (f *FS) Sub(path string) (fs fs.FS, err error) { - if f.mem == nil { - _, err = os.Stat(path) - - return os.DirFS(path), err - } - - path = strings.TrimPrefix(path, f.root) - - return f.mem.Sub(path) -} - -// Open is like fs.Open(). -// -// If the filesystem is in-memory, the teamclient/server application root -// is trimmed from this path, if the latter contains it. -func (f *FS) Open(name string) (fs.File, error) { - if f.mem == nil { - return os.Open(name) - } - - name = strings.TrimPrefix(name, f.root) - - return f.mem.Open(name) -} - -// OpenFile is like os.OpenFile(), but returns a custom *File type implementing -// the io.WriteCloser interface, so that it can be written to and closed more easily. -func (f *FS) OpenFile(name string, flag int, perm fs.FileMode) (*File, error) { - inFile := &File{ - name: name, - } - - if f.mem != nil { - inFile.mem = f.mem - - return inFile, nil - } - - file, err := os.OpenFile(name, flag, perm) - if err != nil { - return nil, err - } - - inFile.file = file - - return inFile, nil -} - -// WriteFile is like os.WriteFile(). -func (f *FS) WriteFile(path string, data []byte, perm fs.FileMode) error { - if f.mem == nil { - return os.WriteFile(path, data, perm) - } - - path = strings.TrimPrefix(path, f.root) - - return f.mem.WriteFile(path, data, perm) -} - -// ReadFile is like os.ReadFile(). -func (f *FS) ReadFile(path string) (b []byte, err error) { - if f.mem == nil { - return os.ReadFile(path) + return &afero.Afero{ + Fs: afero.NewMemMapFs(), + } } - _, err = f.mem.Open(path) - if err != nil { - return + return &afero.Afero{ + Fs: afero.NewOsFs(), } - - return fs.ReadFile(f.mem, path) -} - -// File wraps the *os.File type with some in-memory helpers, -// so that we can write/read to teamserver application files -// regardless of where they are. -// This should disappear if a Write() method set is added to the io/fs package. -type File struct { - name string - file *os.File - mem *memfs.FS -} - -// Write implements the io.Writer interface by writing data either -// to the file on disk, or to an in-memory file. -func (f *File) Write(data []byte) (written int, err error) { - if f.file != nil { - return f.file.Write(data) - } - - fileName := filepath.Base(f.name) - - return len(data), f.mem.WriteFile(fileName, data, FileWritePerm) -} - -// Close implements io.Closer by closing the file on the filesystem. -func (f *File) Close() error { - if f.file != nil { - return f.file.Close() - } - - return nil } diff --git a/server/core.go b/server/core.go index ea9f9a7..b613d5b 100644 --- a/server/core.go +++ b/server/core.go @@ -19,8 +19,6 @@ package server */ import ( - "os/user" - "path/filepath" "runtime" "sync" @@ -112,9 +110,7 @@ func New(application string, options ...Options) (*Server, error) { server.apply(options...) // Filesystem - user, _ := user.Current() - root := filepath.Join(user.HomeDir, "."+server.name) - server.fs = assets.NewFileSystem(root, server.opts.inMemory) + server.fs = assets.NewFileSystem(server.opts.inMemory) // Logging (if allowed) if err := server.initLogging(); err != nil { diff --git a/server/directories.go b/server/directories.go index af75c7b..0b5b87e 100644 --- a/server/directories.go +++ b/server/directories.go @@ -67,8 +67,8 @@ func (ts *Server) TeamDir() string { return dir } -// LogsDir returns the log directory of the server (~/.app-server/logs), creating -// the directory if needed, or logging a fatal event if failing to create it. +// LogsDir returns the log directory of the server (~/.app/teamserver/logs), +// creating the directory if needed, or logging a fatal event if failing to create it. func (ts *Server) LogsDir() string { logDir := path.Join(ts.TeamDir(), assets.DirLogs) @@ -80,8 +80,9 @@ func (ts *Server) LogsDir() string { return logDir } -// Configs returns the configs directory of the server (~/.app-server/logs), creating -// the directory if needed, or logging a fatal event if failing to create it. +// ConfigsDir returns the configs directory of the server +// (~/.app/teamserver/configs), creating the directory if +// needed, or logging a fatal event if failing to create it. func (ts *Server) ConfigsDir() string { logDir := path.Join(ts.TeamDir(), assets.DirConfigs) From 752ad8959d24fca06d1d6da4c4ef4985b8b336cf Mon Sep 17 00:00:00 2001 From: maxlandon Date: Mon, 5 May 2025 15:13:09 +0200 Subject: [PATCH 3/8] Adapt remaining code to use new filesystem utils --- README.md | 1 + client/client.go | 1 - client/directories.go | 17 ++++++++--------- server/commands/teamserver.go | 6 ++---- server/config.go | 36 ++++++----------------------------- server/core.go | 2 +- server/db.go | 20 +++++-------------- server/jobs.go | 2 +- server/log.go | 3 ++- server/server.go | 2 +- server/users.go | 11 +++++------ 11 files changed, 32 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 1f5e09f..8b59b63 100644 --- a/README.md +++ b/README.md @@ -352,4 +352,5 @@ or around enhancing its interoperability with as much Go code/programs as possib - [ ] Replace logrus entirely and restructure behind a single package used by both client/server. - [ ] Review/refine/strenghen the dialer/listener init/close/start process, if it appears needed. - [ ] `teamclient update` downloads latest version of the server binary + method to `team.Client` for it. +- [ ] Implement tests for most sensitive paths (certificates management, database functioning, etc) diff --git a/client/client.go b/client/client.go index 23b65a0..1382fef 100644 --- a/client/client.go +++ b/client/client.go @@ -120,7 +120,6 @@ func New(app string, client team.Client, options ...Options) (*Client, error) { client: client, connect: &sync.Once{}, mutex: &sync.RWMutex{}, - // fs: &assets.FS{}, } teamclient.apply(options...) diff --git a/client/directories.go b/client/directories.go index 8833282..f0db405 100644 --- a/client/directories.go +++ b/client/directories.go @@ -19,6 +19,7 @@ package client */ import ( + "os" "os/user" "path/filepath" @@ -33,15 +34,11 @@ func (tc *Client) HomeDir() string { var dir string // Note: very important not to combine the nested if here. - if !tc.opts.inMemory { - if tc.homeDir == "" { - user, _ := user.Current() - dir = filepath.Join(user.HomeDir, "."+tc.name) - } else { - dir = tc.homeDir - } + if tc.homeDir == "" { + user, _ := user.Current() + dir = filepath.Join(user.HomeDir, "."+tc.name) } else { - dir = "." + tc.name + dir = tc.homeDir } err := tc.fs.MkdirAll(dir, assets.DirPerm) @@ -82,11 +79,13 @@ func (tc *Client) LogsDir() string { // ConfigsDir returns the path to the remote teamserver configs directory // for this application (~/.app/teamclient/configs), creating the directory // if needed, or logging a fatal event if failing to create it. +// +// This uses the on-disk filesystem even if the teamclient is in memory mode. func (tc *Client) ConfigsDir() string { rootDir, _ := filepath.Abs(tc.TeamDir()) dir := filepath.Join(rootDir, assets.DirConfigs) - err := tc.fs.MkdirAll(dir, assets.DirPerm) + err := os.MkdirAll(dir, assets.DirPerm) if err != nil { tc.log().Errorf("cannot write to %s configs dir: %s", dir, err) } diff --git a/server/commands/teamserver.go b/server/commands/teamserver.go index efb6038..5065dec 100644 --- a/server/commands/teamserver.go +++ b/server/commands/teamserver.go @@ -20,8 +20,6 @@ package commands import ( "fmt" - "io/fs" - "os" "path/filepath" "runtime/debug" "strconv" @@ -249,8 +247,8 @@ func statusCmd(serv *server.Server) func(cmd *cobra.Command, args []string) { // Certificate files. certsPath := serv.CertificatesDir() - if dir, err := os.Stat(certsPath); err == nil && dir.IsDir() { - files, err := fs.ReadDir(os.DirFS(certsPath), ".") + if dir, err := serv.Filesystem().Stat(certsPath); err == nil && dir.IsDir() { + files, err := serv.Filesystem().ReadDir(certsPath) if err == nil || len(files) > 0 { fmt.Fprintln(cmd.OutOrStdout(), formatSection("Certificate files")) diff --git a/server/config.go b/server/config.go index 28a5ffb..d76e530 100644 --- a/server/config.go +++ b/server/config.go @@ -77,14 +77,9 @@ type Config struct { // ConfigPath returns the path to the server config.json file, on disk or in-memory. func (ts *Server) ConfigPath() string { - appDir := ts.ConfigsDir() - - err := ts.fs.MkdirAll(appDir, assets.DirPerm) - if err != nil { - ts.log().Errorf("cannot write to %s config dir: %s", appDir, err) - } - - serverConfigPath := filepath.Join(appDir, fmt.Sprintf("%s.%s", ts.Name(), command.ServerConfigExt)) + configsDir := ts.ConfigsDir() + configFile := fmt.Sprintf("%s.%s", ts.Name(), command.ServerConfigExt) + serverConfigPath := filepath.Join(configsDir, configFile) return serverConfigPath } @@ -94,15 +89,11 @@ func (ts *Server) ConfigPath() string { func (ts *Server) GetConfig() *Config { cfgLog := ts.NamedLogger("config", "server") - if ts.opts.inMemory { - return ts.opts.config - } - configPath := ts.ConfigPath() - if _, err := os.Stat(configPath); !os.IsNotExist(err) { + if _, err := ts.fs.Stat(configPath); !os.IsNotExist(err) { cfgLog.Debugf("Loading config from %s", configPath) - data, err := os.ReadFile(configPath) + data, err := ts.fs.ReadFile(configPath) if err != nil { cfgLog.Errorf("Failed to read config file %s", err) return ts.opts.config @@ -139,22 +130,7 @@ func (ts *Server) GetConfig() *Config { func (ts *Server) SaveConfig(cfg *Config) error { cfgLog := ts.NamedLogger("config", "server") - if ts.opts.inMemory { - return nil - } - configPath := ts.ConfigPath() - configDir := filepath.Dir(configPath) - - if _, err := os.Stat(configDir); os.IsNotExist(err) { - cfgLog.Debugf("Creating config dir %s", configDir) - - err := os.MkdirAll(configDir, assets.DirPerm) - if err != nil { - return ts.errorf("%w: %w", ErrConfig, err) - } - } - data, err := json.MarshalIndent(cfg, "", " ") if err != nil { return err @@ -162,7 +138,7 @@ func (ts *Server) SaveConfig(cfg *Config) error { cfgLog.Debugf("Saving config to %s", configPath) - err = os.WriteFile(configPath, data, assets.FileReadPerm) + err = ts.fs.WriteFile(configPath, data, assets.FileReadPerm) if err != nil { return ts.errorf("%w: failed to write config: %s", ErrConfig, err) } diff --git a/server/core.go b/server/core.go index b613d5b..277a3b2 100644 --- a/server/core.go +++ b/server/core.go @@ -195,7 +195,7 @@ func (ts *Server) Users() ([]team.User, error) { } usersDB := []*db.User{} - err := ts.dbSession().Find(&usersDB).Error + err := ts.Database().Find(&usersDB).Error users := make([]team.User, len(usersDB)) diff --git a/server/db.go b/server/db.go index b967784..53591da 100644 --- a/server/db.go +++ b/server/db.go @@ -73,19 +73,15 @@ func (ts *Server) dbConfigPath() string { // Save - Save config file to disk. If the server is configured // to run in-memory only, the config is not saved. func (ts *Server) saveDatabaseConfig(cfg *db.Config) error { - if ts.opts.inMemory { - return nil - } - dblog := ts.NamedLogger("config", "database") configPath := ts.dbConfigPath() configDir := path.Dir(configPath) - if _, err := os.Stat(configDir); os.IsNotExist(err) { + if _, err := ts.fs.Stat(configDir); os.IsNotExist(err) { dblog.Debugf("Creating config dir %s", configDir) - err := os.MkdirAll(configDir, assets.DirPerm) + err := ts.fs.MkdirAll(configDir, assets.DirPerm) if err != nil { return err } @@ -98,7 +94,7 @@ func (ts *Server) saveDatabaseConfig(cfg *db.Config) error { dblog.Debugf("Saving config to %s", configPath) - return os.WriteFile(configPath, data, assets.FileReadPerm) + return ts.fs.WriteFile(configPath, data, assets.FileReadPerm) } // getDatabaseConfig returns a working database configuration, @@ -115,8 +111,8 @@ func (ts *Server) getDatabaseConfig() (*db.Config, error) { } configPath := ts.dbConfigPath() - if _, err := os.Stat(configPath); !os.IsNotExist(err) { - data, err := os.ReadFile(configPath) + if _, err := ts.fs.Stat(configPath); !os.IsNotExist(err) { + data, err := ts.fs.ReadFile(configPath) if err != nil { return nil, fmt.Errorf("Failed to read config file %w", err) } @@ -188,9 +184,3 @@ func (ts *Server) initDatabase() (err error) { return err } - -func (ts *Server) dbSession() *gorm.DB { - return ts.db.Session(&gorm.Session{ - FullSaveAssociations: true, - }) -} diff --git a/server/jobs.go b/server/jobs.go index c2004fe..ff244fa 100644 --- a/server/jobs.go +++ b/server/jobs.go @@ -71,7 +71,7 @@ func (ts *Server) Listeners() []*job { all := []*job{} // Active listeners - ts.jobs.active.Range(func(key, value interface{}) bool { + ts.jobs.active.Range(func(key, value any) bool { all = append(all, value.(*job)) return true }) diff --git a/server/log.go b/server/log.go index 7b1729c..77da552 100644 --- a/server/log.go +++ b/server/log.go @@ -22,8 +22,9 @@ import ( "fmt" "path/filepath" - "github.com/reeflective/team/internal/log" "github.com/sirupsen/logrus" + + "github.com/reeflective/team/internal/log" ) // NamedLogger returns a new logging "thread" with two fields (optional) diff --git a/server/server.go b/server/server.go index 08e24e4..f07536f 100644 --- a/server/server.go +++ b/server/server.go @@ -262,7 +262,7 @@ func (ts *Server) init(opts ...Options) error { // Certificate infrastructure, will make the code panic if unable to work properly. certsLog := ts.NamedLogger("certs", "certificates") - ts.certs = certs.NewManager(ts.fs, ts.dbSession(), certsLog, ts.Name(), ts.TeamDir()) + ts.certs = certs.NewManager(ts.fs, ts.Database(), certsLog, ts.Name(), ts.TeamDir()) }) return err diff --git a/server/users.go b/server/users.go index 58512f4..533576f 100644 --- a/server/users.go +++ b/server/users.go @@ -76,10 +76,9 @@ func (ts *Server) UserCreate(name string, lhost string, lport uint16, perms ...s Name: name, Token: hex.EncodeToString(digest[:]), Permissions: pq.StringArray(perms), - // Permissions: strings.Join(perms, permissionsSep), } - err = ts.dbSession().Save(dbuser).Error + err = ts.Database().Save(dbuser).Error if err != nil { return nil, ts.errorf("%w: %w", ErrDatabase, err) } @@ -123,7 +122,7 @@ func (ts *Server) UserDelete(name string) error { return ts.errorf("%w: %w", ErrDatabase, err) } - err := ts.dbSession().Where(&db.User{ + err := ts.Database().Where(&db.User{ Name: name, }).Delete(&db.User{}).Error if err != nil { @@ -211,7 +210,7 @@ func (ts *Server) UsersTLSConfig() (*tls.Config, error) { _, _, err = ts.certs.UserServerGetCertificate() if errors.Is(err, certs.ErrCertDoesNotExist) { - if _, _, err := ts.certs.UserServerGenerateCertificate(); err != nil { + if _, _, err = ts.certs.UserServerGenerateCertificate(); err != nil { return nil, ts.errorWith(log, "%s", err.Error()) } } @@ -282,7 +281,7 @@ func (ts *Server) userByToken(value string) (*db.User, error) { } user := &db.User{} - err := ts.dbSession().Where(&db.User{ + err := ts.Database().Where(&db.User{ Token: value, }).First(user).Error @@ -291,7 +290,7 @@ func (ts *Server) userByToken(value string) (*db.User, error) { func (ts *Server) updateLastSeen(name string) { lastSeen := time.Now().Round(1 * time.Second) - ts.dbSession().Model(&db.User{}).Where("name", name).Update("LastSeen", lastSeen) + ts.Database().Model(&db.User{}).Where("name", name).Update("LastSeen", lastSeen) } // func TestRootOnlyVerifyCertificate(t *testing.T) { From 2f66476c188b6af9e7271c40ff7485b33375789f Mon Sep 17 00:00:00 2001 From: maxlandon Date: Mon, 5 May 2025 15:22:00 +0200 Subject: [PATCH 4/8] Format imports --- README.md | 1 + client/client.go | 3 ++- client/commands/commands.go | 5 +++-- client/commands/import.go | 5 +++-- client/commands/users.go | 5 +++-- client/commands/version.go | 5 +++-- client/config.go | 1 + client/log.go | 3 ++- client/options.go | 3 ++- internal/certs/certs.go | 5 +++-- internal/log/log.go | 3 ++- server/commands/commands.go | 7 ++++--- server/commands/completers.go | 3 ++- server/commands/teamserver.go | 5 +++-- server/config.go | 3 ++- server/core.go | 5 +++-- server/db.go | 3 ++- server/options.go | 5 +++-- server/users.go | 1 + 19 files changed, 45 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 8b59b63..10573b6 100644 --- a/README.md +++ b/README.md @@ -353,4 +353,5 @@ or around enhancing its interoperability with as much Go code/programs as possib - [ ] Review/refine/strenghen the dialer/listener init/close/start process, if it appears needed. - [ ] `teamclient update` downloads latest version of the server binary + method to `team.Client` for it. - [ ] Implement tests for most sensitive paths (certificates management, database functioning, etc) +- [ ] Update carapace to carapace-sh diff --git a/client/client.go b/client/client.go index 1382fef..38ff03c 100644 --- a/client/client.go +++ b/client/client.go @@ -22,10 +22,11 @@ import ( "runtime" "sync" + "github.com/sirupsen/logrus" + "github.com/reeflective/team" "github.com/reeflective/team/internal/assets" "github.com/reeflective/team/internal/version" - "github.com/sirupsen/logrus" ) // Client is the core driver of an application teamclient. diff --git a/client/commands/commands.go b/client/commands/commands.go index 1416c6b..c178e69 100644 --- a/client/commands/commands.go +++ b/client/commands/commands.go @@ -25,12 +25,13 @@ import ( "path/filepath" "strings" - "github.com/reeflective/team/client" - "github.com/reeflective/team/internal/command" "github.com/rsteube/carapace" "github.com/rsteube/carapace/pkg/style" "github.com/spf13/cobra" "github.com/spf13/pflag" + + "github.com/reeflective/team/client" + "github.com/reeflective/team/internal/command" ) // Generate returns a command tree to embed in client applications connecting diff --git a/client/commands/import.go b/client/commands/import.go index 166a86c..ff470c2 100644 --- a/client/commands/import.go +++ b/client/commands/import.go @@ -22,10 +22,11 @@ import ( "encoding/json" "fmt" - "github.com/reeflective/team/client" - "github.com/reeflective/team/internal/command" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + + "github.com/reeflective/team/client" + "github.com/reeflective/team/internal/command" ) func importCmd(cli *client.Client) func(cmd *cobra.Command, args []string) { diff --git a/client/commands/users.go b/client/commands/users.go index f3045c9..3b7f1ca 100644 --- a/client/commands/users.go +++ b/client/commands/users.go @@ -23,10 +23,11 @@ import ( "time" "github.com/jedib0t/go-pretty/v6/table" - "github.com/reeflective/team/client" - "github.com/reeflective/team/internal/command" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + + "github.com/reeflective/team/client" + "github.com/reeflective/team/internal/command" ) func usersCmd(cli *client.Client) func(cmd *cobra.Command, args []string) error { diff --git a/client/commands/version.go b/client/commands/version.go index 975c0d9..2920bca 100644 --- a/client/commands/version.go +++ b/client/commands/version.go @@ -22,10 +22,11 @@ import ( "fmt" "time" - "github.com/reeflective/team/client" - "github.com/reeflective/team/internal/command" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + + "github.com/reeflective/team/client" + "github.com/reeflective/team/internal/command" ) func versionCmd(cli *client.Client) func(cmd *cobra.Command, args []string) error { diff --git a/client/config.go b/client/config.go index 2e6791e..daec0c5 100644 --- a/client/config.go +++ b/client/config.go @@ -30,6 +30,7 @@ import ( "sort" "github.com/AlecAivazis/survey/v2" + "github.com/reeflective/team/internal/assets" "github.com/reeflective/team/internal/certs" "github.com/reeflective/team/internal/command" diff --git a/client/log.go b/client/log.go index ed602c2..b4e9a36 100644 --- a/client/log.go +++ b/client/log.go @@ -23,8 +23,9 @@ import ( "io" "path/filepath" - "github.com/reeflective/team/internal/log" "github.com/sirupsen/logrus" + + "github.com/reeflective/team/internal/log" ) // NamedLogger returns a new logging "thread" with two fields (optional) diff --git a/client/options.go b/client/options.go index d8cbfd6..858fd58 100644 --- a/client/options.go +++ b/client/options.go @@ -23,8 +23,9 @@ import ( "os" "strings" - "github.com/reeflective/team/internal/assets" "github.com/sirupsen/logrus" + + "github.com/reeflective/team/internal/assets" ) const noTeamdir = "no team subdirectory" diff --git a/internal/certs/certs.go b/internal/certs/certs.go index d2377ea..51f532f 100644 --- a/internal/certs/certs.go +++ b/internal/certs/certs.go @@ -36,10 +36,11 @@ import ( "path/filepath" "time" - "github.com/reeflective/team/internal/assets" - "github.com/reeflective/team/internal/db" "github.com/sirupsen/logrus" "gorm.io/gorm" + + "github.com/reeflective/team/internal/assets" + "github.com/reeflective/team/internal/db" ) const ( diff --git a/internal/log/log.go b/internal/log/log.go index b31cccf..0219661 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -23,8 +23,9 @@ import ( "io" "path/filepath" - "github.com/reeflective/team/internal/assets" "github.com/sirupsen/logrus" + + "github.com/reeflective/team/internal/assets" ) const ( diff --git a/server/commands/commands.go b/server/commands/commands.go index e66847d..690730b 100644 --- a/server/commands/commands.go +++ b/server/commands/commands.go @@ -21,13 +21,14 @@ package commands import ( "fmt" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "github.com/reeflective/team/client" cli "github.com/reeflective/team/client/commands" "github.com/reeflective/team/internal/command" "github.com/reeflective/team/server" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" ) // Generate returns a "teamserver" command root and its tree for teamserver (server-side) management. diff --git a/server/commands/completers.go b/server/commands/completers.go index 5bf98b8..956c33a 100644 --- a/server/commands/completers.go +++ b/server/commands/completers.go @@ -23,9 +23,10 @@ import ( "net" "strings" + "github.com/rsteube/carapace" + "github.com/reeflective/team/client" "github.com/reeflective/team/server" - "github.com/rsteube/carapace" ) // interfacesCompleter completes interface addresses on the client host. diff --git a/server/commands/teamserver.go b/server/commands/teamserver.go index 5065dec..ab8e4a6 100644 --- a/server/commands/teamserver.go +++ b/server/commands/teamserver.go @@ -25,13 +25,14 @@ import ( "strconv" "strings" + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/jedib0t/go-pretty/v6/table" "github.com/reeflective/team/internal/command" "github.com/reeflective/team/internal/log" "github.com/reeflective/team/internal/systemd" "github.com/reeflective/team/server" - "github.com/sirupsen/logrus" - "github.com/spf13/cobra" ) func daemoncmd(serv *server.Server) func(cmd *cobra.Command, args []string) error { diff --git a/server/config.go b/server/config.go index d76e530..f1699db 100644 --- a/server/config.go +++ b/server/config.go @@ -27,9 +27,10 @@ import ( "path/filepath" "time" + "github.com/sirupsen/logrus" + "github.com/reeflective/team/internal/assets" "github.com/reeflective/team/internal/command" - "github.com/sirupsen/logrus" ) const ( diff --git a/server/core.go b/server/core.go index 277a3b2..a3570b7 100644 --- a/server/core.go +++ b/server/core.go @@ -22,14 +22,15 @@ import ( "runtime" "sync" + "github.com/sirupsen/logrus" + "gorm.io/gorm" + "github.com/reeflective/team" "github.com/reeflective/team/client" "github.com/reeflective/team/internal/assets" "github.com/reeflective/team/internal/certs" "github.com/reeflective/team/internal/db" "github.com/reeflective/team/internal/version" - "github.com/sirupsen/logrus" - "gorm.io/gorm" ) // Server is the core driver of an application teamserver. diff --git a/server/db.go b/server/db.go index 53591da..6edc116 100644 --- a/server/db.go +++ b/server/db.go @@ -25,10 +25,11 @@ import ( "path" "path/filepath" + "gorm.io/gorm" + "github.com/reeflective/team/internal/assets" "github.com/reeflective/team/internal/command" "github.com/reeflective/team/internal/db" - "gorm.io/gorm" ) const ( diff --git a/server/options.go b/server/options.go index 1ea2933..c00c19e 100644 --- a/server/options.go +++ b/server/options.go @@ -22,10 +22,11 @@ import ( "os" "strings" - "github.com/reeflective/team/internal/assets" - "github.com/reeflective/team/internal/db" "github.com/sirupsen/logrus" "gorm.io/gorm" + + "github.com/reeflective/team/internal/assets" + "github.com/reeflective/team/internal/db" ) const noTeamdir = "no team subdirectory" diff --git a/server/users.go b/server/users.go index 533576f..7ffc071 100644 --- a/server/users.go +++ b/server/users.go @@ -31,6 +31,7 @@ import ( "time" "github.com/lib/pq" + "github.com/reeflective/team" "github.com/reeflective/team/client" "github.com/reeflective/team/internal/certs" From 584e59500fb752f6e9a8cba8cf216310fcb4a524 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Mon, 5 May 2025 15:43:13 +0200 Subject: [PATCH 5/8] Format import --- internal/db/sql.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/db/sql.go b/internal/db/sql.go index b8f86d3..6509086 100644 --- a/internal/db/sql.go +++ b/internal/db/sql.go @@ -23,12 +23,13 @@ import ( "fmt" "time" - "github.com/reeflective/team/internal/log" "github.com/sirupsen/logrus" "gorm.io/driver/mysql" "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/logger" + + "github.com/reeflective/team/internal/log" ) const ( From 822646962aeaa33e4dc6fe589c0f993cf75740c4 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Mon, 5 May 2025 17:02:41 +0200 Subject: [PATCH 6/8] Update go.mod --- go.mod | 13 ++++++------- go.sum | 13 ++++++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index fa62d11..8c5f770 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,6 @@ require ( github.com/lib/pq v1.10.9 github.com/ncruces/go-sqlite3 v0.8.4 github.com/ncruces/go-sqlite3/gormlite v0.8.4 - github.com/psanford/memfs v0.0.0-20230130182539-4dbf7e3e865e github.com/rsteube/carapace v0.47.4 github.com/sirupsen/logrus v1.9.3 github.com/spf13/afero v1.14.0 @@ -52,13 +51,13 @@ require ( github.com/rsteube/carapace-shlex v0.1.1 // indirect github.com/stretchr/testify v1.8.2 // indirect github.com/tetratelabs/wazero v1.4.0 // indirect - golang.org/x/crypto v0.23.0 // indirect + golang.org/x/crypto v0.37.0 // indirect golang.org/x/mod v0.17.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sync v0.12.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/term v0.20.0 // indirect - golang.org/x/text v0.23.0 // indirect + golang.org/x/net v0.39.0 // indirect + golang.org/x/sync v0.13.0 // indirect + golang.org/x/sys v0.32.0 // indirect + golang.org/x/term v0.31.0 // indirect + golang.org/x/text v0.24.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 86e586f..0b6b255 100644 --- a/go.sum +++ b/go.sum @@ -44,7 +44,6 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -110,8 +109,6 @@ github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdL github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/psanford/memfs v0.0.0-20230130182539-4dbf7e3e865e h1:51xcRlSMBU5rhM9KahnJGfEsBPVPz3182TgFRowA8yY= -github.com/psanford/memfs v0.0.0-20230130182539-4dbf7e3e865e/go.mod h1:tcaRap0jS3eifrEEllL6ZMd9dg8IlDpi2S1oARrQ+NI= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= @@ -164,6 +161,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= +golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -186,6 +185,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= +golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.7.0 h1:qe6s0zUXlPX80/dITx3440hWZ7GwMwgDDyrSGTPJG/g= golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4= @@ -197,6 +198,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -215,16 +217,21 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= +golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= +golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= From 084cc1e769f6fe13cbef6db28da0f1961ae1f3a8 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Mon, 5 May 2025 17:04:04 +0200 Subject: [PATCH 7/8] Update carapace dependency --- client/commands/commands.go | 4 ++-- go.mod | 4 +++- go.sum | 24 +++++++++--------------- server/commands/commands.go | 2 +- server/commands/completers.go | 2 +- server/commands/teamserver.go | 2 +- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/client/commands/commands.go b/client/commands/commands.go index c178e69..9c63bf5 100644 --- a/client/commands/commands.go +++ b/client/commands/commands.go @@ -25,8 +25,8 @@ import ( "path/filepath" "strings" - "github.com/rsteube/carapace" - "github.com/rsteube/carapace/pkg/style" + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace/pkg/style" "github.com/spf13/cobra" "github.com/spf13/pflag" diff --git a/go.mod b/go.mod index 8c5f770..0950fdf 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ toolchain go1.24.2 require ( github.com/AlecAivazis/survey/v2 v2.3.7 + github.com/carapace-sh/carapace v1.8.1 github.com/gofrs/uuid v4.4.0+incompatible github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/jedib0t/go-pretty/v6 v6.4.6 @@ -15,7 +16,7 @@ require ( github.com/rsteube/carapace v0.47.4 github.com/sirupsen/logrus v1.9.3 github.com/spf13/afero v1.14.0 - github.com/spf13/cobra v1.8.1 + github.com/spf13/cobra v1.9.1 github.com/spf13/pflag v1.0.6 google.golang.org/grpc v1.56.1 google.golang.org/protobuf v1.31.0 @@ -27,6 +28,7 @@ require ( ) require ( + github.com/carapace-sh/carapace-shlex v1.0.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/golang/protobuf v1.5.3 // indirect diff --git a/go.sum b/go.sum index 0b6b255..d7abf50 100644 --- a/go.sum +++ b/go.sum @@ -10,11 +10,15 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s= github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/carapace-sh/carapace v1.8.1 h1:W5NlN2Vm5WOI4QlVHWRLobeKU6pOY682BgOyQhSRj+4= +github.com/carapace-sh/carapace v1.8.1/go.mod h1:C0PH0NpNW+Gb2nvnJ8nl2yRvvPxEHqVgYU8fphWGoEg= +github.com/carapace-sh/carapace-shlex v1.0.1 h1:ww0JCgWpOVuqWG7k3724pJ18Lq8gh5pHQs9j3ojUs1c= +github.com/carapace-sh/carapace-shlex v1.0.1/go.mod h1:lJ4ZsdxytE0wHJ8Ta9S7Qq0XpjgjU0mdfCqiI2FHx7M= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -127,8 +131,8 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA= github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= -github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= -github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= +github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -159,8 +163,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -183,8 +185,6 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -196,8 +196,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= -golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -215,21 +214,16 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= -golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/server/commands/commands.go b/server/commands/commands.go index 690730b..cd7c202 100644 --- a/server/commands/commands.go +++ b/server/commands/commands.go @@ -21,7 +21,7 @@ package commands import ( "fmt" - "github.com/rsteube/carapace" + "github.com/carapace-sh/carapace" "github.com/spf13/cobra" "github.com/spf13/pflag" diff --git a/server/commands/completers.go b/server/commands/completers.go index 956c33a..832805c 100644 --- a/server/commands/completers.go +++ b/server/commands/completers.go @@ -23,7 +23,7 @@ import ( "net" "strings" - "github.com/rsteube/carapace" + "github.com/carapace-sh/carapace" "github.com/reeflective/team/client" "github.com/reeflective/team/server" diff --git a/server/commands/teamserver.go b/server/commands/teamserver.go index ab8e4a6..3733d66 100644 --- a/server/commands/teamserver.go +++ b/server/commands/teamserver.go @@ -25,10 +25,10 @@ import ( "strconv" "strings" + "github.com/jedib0t/go-pretty/v6/table" "github.com/sirupsen/logrus" "github.com/spf13/cobra" - "github.com/jedib0t/go-pretty/v6/table" "github.com/reeflective/team/internal/command" "github.com/reeflective/team/internal/log" "github.com/reeflective/team/internal/systemd" From 22447c73233bdc1afd5ae0752b9d373c640264ee Mon Sep 17 00:00:00 2001 From: maxlandon Date: Mon, 5 May 2025 18:28:49 +0200 Subject: [PATCH 8/8] Update README --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 10573b6..f6e301d 100644 --- a/README.md +++ b/README.md @@ -343,8 +343,6 @@ This teamserver library aims to remain small, with a precise behavior and role. Overall, contributions and ideas should revolve around strenghening its core/transport code or around enhancing its interoperability with as much Go code/programs as possible. -- [x] Use viper for configs. -- [x] Use afero filesystem. - [ ] Add support for encrypted sqlite by default. - [ ] Encrypt in-memory channels, or add option for it. - [ ] Simpler/different listener/dialer backend interfaces, if it appears needed. @@ -353,5 +351,4 @@ or around enhancing its interoperability with as much Go code/programs as possib - [ ] Review/refine/strenghen the dialer/listener init/close/start process, if it appears needed. - [ ] `teamclient update` downloads latest version of the server binary + method to `team.Client` for it. - [ ] Implement tests for most sensitive paths (certificates management, database functioning, etc) -- [ ] Update carapace to carapace-sh