From 206296b220f3a44e0a62e7253bd9fcf814835cf0 Mon Sep 17 00:00:00 2001 From: Alexei Yuzhakov Date: Sat, 7 Oct 2023 22:12:44 +0300 Subject: [PATCH] TECH Remove deprecated constructions --- cmd/apps/deploy.go | 3 +-- cmd/completion.go | 2 +- cmd/root.go | 4 ++-- internal/actions/apps.go | 3 +-- internal/api/factory/factory.go | 6 +++--- internal/api/json/auth.go | 6 +++--- internal/api/json/databases.go | 18 +++++++++--------- internal/api/json/domains.go | 12 ++++++------ internal/api/json/ftp.go | 8 ++++---- internal/api/json/info.go | 4 ++-- internal/utils/utils.go | 8 ++------ 11 files changed, 34 insertions(+), 40 deletions(-) diff --git a/cmd/apps/deploy.go b/cmd/apps/deploy.go index c5f16af..0b00cc9 100644 --- a/cmd/apps/deploy.go +++ b/cmd/apps/deploy.go @@ -6,7 +6,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "path/filepath" @@ -43,7 +42,7 @@ var deployCmd = &cobra.Command{ } var c types.App - f, err := ioutil.ReadFile(path + "/.plesk") + f, err := os.ReadFile(path + "/.plesk") if err != nil { return errors.New(locales.L.Get("errors.cannot.parse.config", path+"/.plesk")) } diff --git a/cmd/completion.go b/cmd/completion.go index 4430cb8..af1f9a4 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -22,5 +22,5 @@ var completionCmd = &cobra.Command{ }, DisableFlagsInUseLine: true, ValidArgs: []string{"bash", "zsh"}, - Args: cobra.ExactValidArgs(1), + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), } diff --git a/cmd/root.go b/cmd/root.go index 3f27a0e..4c3879a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,7 +3,7 @@ package cmd import ( - "io/ioutil" + "io" "log" appsCmd "github.com/plesk/pleskapp/plesk/cmd/apps" @@ -51,6 +51,6 @@ func initLogger() { v, _ := rootCmd.PersistentFlags().GetBool("verbose") if !v { - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) } } diff --git a/internal/actions/apps.go b/internal/actions/apps.go index 56c6142..23ed405 100644 --- a/internal/actions/apps.go +++ b/internal/actions/apps.go @@ -5,7 +5,6 @@ package actions import ( "encoding/json" "errors" - "io/ioutil" "os" "github.com/plesk/pleskapp/plesk/internal/api/factory" @@ -48,7 +47,7 @@ func AppAdd( return err } - ioutil.WriteFile(path+"/.plesk", aj, 0600) + os.WriteFile(path+"/.plesk", aj, 0600) return nil } diff --git a/internal/api/factory/factory.go b/internal/api/factory/factory.go index 12d9b8d..19e7199 100644 --- a/internal/api/factory/factory.go +++ b/internal/api/factory/factory.go @@ -4,7 +4,7 @@ package factory import ( "crypto/tls" - "io/ioutil" + "io" "log" "net/http" @@ -24,9 +24,9 @@ func buildClient(a api.Auth) *resty.Client { } r := resty.NewWithClient(c). - SetHostURL("https://"+a.GetAddress()+":"+a.GetPort()). + SetBaseURL("https://"+a.GetAddress()+":"+a.GetPort()). SetHeader("Content-Type", "application/json"). - SetDebug(log.Writer() != ioutil.Discard) + SetDebug(log.Writer() != io.Discard) login := a.GetLogin() pass := a.GetPassword() diff --git a/internal/api/json/auth.go b/internal/api/json/auth.go index caf64c5..6c64bb5 100644 --- a/internal/api/json/auth.go +++ b/internal/api/json/auth.go @@ -64,7 +64,7 @@ func (j Auth) GetAPIKey(a api.Auth) (string, error) { } if res.StatusCode() == 403 { - return "", authError{server: j.client.HostURL, needReauth: false} + return "", authError{server: j.client.BaseURL, needReauth: false} } var r = res.Error().(*jsonError) @@ -104,7 +104,7 @@ func (j Auth) GetAPIKey(a api.Auth) (string, error) { } if res.StatusCode() == 403 { - return "", authError{server: j.client.HostURL, needReauth: false} + return "", authError{server: j.client.BaseURL, needReauth: false} } var r = res.Error().(*jsonError) @@ -143,7 +143,7 @@ func (j Auth) GetLoginLink(auth api.Auth) (string, error) { } if res.StatusCode() == 403 { - return "", authError{server: j.client.HostURL, needReauth: true} + return "", authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) diff --git a/internal/api/json/databases.go b/internal/api/json/databases.go index 7d782c1..e0d0573 100644 --- a/internal/api/json/databases.go +++ b/internal/api/json/databases.go @@ -52,7 +52,7 @@ func (j jsonDatabases) ListDatabases() ([]api.DatabaseInfo, error) { } if res.StatusCode() == 403 { - return jsonDatabaseInfoToInfo([]databaseInfo{}), authError{server: j.client.HostURL, needReauth: true} + return jsonDatabaseInfoToInfo([]databaseInfo{}), authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -76,7 +76,7 @@ func (j jsonDatabases) ListDomainDatabases(domain string) ([]api.DatabaseInfo, e } if res.StatusCode() == 403 { - return jsonDatabaseInfoToInfo([]databaseInfo{}), authError{server: j.client.HostURL, needReauth: true} + return jsonDatabaseInfoToInfo([]databaseInfo{}), authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -119,7 +119,7 @@ func (j jsonDatabases) CreateDatabase(domain types.Domain, db types.NewDatabase, } if res.StatusCode() == 403 { - return nil, authError{server: j.client.HostURL, needReauth: true} + return nil, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -136,7 +136,7 @@ func (j jsonDatabases) RemoveDatabase(db types.Database) error { } if res.StatusCode() == 403 { - return authError{server: j.client.HostURL, needReauth: true} + return authError{server: j.client.BaseURL, needReauth: true} } if res.IsError() { @@ -216,7 +216,7 @@ func (j jsonDatabases) DeployDatabase( } if res.StatusCode() == 403 { - return authError{server: j.client.HostURL, needReauth: true} + return authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -239,7 +239,7 @@ func (j jsonDatabases) ListDatabaseServers() ([]api.DatabaseServerInfo, error) { } if res.StatusCode() == 403 { - return []api.DatabaseServerInfo{}, authError{server: j.client.HostURL, needReauth: true} + return []api.DatabaseServerInfo{}, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -277,7 +277,7 @@ func (j jsonDatabases) CreateDatabaseUser(db types.Database, dbuser types.NewDat } if res.StatusCode() == 403 { - return nil, authError{server: j.client.HostURL, needReauth: true} + return nil, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -294,7 +294,7 @@ func (j jsonDatabases) RemoveDatabaseUser(dbu types.DatabaseUser) error { } if res.StatusCode() == 403 { - return authError{server: j.client.HostURL, needReauth: true} + return authError{server: j.client.BaseURL, needReauth: true} } if res.IsError() { @@ -322,7 +322,7 @@ func (j jsonDatabases) ListDatabaseUsers(db types.Database) ([]api.DatabaseUserI } if res.StatusCode() == 403 { - return []api.DatabaseUserInfo{}, authError{server: j.client.HostURL, needReauth: true} + return []api.DatabaseUserInfo{}, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) diff --git a/internal/api/json/domains.go b/internal/api/json/domains.go index fc45500..36332e4 100644 --- a/internal/api/json/domains.go +++ b/internal/api/json/domains.go @@ -85,7 +85,7 @@ func (j jsonDomains) getDomainSysUser(d string) (string, error) { } if res.StatusCode() == 403 { - return "", authError{server: j.client.HostURL, needReauth: true} + return "", authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -134,7 +134,7 @@ func (j jsonDomains) CreateDomain(d string, ipa types.ServerIPAddresses) (*api.D } if res.StatusCode() == 403 { - return nil, authError{server: j.client.HostURL, needReauth: true} + return nil, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -175,7 +175,7 @@ func (j jsonDomains) AddDomainFeatures(domain string, featureList []string, isWi } if res.StatusCode() == 403 { - return authError{server: j.client.HostURL, needReauth: true} + return authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -220,7 +220,7 @@ func (j jsonDomains) GetDomain(d string) (api.DomainInfo, error) { } if res.StatusCode() == 403 { - return api.DomainInfo{}, authError{server: j.client.HostURL, needReauth: true} + return api.DomainInfo{}, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -242,7 +242,7 @@ func (j jsonDomains) RemoveDomain(d string) error { } if res.StatusCode() == 403 { - return authError{server: j.client.HostURL, needReauth: true} + return authError{server: j.client.BaseURL, needReauth: true} } if res.IsError() { @@ -269,7 +269,7 @@ func (j jsonDomains) ListDomains() ([]api.DomainInfo, error) { } if res.StatusCode() == 403 { - return []api.DomainInfo{}, authError{server: j.client.HostURL, needReauth: true} + return []api.DomainInfo{}, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) diff --git a/internal/api/json/ftp.go b/internal/api/json/ftp.go index 6b6d082..5751a14 100644 --- a/internal/api/json/ftp.go +++ b/internal/api/json/ftp.go @@ -58,7 +58,7 @@ func (j jsonFTPUsers) ListDomainFtpUsers(domain string, user types.FtpUser) ([]a } if res.StatusCode() == 403 { - return nil, authError{server: j.client.HostURL, needReauth: true} + return nil, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -105,7 +105,7 @@ func (j jsonFTPUsers) CreateFtpUser(domain string, user types.FtpUser) (*api.FTP } if res.StatusCode() == 403 { - return nil, authError{server: j.client.HostURL, needReauth: true} + return nil, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -140,7 +140,7 @@ func (j jsonFTPUsers) UpdateFtpUser(domain string, user string, userNew types.Ft } if res.StatusCode() == 403 { - return authError{server: j.client.HostURL, needReauth: true} + return authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -157,7 +157,7 @@ func (j jsonFTPUsers) DeleteFtpUser(domain string, user types.FtpUser) error { } if res.StatusCode() == 403 { - return authError{server: j.client.HostURL, needReauth: true} + return authError{server: j.client.BaseURL, needReauth: true} } if res.IsError() { diff --git a/internal/api/json/info.go b/internal/api/json/info.go index 9688626..79e45a3 100644 --- a/internal/api/json/info.go +++ b/internal/api/json/info.go @@ -59,7 +59,7 @@ func (j jsonInfo) GetInfo() (api.ServerInfo, error) { } if res.StatusCode() == 403 { - return api.ServerInfo{}, authError{server: j.client.HostURL, needReauth: true} + return api.ServerInfo{}, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) @@ -95,7 +95,7 @@ func (j jsonInfo) GetIPAddresses() (types.ServerIPAddresses, error) { } if res.StatusCode() == 403 { - return types.ServerIPAddresses{}, authError{server: j.client.HostURL, needReauth: true} + return types.ServerIPAddresses{}, authError{server: j.client.BaseURL, needReauth: true} } var r = res.Error().(*jsonError) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index faafdea..bdab8ff 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -4,13 +4,11 @@ package utils import ( "fmt" + "github.com/plesk/pleskapp/plesk/internal/types" + "golang.org/x/term" "math/rand" "strings" "syscall" - "time" - - "github.com/plesk/pleskapp/plesk/internal/types" - "golang.org/x/term" ) const allowedChars = "abcdefghijklmnopqrstuvwxyz" @@ -68,7 +66,6 @@ func GeneratePassword(length int) string { strings.Split("!@#$%^*()-=+_", ""), } - rand.Seed(time.Now().UnixNano()) pw := "" for i := 0; i < length; i++ { pw += charsets[i%3][rand.Intn(len(charsets[i%3]))] @@ -83,7 +80,6 @@ func GeneratePassword(length int) string { func GenerateUsername(length int) string { var charset = strings.Split(allowedChars, "") - rand.Seed(time.Now().UnixNano()) pw := "" for i := 0; i < length; i++ { pw += charset[rand.Intn(len(charset))]