aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-12-10 03:23:02 +0700
committerShulhan <ms@kilabit.info>2023-12-14 20:23:47 +0700
commitf1bcd6e27e9cbf541b9f6d76944bb491aede370a (patch)
tree7349319155d7f8321afc9df08c3ed4ef71bbfcea
parent87b79dbd1da7acc73456b3fbfe59a40b59bf116f (diff)
downloadawwan-f1bcd6e27e9cbf541b9f6d76944bb491aede370a.tar.xz
all: changes based on reports from linter revive
Better to fix and follow the reported warnings rather than adding configuration file to add an exception.
-rw-r--r--awwan.go22
-rw-r--r--awwan_test.go8
-rw-r--r--http_server.go56
-rw-r--r--http_server_play_test.go4
-rw-r--r--http_server_test.go20
-rw-r--r--session.go2
-rw-r--r--ssh_client.go6
7 files changed, 59 insertions, 59 deletions
diff --git a/awwan.go b/awwan.go
index 796eefe..5164245 100644
--- a/awwan.go
+++ b/awwan.go
@@ -45,8 +45,8 @@ const (
const (
defCacheDir = `.cache`
defEnvFileName = `awwan.env` // The default awwan environment file name.
- defSshConfig = `config` // The default SSH config file name.
- defSshDir = `.ssh` // The default SSH config directory name.
+ defSSHConfig = `config` // The default SSH config file name.
+ defSSHDir = `.ssh` // The default SSH config directory name.
defTmpDir = `/tmp`
)
@@ -366,7 +366,7 @@ func (aww *Awwan) Play(req *ExecRequest) (err error) {
// Always load the SSH config, in case we run on "serve" and
// .ssh/config changed by user.
- err = aww.loadSshConfig()
+ err = aww.loadSSHConfig()
if err != nil {
goto out
}
@@ -427,7 +427,7 @@ func (aww *Awwan) Serve(address string, isDev bool) (err error) {
go internal.Watch()
}
- aww.httpd, err = newHttpServer(aww, address)
+ aww.httpd, err = newHTTPServer(aww, address)
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}
@@ -435,11 +435,11 @@ func (aww *Awwan) Serve(address string, isDev bool) (err error) {
return aww.httpd.start()
}
-// loadSshConfig load all SSH config from user's home and the awwan base
+// loadSSHConfig load all SSH config from user's home and the awwan base
// directory.
-func (aww *Awwan) loadSshConfig() (err error) {
+func (aww *Awwan) loadSSHConfig() (err error) {
var (
- logp = "loadSshConfig"
+ logp = `loadSSHConfig`
baseDirConfig *config.Config
homeDir string
@@ -451,13 +451,13 @@ func (aww *Awwan) loadSshConfig() (err error) {
return fmt.Errorf("%s: %w", logp, err)
}
- configFile = filepath.Join(homeDir, defSshDir, defSshConfig)
+ configFile = filepath.Join(homeDir, defSSHDir, defSSHConfig)
aww.sshConfig, err = config.Load(configFile)
if err != nil {
return fmt.Errorf("%s: %w", logp, err)
}
- configFile = filepath.Join(aww.BaseDir, defSshDir, defSshConfig)
+ configFile = filepath.Join(aww.BaseDir, defSSHDir, defSSHConfig)
baseDirConfig, err = config.Load(configFile)
if err != nil {
@@ -481,7 +481,7 @@ func lookupBaseDir(baseDir string) (dir string, err error) {
)
if len(baseDir) > 0 {
- _, err = os.Stat(filepath.Join(baseDir, defSshDir))
+ _, err = os.Stat(filepath.Join(baseDir, defSSHDir))
if err != nil {
return "", fmt.Errorf("%s: cannot find .ssh directory on %s", logp, baseDir)
}
@@ -494,7 +494,7 @@ func lookupBaseDir(baseDir string) (dir string, err error) {
}
for dir != "/" {
- _, err = os.Stat(filepath.Join(dir, defSshDir))
+ _, err = os.Stat(filepath.Join(dir, defSSHDir))
if err == nil {
found = true
break
diff --git a/awwan_test.go b/awwan_test.go
index 2e40a7c..008702c 100644
--- a/awwan_test.go
+++ b/awwan_test.go
@@ -26,17 +26,17 @@ func TestMain(m *testing.M) {
func testInitWorkspace(dir string, awwanKey, awwanPass []byte) {
var (
logp = `testInitWorkspace`
- dirSsh = filepath.Join(dir, defSshDir)
+ dirSSH = filepath.Join(dir, defSSHDir)
)
- var err = os.Mkdir(dirSsh, 0700)
+ var err = os.Mkdir(dirSSH, 0700)
if err != nil {
log.Fatalf(`%s: %s`, logp, err)
}
var file string
if len(awwanKey) != 0 {
- file = filepath.Join(dirSsh, defFilePrivateKey)
+ file = filepath.Join(dirSSH, defFilePrivateKey)
err = os.WriteFile(file, awwanKey, 0600)
if err != nil {
log.Fatalf(`%s: %s`, logp, err)
@@ -44,7 +44,7 @@ func testInitWorkspace(dir string, awwanKey, awwanPass []byte) {
}
if len(awwanPass) != 0 {
- file = filepath.Join(dirSsh, defFilePassphrase)
+ file = filepath.Join(dirSSH, defFilePassphrase)
err = os.WriteFile(file, awwanPass, 0600)
if err != nil {
log.Fatalf(`%s: %s`, logp, err)
diff --git a/http_server.go b/http_server.go
index e83cb2f..1926cfb 100644
--- a/http_server.go
+++ b/http_server.go
@@ -26,11 +26,11 @@ import (
// List of available HTTP API.
const (
- pathAwwanApiDecrypt = `/awwan/api/decrypt`
- pathAwwanApiEncrypt = `/awwan/api/encrypt`
- pathAwwanApiExecute = `/awwan/api/execute`
- pathAwwanApiExecuteTail = `/awwan/api/execute/tail`
- pathAwwanApiFs = `/awwan/api/fs`
+ pathAwwanAPIDecrypt = `/awwan/api/decrypt`
+ pathAwwanAPIEncrypt = `/awwan/api/encrypt`
+ pathAwwanAPIExecute = `/awwan/api/execute`
+ pathAwwanAPIExecuteTail = `/awwan/api/execute/tail`
+ pathAwwanAPIFs = `/awwan/api/fs`
)
// List of known parameter in request.
@@ -55,11 +55,11 @@ type httpServer struct {
baseDir string
}
-// newHttpServer create and initialize HTTP server to serve awwan HTTP API
+// newHTTPServer create and initialize HTTP server to serve awwan HTTP API
// and web user interface.
-func newHttpServer(aww *Awwan, address string) (httpd *httpServer, err error) {
+func newHTTPServer(aww *Awwan, address string) (httpd *httpServer, err error) {
var (
- logp = `newHttpServer`
+ logp = `newHTTPServer`
)
httpd = &httpServer{
@@ -109,7 +109,7 @@ func (httpd *httpServer) registerEndpoints() (err error) {
err = httpd.RegisterEndpoint(&libhttp.Endpoint{
Method: libhttp.RequestMethodGet,
- Path: pathAwwanApiFs,
+ Path: pathAwwanAPIFs,
RequestType: libhttp.RequestTypeQuery,
ResponseType: libhttp.ResponseTypeJSON,
Call: httpd.FSGet,
@@ -120,10 +120,10 @@ func (httpd *httpServer) registerEndpoints() (err error) {
err = httpd.RegisterEndpoint(&libhttp.Endpoint{
Method: libhttp.RequestMethodDelete,
- Path: pathAwwanApiFs,
+ Path: pathAwwanAPIFs,
RequestType: libhttp.RequestTypeJSON,
ResponseType: libhttp.ResponseTypeJSON,
- Call: httpd.awwanApiFsDelete,
+ Call: httpd.awwanAPIFsDelete,
})
if err != nil {
return fmt.Errorf("%s: %w", logp, err)
@@ -131,10 +131,10 @@ func (httpd *httpServer) registerEndpoints() (err error) {
err = httpd.RegisterEndpoint(&libhttp.Endpoint{
Method: libhttp.RequestMethodPost,
- Path: pathAwwanApiFs,
+ Path: pathAwwanAPIFs,
RequestType: libhttp.RequestTypeJSON,
ResponseType: libhttp.ResponseTypeJSON,
- Call: httpd.awwanApiFsPost,
+ Call: httpd.awwanAPIFsPost,
})
if err != nil {
return fmt.Errorf("%s: %w", logp, err)
@@ -142,10 +142,10 @@ func (httpd *httpServer) registerEndpoints() (err error) {
err = httpd.RegisterEndpoint(&libhttp.Endpoint{
Method: libhttp.RequestMethodPut,
- Path: pathAwwanApiFs,
+ Path: pathAwwanAPIFs,
RequestType: libhttp.RequestTypeJSON,
ResponseType: libhttp.ResponseTypeJSON,
- Call: httpd.awwanApiFsPut,
+ Call: httpd.awwanAPIFsPut,
})
if err != nil {
return fmt.Errorf("%s: %w", logp, err)
@@ -153,7 +153,7 @@ func (httpd *httpServer) registerEndpoints() (err error) {
var epDecrypt = libhttp.Endpoint{
Method: libhttp.RequestMethodPost,
- Path: pathAwwanApiDecrypt,
+ Path: pathAwwanAPIDecrypt,
RequestType: libhttp.RequestTypeJSON,
ResponseType: libhttp.ResponseTypeJSON,
Call: httpd.Decrypt,
@@ -165,7 +165,7 @@ func (httpd *httpServer) registerEndpoints() (err error) {
var epEncrypt = libhttp.Endpoint{
Method: libhttp.RequestMethodPost,
- Path: pathAwwanApiEncrypt,
+ Path: pathAwwanAPIEncrypt,
RequestType: libhttp.RequestTypeJSON,
ResponseType: libhttp.ResponseTypeJSON,
Call: httpd.Encrypt,
@@ -177,7 +177,7 @@ func (httpd *httpServer) registerEndpoints() (err error) {
err = httpd.RegisterEndpoint(&libhttp.Endpoint{
Method: libhttp.RequestMethodPost,
- Path: pathAwwanApiExecute,
+ Path: pathAwwanAPIExecute,
RequestType: libhttp.RequestTypeJSON,
ResponseType: libhttp.ResponseTypeJSON,
Call: httpd.Execute,
@@ -190,7 +190,7 @@ func (httpd *httpServer) registerEndpoints() (err error) {
// output.
var epExecuteTail = &libhttp.SSEEndpoint{
- Path: pathAwwanApiExecuteTail,
+ Path: pathAwwanAPIExecuteTail,
Call: httpd.ExecuteTail,
}
err = httpd.RegisterSSE(epExecuteTail)
@@ -424,7 +424,7 @@ func (httpd *httpServer) FSGet(epr *libhttp.EndpointRequest) (resb []byte, err e
return json.Marshal(res)
}
-// awwanApiFsDelete an HTTP API to delete a file.
+// awwanAPIFsDelete an HTTP API to delete a file.
//
// Request format,
//
@@ -450,9 +450,9 @@ func (httpd *httpServer) FSGet(epr *libhttp.EndpointRequest) (resb []byte, err e
// - 400: Bad request.
// - 401: Unauthorized.
// - 404: File not found.
-func (httpd *httpServer) awwanApiFsDelete(epr *libhttp.EndpointRequest) (resb []byte, err error) {
+func (httpd *httpServer) awwanAPIFsDelete(epr *libhttp.EndpointRequest) (resb []byte, err error) {
var (
- logp = `awwanApiFsDelete`
+ logp = `awwanAPIFsDelete`
res = &libhttp.EndpointResponse{}
req = &fsRequest{}
@@ -512,7 +512,7 @@ func (httpd *httpServer) awwanApiFsDelete(epr *libhttp.EndpointRequest) (resb []
return json.Marshal(res)
}
-// awwanApiFsPost create new directory or file.
+// awwanAPIFsPost create new directory or file.
//
// # Request
//
@@ -525,9 +525,9 @@ func (httpd *httpServer) awwanApiFsDelete(epr *libhttp.EndpointRequest) (resb []
// "path": <string>, the path to new directory or file.
// "is_dir": <boolean>, true if its directory.
// }
-func (httpd *httpServer) awwanApiFsPost(epr *libhttp.EndpointRequest) (rawBody []byte, err error) {
+func (httpd *httpServer) awwanAPIFsPost(epr *libhttp.EndpointRequest) (rawBody []byte, err error) {
var (
- logp = `awwanApiFsPost`
+ logp = `awwanAPIFsPost`
res = &libhttp.EndpointResponse{}
req = &fsRequest{}
@@ -598,10 +598,10 @@ func (httpd *httpServer) awwanApiFsPost(epr *libhttp.EndpointRequest) (rawBody [
return json.Marshal(res)
}
-// awwanApiFsPut save the content of file.
-func (httpd *httpServer) awwanApiFsPut(epr *libhttp.EndpointRequest) (rawBody []byte, err error) {
+// awwanAPIFsPut save the content of file.
+func (httpd *httpServer) awwanAPIFsPut(epr *libhttp.EndpointRequest) (rawBody []byte, err error) {
var (
- logp = "awwanApiFsPut"
+ logp = `awwanAPIFsPut`
res = &libhttp.EndpointResponse{}
req = &fsRequest{}
diff --git a/http_server_play_test.go b/http_server_play_test.go
index df9f4f3..ed5bae6 100644
--- a/http_server_play_test.go
+++ b/http_server_play_test.go
@@ -66,7 +66,7 @@ func TestHttpServerPlaySshConfigChanges(t *testing.T) {
var httpd *httpServer
- httpd, err = newHttpServer(aww, ``)
+ httpd, err = newHTTPServer(aww, ``)
if err != nil {
t.Fatal(err)
}
@@ -92,7 +92,7 @@ func testHttpExecute(t *testing.T, httpd *httpServer, tdata *test.Data, tag stri
reqBody.Write(tdata.Input[tag])
- var httpReq = httptest.NewRequest(http.MethodPost, pathAwwanApiExecute, &reqBody)
+ var httpReq = httptest.NewRequest(http.MethodPost, pathAwwanAPIExecute, &reqBody)
var httpWriter = httptest.NewRecorder()
httpd.ServeHTTP(httpWriter, httpReq)
diff --git a/http_server_test.go b/http_server_test.go
index 7dcff3f..9a7603f 100644
--- a/http_server_test.go
+++ b/http_server_test.go
@@ -49,14 +49,14 @@ func TestHttpServer_Decrypt(t *testing.T) {
var httpd *httpServer
- httpd, err = newHttpServer(aww, ``)
+ httpd, err = newHTTPServer(aww, ``)
if err != nil {
t.Fatal(err)
}
var endpointDecrypt = &libhttp.Endpoint{
Method: libhttp.RequestMethodPost,
- Path: pathAwwanApiDecrypt,
+ Path: pathAwwanAPIDecrypt,
RequestType: libhttp.RequestTypeJSON,
ResponseType: libhttp.ResponseTypeJSON,
}
@@ -137,14 +137,14 @@ func TestHttpServer_Encrypt(t *testing.T) {
var httpd *httpServer
- httpd, err = newHttpServer(aww, ``)
+ httpd, err = newHTTPServer(aww, ``)
if err != nil {
t.Fatal(err)
}
var endpointEncrypt = &libhttp.Endpoint{
Method: libhttp.RequestMethodPost,
- Path: pathAwwanApiEncrypt,
+ Path: pathAwwanAPIEncrypt,
RequestType: libhttp.RequestTypeJSON,
ResponseType: libhttp.ResponseTypeJSON,
}
@@ -239,7 +239,7 @@ func TestHttpServer_Execute(t *testing.T) {
clientOpts = libhttp.ClientOptions{
ServerUrl: fmt.Sprintf(`http://%s`, address),
}
- reqJson = tdata.Input[`local:/local.aww:1-`]
+ reqJSON = tdata.Input[`local:/local.aww:1-`]
execRequest ExecRequest
cl *libhttp.Client
@@ -247,7 +247,7 @@ func TestHttpServer_Execute(t *testing.T) {
cl = libhttp.NewClient(&clientOpts)
- err = json.Unmarshal(reqJson, &execRequest)
+ err = json.Unmarshal(reqJSON, &execRequest)
if err != nil {
t.Fatal(err)
}
@@ -257,7 +257,7 @@ func TestHttpServer_Execute(t *testing.T) {
buf bytes.Buffer
)
- _, resBody, err = cl.PostJSON(pathAwwanApiExecute, nil, &execRequest)
+ _, resBody, err = cl.PostJSON(pathAwwanAPIExecute, nil, &execRequest)
if err != nil {
t.Fatal(err)
}
@@ -283,7 +283,7 @@ func TestHttpServer_Execute(t *testing.T) {
// Tail the execution output.
var ssec = sseclient.Client{
- Endpoint: fmt.Sprintf(`http://%s%s?id=%s`, address, pathAwwanApiExecuteTail, execResp.ID),
+ Endpoint: fmt.Sprintf(`http://%s%s?id=%s`, address, pathAwwanAPIExecuteTail, execResp.ID),
}
err = ssec.Connect(nil)
@@ -344,7 +344,7 @@ func TestHttpServer_FSGet(t *testing.T) {
var httpd *httpServer
- httpd, err = newHttpServer(aww, ``)
+ httpd, err = newHTTPServer(aww, ``)
if err != nil {
t.Fatal(err)
}
@@ -380,7 +380,7 @@ func TestHttpServer_FSGet(t *testing.T) {
for _, c = range cases {
t.Log(c.desc)
- httpReq = httptest.NewRequest(http.MethodGet, pathAwwanApiFs+`?path=`+c.path, nil)
+ httpReq = httptest.NewRequest(http.MethodGet, pathAwwanAPIFs+`?path=`+c.path, nil)
httpWriter = httptest.NewRecorder()
diff --git a/session.go b/session.go
index 50356a8..9f33094 100644
--- a/session.go
+++ b/session.go
@@ -615,7 +615,7 @@ func (ses *Session) initSSHClient(req *ExecRequest, sshSection *config.Section)
lastIdentFile = sshSection.IdentityFile[len(sshSection.IdentityFile)-1]
}
- ses.sshc, err = newSshClient(req, sshSection, ses.dirTmp)
+ ses.sshc, err = newSSHClient(req, sshSection, ses.dirTmp)
if err != nil {
return fmt.Errorf(`%s: %w`, logp, err)
}
diff --git a/ssh_client.go b/ssh_client.go
index 519a19c..766e40b 100644
--- a/ssh_client.go
+++ b/ssh_client.go
@@ -30,12 +30,12 @@ type sshClient struct {
dirTmp string
}
-// newSshClient create new clients using the SSH config section.
+// newSSHClient create new clients using the SSH config section.
//
// Once connection established, the client create new temporary directory on
// server at dirTmp for sudoGet or sudoPut operations.
-func newSshClient(req *ExecRequest, section *config.Section, dirTmp string) (sshc *sshClient, err error) {
- var logp = `newSshClient`
+func newSSHClient(req *ExecRequest, section *config.Section, dirTmp string) (sshc *sshClient, err error) {
+ var logp = `newSSHClient`
req.mlog.Outf(`--- SSH connection: %s@%s:%s`,
section.User(), section.Hostname(), section.Port())