Skip to content

Commit

Permalink
TECH Remove deprecated constructions
Browse files Browse the repository at this point in the history
  • Loading branch information
sibprogrammer committed Oct 7, 2023
1 parent 2eaa41e commit 206296b
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 40 deletions.
3 changes: 1 addition & 2 deletions cmd/apps/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -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"))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package cmd

import (
"io/ioutil"
"io"
"log"

appsCmd "github.com/plesk/pleskapp/plesk/cmd/apps"
Expand Down Expand Up @@ -51,6 +51,6 @@ func initLogger() {

v, _ := rootCmd.PersistentFlags().GetBool("verbose")
if !v {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
}
3 changes: 1 addition & 2 deletions internal/actions/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package actions
import (
"encoding/json"
"errors"
"io/ioutil"
"os"

"github.com/plesk/pleskapp/plesk/internal/api/factory"
Expand Down Expand Up @@ -48,7 +47,7 @@ func AppAdd(
return err
}

ioutil.WriteFile(path+"/.plesk", aj, 0600)
os.WriteFile(path+"/.plesk", aj, 0600)

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/api/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package factory

import (
"crypto/tls"
"io/ioutil"
"io"
"log"
"net/http"

Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions internal/api/json/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions internal/api/json/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions internal/api/json/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions internal/api/json/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions internal/api/json/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]))]
Expand All @@ -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))]
Expand Down

0 comments on commit 206296b

Please sign in to comment.