diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index a6968227..00000000 --- a/.golangci.yml +++ /dev/null @@ -1,21 +0,0 @@ -run: - timeout: 15m - tests: false # Exclude test files from linting - -# Linter options and descriptions: https://golangci-lint.run/usage/linters/ -linters: - enable: - - errcheck - - govet - - ineffassign - - staticcheck - disable: - # Disabling these two default linters for now as their checks are not a priority - - gosimple - - unused - -linters-settings: - staticcheck: - checks: - - all - - -SA1019 # Ignore pkg deprecation warnings from staticcheck \ No newline at end of file diff --git a/.pipelines/build.yaml b/.pipelines/build.yaml index f3bccbad..ee8f0efd 100644 --- a/.pipelines/build.yaml +++ b/.pipelines/build.yaml @@ -63,47 +63,3 @@ jobs: - publish: $(System.DefaultWorkingDirectory)/manifest artifact: manifest - -- job: Lint - displayName: 'Lint' - - pool: - vmImage: 'ubuntu-latest' - - variables: - - group: moc-build - - name: GO111MODULE - value: 'on' - - steps: - - task: GoTool@0 - inputs: - version: '1.22.5' - - - task: InstallSSHKey@0 - inputs: - knownHostsEntry: | - $(KNOWN_HOST_GITHUB) - $(KNOWN_HOST_GITHUB_ECDSA) - $(KNOWN_HOST_GITHUB_Ed25519) - sshPublicKey: '$(SSH_PUBLIC_KEY)' - sshKeySecureFile: 'azure-pipelines-ssh-key-new' - - - task: AzureCLI@2 - inputs: - azureSubscription: 'kva-azuredevops-gcm' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - # Obtain Azure DevOps access token - aadToken=$(az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv) - - # Set git configuration for authentication - git config --global http.extraheader "AUTHORIZATION: bearer $aadToken" - git config --global url."ssh://git@github.com/".insteadOf "https://github.com/" - displayName: 'Set git config' - - - script: | - make golangci-lint - displayName: 'Run GolangCI-Lint' - workingDirectory: '$(System.DefaultWorkingDirectory)' diff --git a/Makefile b/Makefile index 18247fb5..5bbef6bc 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ GOBUILD=$(GOCMD) build -v #-mod=vendor GOTEST=$(GOCMD) test -v GOHOSTOS=$(strip $(shell $(GOCMD) env get GOHOSTOS)) MOCKGEN=$(shell command -v mockgen 2> /dev/null) -GOPATH_BIN := $(shell go env GOPATH)/bin # Private repo workaround export GOPRIVATE = github.com/microsoft @@ -52,7 +51,3 @@ mocks: go get github.com/golang/mock@v1.6.0 go generate ./... -golangci-lint: - $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - $(GOPATH_BIN)/golangci-lint run --config .golangci.yml - diff --git a/go.mod b/go.mod index d82a4636..a639b769 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/microsoft/moc -go 1.22.4 +go 1.22 require ( github.com/golang-jwt/jwt v3.2.2+incompatible diff --git a/pkg/auth/auth_env.go b/pkg/auth/auth_env.go index dbaece16..c896f6d9 100644 --- a/pkg/auth/auth_env.go +++ b/pkg/auth/auth_env.go @@ -81,14 +81,13 @@ func GetWssdConfigLocation() string { // Create the default config path and set the // env variable defaultPath = filepath.Join(wd, DefaultWSSDFolder) - os.Setenv(AccessFileDirPath, defaultPath) //nolint:golint,errcheck + os.Setenv(AccessFileDirPath, defaultPath) } if execName, err := getExecutableName(); err == nil { defaultPath = filepath.Join(defaultPath, execName) } - // needs to be fixed later since a large number of repos use this - os.MkdirAll(defaultPath, os.ModePerm) //nolint:golint,errcheck + os.MkdirAll(defaultPath, os.ModePerm) accessFilePath := filepath.Join(defaultPath, AccessFileDefaultName) return accessFilePath } @@ -109,9 +108,9 @@ func GetMocConfigLocationName(subfolder, filename string) string { // Create the default config path and set the // env variable defaultPath := filepath.Join(wd, DefaultWSSDFolder, subfolder) - os.MkdirAll(defaultPath, os.ModePerm) //nolint:golint,errcheck + os.MkdirAll(defaultPath, os.ModePerm) wssdConfigPath = filepath.Join(defaultPath, file) - os.Setenv(WssdConfigPath, wssdConfigPath) //nolint:golint,errcheck + os.Setenv(WssdConfigPath, wssdConfigPath) } return wssdConfigPath } @@ -127,9 +126,9 @@ func getClientTokenLocation() string { // Create the default token path and set the // env variable defaultPath := filepath.Join(wd, DefaultWSSDFolder) - os.MkdirAll(defaultPath, os.ModePerm) //nolint:golint,errcheck + os.MkdirAll(defaultPath, os.ModePerm) clientTokenPath = filepath.Join(defaultPath, ClientTokenName) - os.Setenv(ClientTokenPath, clientTokenPath) //nolint:golint,errcheck + os.Setenv(ClientTokenPath, clientTokenPath) } return clientTokenPath } diff --git a/pkg/auth/utils.go b/pkg/auth/utils.go index 12fbb08b..c867155e 100644 --- a/pkg/auth/utils.go +++ b/pkg/auth/utils.go @@ -67,9 +67,6 @@ func GenerateClientCsr(loginconfig LoginConfig) (string, WssdConfig, error) { return "", WssdConfig{}, err } accessFile, err := readAccessFile(GetWssdConfigLocation()) - if err != nil { - return "", WssdConfig{}, err - } cloudAgentIpAddress, err := wssdnet.GetIPAddress() if err != nil { return "", WssdConfig{}, err diff --git a/pkg/certs/certificateAuthority.go b/pkg/certs/certificateAuthority.go index bb16b0ad..6229aa2b 100644 --- a/pkg/certs/certificateAuthority.go +++ b/pkg/certs/certificateAuthority.go @@ -176,9 +176,6 @@ func (ca *CertificateAuthority) SignRequest(csrPem []byte, oldCertPem []byte, co return nil, errors.Wrapf(errors.InvalidInput, "Old certificate verification failed : %v", err) } oldCert, err = DecodeCertPEM(oldCertPem) - if err != nil { - return - } } err = csr.CheckSignature() if err != nil { @@ -305,9 +302,7 @@ func (ca *CertificateAuthority) SignRequest(csrPem []byte, oldCertPem []byte, co if ext.Id.Equal(oidOriginalCertificate) { origCertDER = ext.Value } else if ext.Id.Equal(oidRenewCount) { - if _, err := asn1.Unmarshal(ext.Value, &renewCount); err != nil { - return nil, errors.Wrapf(err, "Failed to unmarshall renew count") - } + asn1.Unmarshal(ext.Value, &renewCount) } } diff --git a/pkg/config/config.go b/pkg/config/config.go index 2ea2fb0a..879ac8d8 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -154,9 +154,7 @@ func MarshalOutput(data interface{}, query string, outputType string) ([]byte, e if err != nil { return nil, err } - if err := marshal.FromJSONBytes(jsonByte, &queryTarget); err != nil { - return nil, err - } + marshal.FromJSONBytes(jsonByte, &queryTarget) if query != "" { result, err = jmespath.Search(query, queryTarget) if err != nil { diff --git a/pkg/logging/loggingRedirect.go b/pkg/logging/loggingRedirect.go index 519cfa50..44f7f8f8 100644 --- a/pkg/logging/loggingRedirect.go +++ b/pkg/logging/loggingRedirect.go @@ -20,9 +20,7 @@ var ( func createLogFile(logFileAbsolutePath string, logFileName string) (*os.File, error) { // Create log path - if err := os.MkdirAll(logFileAbsolutePath, os.ModeDir); err != nil { - return nil, err - } + os.MkdirAll(logFileAbsolutePath, os.ModeDir) err := path.CheckPath(logFileAbsolutePath) if err != nil { @@ -42,9 +40,7 @@ func createLogFile(logFileAbsolutePath string, logFileName string) (*os.File, er // If there are contents in the file already, move the file and replace it. if st.Size() > 0 { logFile.Close() - if err := os.Rename(path, path+".old"); err != nil { - return nil, err - } + os.Rename(path, path+".old") logFile, err = os.Create(path) if err != nil { return nil, err diff --git a/pkg/logging/redirectstderr_linux.go b/pkg/logging/redirectstderr_linux.go index 7f4139ab..dcbc915a 100644 --- a/pkg/logging/redirectstderr_linux.go +++ b/pkg/logging/redirectstderr_linux.go @@ -10,6 +10,7 @@ import ( func RedirectStdErr(file *os.File) { err := syscall.Dup3(int(file.Fd()), int(os.Stderr.Fd()), 0) - if err != nil { //nolint:golint,staticcheck + if err != nil { } + return } diff --git a/pkg/status/status.go b/pkg/status/status.go index 8712b735..bb527d93 100644 --- a/pkg/status/status.go +++ b/pkg/status/status.go @@ -197,27 +197,27 @@ func GetFromStatuses(statuses map[string]*string) (status *common.Status) { status = &common.Status{} if val, ok := statuses["ProvisionState"]; ok { ps := new(common.ProvisionStatus) - proto.UnmarshalText(*val, ps) //nolint:golint,errcheck + proto.UnmarshalText(*val, ps) status.ProvisioningStatus = ps } if val, ok := statuses["HealthState"]; ok { ps := new(common.Health) - proto.UnmarshalText(*val, ps) //nolint:golint,errcheck + proto.UnmarshalText(*val, ps) status.Health = ps } if val, ok := statuses["Error"]; ok { ps := new(common.Error) - proto.UnmarshalText(*val, ps) //nolint:golint,errcheck + proto.UnmarshalText(*val, ps) status.LastError = ps } if val, ok := statuses["DownloadStatus"]; ok { ps := new(common.DownloadStatus) - proto.UnmarshalText(*val, ps) //nolint:golint,errcheck + proto.UnmarshalText(*val, ps) status.DownloadStatus = ps } if val, ok := statuses["PlacementStatus"]; ok { ps := new(common.PlacementStatus) - proto.UnmarshalText(*val, ps) //nolint:golint,errcheck + proto.UnmarshalText(*val, ps) status.PlacementStatus = ps } if val, ok := statuses["UploadStatus"]; ok { diff --git a/pkg/validations/proxy_validation.go b/pkg/validations/proxy_validation.go index f77a2c95..426f11cb 100644 --- a/pkg/validations/proxy_validation.go +++ b/pkg/validations/proxy_validation.go @@ -18,7 +18,7 @@ func ValidateProxyURL(proxyURL string) (*url.URL, error) { parsedURL, err := url.ParseRequestURI(proxyURL) if err != nil { - return nil, errors.Wrapf(errors.InvalidInput, "%s", err.Error()) + return nil, errors.Wrapf(errors.InvalidInput, err.Error()) } // Check if url scheme is http or https @@ -54,7 +54,7 @@ func TestProxyUrlConnection(parsedURL *url.URL, certContent string, getRequestUr // Test the HTTP GET request response, err := client.Get(getRequestUrl) if err != nil { - return errors.Wrapf(errors.InvalidInput, "%s", err.Error()) + return errors.Wrapf(errors.InvalidInput, err.Error()) } else { defer response.Body.Close() fmt.Println("Connected successfully to the proxy server")