Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Require lint #41

Merged
merged 3 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ func NewCleanCmd() *cobra.Command {
return &cobra.Command{
Use: "clean SUBCOMMAND",
Short: "clean objects",
Long: descAddLong,
Long: descCleanLong,
}
}
2 changes: 1 addition & 1 deletion pkg/cmd/show_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s showContextCmd) runFunc() CommandRunnerFunc {
ctx.Current = rcontext.DefaultCtx
}

fmt.Println(fmt.Sprintf("Current context: %s", ctx.Current))
fmt.Printf("Current context: %s", ctx.Current)

return nil
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/credential/credsingle/finder_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package credsingle

import (
"fmt"
"os"
"reflect"
"testing"
Expand All @@ -11,7 +12,11 @@ import (
func TestFind(t *testing.T) {
tmp := os.TempDir()
setter := NewSetter(tmp, ctxFinder, sessManager)
setter.Set(githubCred)
err := setter.Set(githubCred)
if err != nil {
fmt.Sprintf("Error in Set")
return
}
finder := NewFinder(tmp, ctxFinder, sessManager)

type out struct {
Expand Down
7 changes: 6 additions & 1 deletion pkg/credential/credteam/credteam_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package credteam

import (
"fmt"
"github.com/ZupIT/ritchie-cli/pkg/credential"
"github.com/ZupIT/ritchie-cli/pkg/rcontext"
"github.com/ZupIT/ritchie-cli/pkg/session"
Expand Down Expand Up @@ -59,6 +60,10 @@ func TestMain(m *testing.M) {
func mockServer(status int, body []byte) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(status)
rw.Write(body)
_, err := rw.Write(body)
if err != nil {
fmt.Sprintf("Error in Write")
return
}
}))
}
12 changes: 10 additions & 2 deletions pkg/crypto/cryptoutil/crypto_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ func SumHashMachine(text string) ([]byte, error) {
}

hash := sha256.New()
hash.Write([]byte(text))
hash.Write([]byte(id))
_, err = hash.Write([]byte(text))
if err != nil {
return nil, err
}

_, err = hash.Write([]byte(id))
if err != nil {
return nil, err
}

sum := hash.Sum(nil)

return sum, nil
Expand Down
12 changes: 9 additions & 3 deletions pkg/file/fileutil/file_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ func CreateDirIfNotExists(dir string, perm os.FileMode) error {
}

// CreateFileIfNotExist creates file if not exists
func CreateFileIfNotExist(file string, content []byte) {
func CreateFileIfNotExist(file string, content []byte) error {
if _, err := os.Stat(file); os.IsNotExist(err) {
WriteFile(file, content)
if err := WriteFile(file, content); err != nil {
return err
}
}
return nil
}

// RemoveDir removes path and any children it contains.
Expand Down Expand Up @@ -198,7 +201,10 @@ func Unzip(src string, dest string) error {

if file.FileInfo().IsDir() {
log.Println("Directory Created:", extractedFilePath)
os.MkdirAll(extractedFilePath, file.Mode())
err := os.MkdirAll(extractedFilePath, file.Mode())
if err != nil {
return err
}
} else {
log.Println("File extracted:", file.Name)

Expand Down
11 changes: 8 additions & 3 deletions pkg/formula/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ func (c CreateManager) Create(fCmd string) error {
}

if fileutil.Exists(fmt.Sprintf(TreeCreatePathPattern, c.formPath)) && (fileutil.Exists(fmt.Sprintf("%s/%s", c.formPath, Makefile))) {
generateFormulaFiles(c.formPath, fCmd, false)

err = generateFormulaFiles(c.formPath, fCmd, false)
if err != nil {
return err
}
} else {
generateFormulaFiles(c.formPath, fCmd, true)
err = generateFormulaFiles(c.formPath, fCmd, true)
if err != nil {
return err
}
}
err = generateTreeJsonFile(c.formPath, fCmd)
if err != nil {
Expand Down
18 changes: 13 additions & 5 deletions pkg/formula/default_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type RepoManager struct {
homePath string
httpClient *http.Client
sessionManager session.Manager
serverURL string
serverURL string
}

// ByPriority implements sort.Interface for []Repository based on
Expand All @@ -63,7 +63,7 @@ func NewTeamRepoManager(homePath string, serverURL string, hc *http.Client, sm s
repoFile: fmt.Sprintf(repositoryConfFilePattern, homePath),
cacheFile: fmt.Sprintf(repositoryCacheFolderPattern, homePath),
homePath: homePath,
serverURL : serverURL,
serverURL: serverURL,
httpClient: hc,
sessionManager: sm,
}
Expand All @@ -81,7 +81,9 @@ func (dm RepoManager) Add(r Repository) error {
defer cancel()
locked, err := lock.TryLockContext(lockCtx, time.Second)
if locked {
defer lock.Unlock()
defer func() {
_ = lock.Unlock()
}()
}
if err != nil {
return err
Expand All @@ -92,7 +94,10 @@ func (dm RepoManager) Add(r Repository) error {
if err != nil {
return err
}
fileutil.WriteFile(dm.repoFile, wb)
err = fileutil.WriteFile(dm.repoFile, wb)
if err != nil {
return err
}
}

rb, err := fileutil.ReadFile(dm.repoFile)
Expand Down Expand Up @@ -247,7 +252,10 @@ func (dm RepoManager) Load() error {
}

for _, v := range dd {
dm.Add(v)
err = dm.Add(v)
if err != nil {
return err
}
}

return nil
Expand Down
7 changes: 6 additions & 1 deletion pkg/formula/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ func (d DefaultRunner) persistCache(formulaPath, inputVal string, input Input, i
items = items[0:qtd]
}
itemsBytes, _ := json.Marshal(items)
fileutil.WriteFile(cachePath, itemsBytes)
err := fileutil.WriteFile(cachePath, itemsBytes)
if err != nil {
fmt.Sprintf("Error in WriteFile")
return
}

}
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -62,12 +61,6 @@ func (s Sender) SendCommand() {
}

defer resp.Body.Close()

b, err = ioutil.ReadAll(resp.Body)
if err != nil {
return
}

}

func cmd() string {
Expand Down
7 changes: 6 additions & 1 deletion pkg/rcontext/finder_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rcontext

import (
"fmt"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -52,7 +53,11 @@ func TestFind(t *testing.T) {

in := tt.in
if in != nil {
setter.Set(in.ctx)
_, err := setter.Set(in.ctx)
if err != nil {
fmt.Sprintf("Error in Set")
return
}
}

out := tt.out
Expand Down
13 changes: 11 additions & 2 deletions pkg/rcontext/remover_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rcontext

import (
"fmt"
"os"
"reflect"
"testing"
Expand All @@ -12,8 +13,16 @@ func TestRemove(t *testing.T) {
setter := NewSetter(tmp, finder)
remover := NewRemover(tmp, finder)

setter.Set(dev)
setter.Set(qa)
_, err := setter.Set(dev)
if err != nil {
fmt.Sprintf("Error in Set")
return
}
_, err = setter.Set(qa)
if err != nil {
fmt.Sprintf("Error in Set")
return
}

type out struct {
want ContextHolder
Expand Down
22 changes: 16 additions & 6 deletions pkg/security/oauth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"errors"
"fmt"
"github.com/ZupIT/ritchie-cli/pkg/security"
"net/http"

"github.com/coreos/go-oidc"
"golang.org/x/oauth2"
"net/http"

"github.com/ZupIT/ritchie-cli/pkg/security"
)

const (
Expand Down Expand Up @@ -65,13 +67,13 @@ const (
)

type LoginManager struct {
Resp chan security.ChanResponse
Resp chan security.ChanResponse
serverURL string
}

func NewLoginManager(resp chan security.ChanResponse, serverURL string) *LoginManager {
return &LoginManager{
Resp: resp,
Resp: resp,
serverURL: serverURL,
}
}
Expand Down Expand Up @@ -146,8 +148,16 @@ func (l LoginManager) handlerLogin(provider *oidc.Provider, state string, oauth2
Email string `json:"email"`
Username string `json:"preferred_username"`
}{}
idToken.Claims(&user)
w.Write([]byte(htmlLogin))
err = idToken.Claims(&user)
if err != nil {
fmt.Sprintf("Error in Claims")
return
}
_, err = w.Write([]byte(htmlLogin))
if err != nil {
fmt.Sprintf("Error in Write")
return
}
l.Resp <- security.ChanResponse{
Token: token,
Username: user.Username,
Expand Down
14 changes: 9 additions & 5 deletions pkg/security/oauth/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ const (
)

type LogoutManager struct {
Resp chan security.ChanResponse
Org string
Resp chan security.ChanResponse
Org string
serverURL string
}

func NewLogoutManager(org string, resp chan security.ChanResponse, serverURL string) *LogoutManager {
return &LogoutManager{
Resp: resp,
Org: org,
Resp: resp,
Org: org,
serverURL: serverURL,
}
}
Expand All @@ -94,7 +94,11 @@ func (l *LogoutManager) Logout() error {

func (l *LogoutManager) handlerLogout() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(htmlLogout))
_, err := w.Write([]byte(htmlLogout))
if err != nil {
fmt.Sprintf("Error in Write")
return
}
l.Resp <- security.ChanResponse{}
}
}
6 changes: 5 additions & 1 deletion pkg/security/oauth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ func providerConfig(organization, serverURL string) (ProviderConfig, error) {
return provideConfig, fmt.Errorf("Failed parse response to body: %s\n", string(bodyBytes))
}

json.Unmarshal(bodyBytes, &provideConfig)
err = json.Unmarshal(bodyBytes, &provideConfig)
if err != nil {
return provideConfig, err
}

return provideConfig, nil
}

Expand Down
18 changes: 16 additions & 2 deletions pkg/security/secteam/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package secteam

import (
"fmt"

"github.com/ZupIT/ritchie-cli/pkg/security"
"github.com/ZupIT/ritchie-cli/pkg/security/oauth"
)
Expand All @@ -10,7 +12,13 @@ func loginChannelProvider(p security.AuthProvider, org, serverURL string) (chan
switch p {
case security.OAuthProvider:
oauthCli := oauth.NewLoginManager(cr, serverURL)
go oauthCli.Login(org)
go func() {
err := oauthCli.Login(org)
if err != nil {
fmt.Sprintf("Error in Login")
return
}
}()
default:
return nil, security.ErrUnknownProvider
}
Expand All @@ -22,7 +30,13 @@ func logoutChannelProvider(p security.AuthProvider, org, serverURL string) (chan
switch p {
case security.OAuthProvider:
oauthCli := oauth.NewLogoutManager(org, cr, serverURL)
go oauthCli.Logout()
go func() {
err := oauthCli.Logout()
if err != nil {
fmt.Sprintf("Error in Logout")
return
}
}()
default:
return nil, security.ErrUnknownProvider
}
Expand Down
Loading