Skip to content

Commit

Permalink
enable lint (#297)
Browse files Browse the repository at this point in the history
* enable lint

* Iteration 1

* Iteration 2
  • Loading branch information
raghavendra-nataraj authored Jan 3, 2025
1 parent 9608bbf commit 0034fe3
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 19 deletions.
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
44 changes: 44 additions & 0 deletions .pipelines/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,47 @@ jobs:
artifact: binaries
- 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://[email protected]/".insteadOf "https://github.com/"
displayName: 'Set git config'

- script: |
make golangci-lint
displayName: 'Run GolangCI-Lint'
workingDirectory: '$(System.DefaultWorkingDirectory)'
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
GOCMD=go
GOBUILD=$(GOCMD) build -v
GOHOSTOS=$(strip $(shell $(GOCMD) env get GOHOSTOS))
GOPATH_BIN := $(shell go env GOPATH)/bin

TAG ?= $(shell git describe --tags)
COMMIT ?= $(shell git describe --always)
Expand Down Expand Up @@ -42,3 +43,8 @@ format:

unittest:
GOARCH=amd64 go test -v ./services/security/...


golangci-lint:
$(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
$(GOPATH_BIN)/golangci-lint run --config .golangci.yml
2 changes: 1 addition & 1 deletion services/admin/logging/internal/wssd.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *client) GetLogFile(ctx context.Context, location, filename string) erro
}
tempFilename := strconv.FormatInt(time.Now().Unix(), 16) + ".log"
err = loggingHelpers.ReceiveFile(ctx, tempFilename, recFunc)
os.Rename(tempFilename, filename)
os.Rename(tempFilename, filename) //nolint:golint,errcheck
}
if err != doneErr {
return err
Expand Down
2 changes: 1 addition & 1 deletion services/compute/virtualmachine/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ func (c *client) getVirtualMachineOSProfile(o *wssdcloudcompute.OperatingSystemC
osType = compute.Windows
}

osBootstrapEngine := compute.CloudInit
var osBootstrapEngine compute.OperatingSystemBootstrapEngine
switch o.OsBootstrapEngine {
case wssdcommon.OperatingSystemBootstrapEngine_WINDOWS_ANSWER_FILES:
osBootstrapEngine = compute.WindowsAnswerFiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (c *client) getVirtualMachineScaleSetOSProfile(o *wssdcloudcompute.Operatin

ssh := compute.SSHConfiguration{PublicKeys: &publicKeys}

osBootstrapEngine := compute.CloudInit
var osBootstrapEngine compute.OperatingSystemBootstrapEngine
switch o.OsBootstrapEngine {
case wssdcommon.OperatingSystemBootstrapEngine_WINDOWS_ANSWER_FILES:
osBootstrapEngine = compute.WindowsAnswerFiles
Expand Down Expand Up @@ -625,7 +625,7 @@ func (c *client) getWssdVirtualMachineScaleSetOSConfiguration(s *compute.Virtual
adminuser.Password = *s.AdminPassword
}

osBootstrapEngine := wssdcommon.OperatingSystemBootstrapEngine_CLOUD_INIT
var osBootstrapEngine wssdcommon.OperatingSystemBootstrapEngine
switch s.OsBootstrapEngine {
case compute.WindowsAnswerFiles:
osBootstrapEngine = wssdcommon.OperatingSystemBootstrapEngine_WINDOWS_ANSWER_FILES
Expand Down
6 changes: 3 additions & 3 deletions services/network/loadbalancer/wssd.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func getWssdLoadBalancer(networkLB *network.LoadBalancer, group string) (wssdClo
return nil, errors.Wrapf(errors.InvalidInput, "Backend port not specified")
}

protocol := wssdcloudcommon.Protocol_All
var protocol wssdcloudcommon.Protocol

if strings.EqualFold(string(rule.Protocol), string(network.TransportProtocolAll)) {
protocol = wssdcloudcommon.Protocol_All
Expand Down Expand Up @@ -319,7 +319,7 @@ func getLoadBalancer(wssdLB *wssdcloudnetwork.LoadBalancer) (networkLB *network.
for _, loadbalancingrule := range wssdLB.Loadbalancingrules {
frontendport := int32(loadbalancingrule.FrontendPort)
backendport := int32(loadbalancingrule.BackendPort)
protocol := network.TransportProtocolAll
var protocol network.TransportProtocol

if loadbalancingrule.Protocol == wssdcloudcommon.Protocol_All {
protocol = network.TransportProtocolAll
Expand Down Expand Up @@ -347,7 +347,7 @@ func getLoadBalancer(wssdLB *wssdcloudnetwork.LoadBalancer) (networkLB *network.
for _, wssdInboundNatRule := range wssdLB.InboundNatRules {
fePort := int32(wssdInboundNatRule.FrontendPort)
bePort := int32(wssdInboundNatRule.BackendPort)
protocol := network.TransportProtocolAll
var protocol network.TransportProtocol
if wssdInboundNatRule.Protocol == wssdcloudcommon.Protocol_All {
protocol = network.TransportProtocolAll
} else if wssdInboundNatRule.Protocol == wssdcloudcommon.Protocol_Tcp {
Expand Down
6 changes: 3 additions & 3 deletions services/network/networksecuritygroup/wssd.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ func getNetworkSecurityGroup(wssdNSG *wssdcloudnetwork.NetworkSecurityGroup) (ne
for _, rule := range wssdNSG.Networksecuritygrouprules {
name := rule.Name
description := rule.Description
protocol := network.SecurityRuleProtocolAsterisk
action := network.SecurityRuleAccessDeny
direction := network.SecurityRuleDirectionInbound
var protocol network.SecurityRuleProtocol
var action network.SecurityRuleAccess
var direction network.SecurityRuleDirection
priority := uint32(rule.GetPriority())

if rule.Protocol == wssdcloudcommon.Protocol_All {
Expand Down
6 changes: 3 additions & 3 deletions services/security/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func GetMocCSR(csr *security.CertificateRequest) (*wssdcloudsecurity.Certificate
var csrRequest []byte
var err error
if csr.PrivateKey != nil {
pemKey, err := marshal.FromBase64(*csr.PrivateKey)
if err != nil {
return nil, "", err
pemKey, marshalErr := marshal.FromBase64(*csr.PrivateKey)
if marshalErr != nil {
return nil, "", marshalErr
}
csrRequest, key, err = certs.GenerateCertificateRequest(&conf, pemKey)
} else {
Expand Down
12 changes: 6 additions & 6 deletions services/security/keyvault/key/wssd.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *client) get(ctx context.Context, group, vaultName, name string) ([]*wss
// CreateOrUpdate
func (c *client) CreateOrUpdate(ctx context.Context, group, vaultName, name string,
param *keyvault.Key) (*keyvault.Key, error) {
err := c.validate(ctx, group, vaultName, name, param)
err := c.validate(vaultName, name, param)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func ParseAndValidateImportParams(keyValue *string, importKey *wssdcloudsecurity

// Import
func (c *client) ImportKey(ctx context.Context, group, vaultName, name string, param *keyvault.Key) (*keyvault.Key, error) {
err := c.validate(ctx, group, vaultName, name, param)
err := c.validate(vaultName, name, param)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -235,7 +235,7 @@ func GetExportInformationFromResponseKey(responseKey *wssdcloudsecurity.Key) (st

// Export
func (c *client) ExportKey(ctx context.Context, group, vaultName, name string, param *keyvault.Key) (*keyvault.Key, error) {
err := c.validate(ctx, group, vaultName, name, param)
err := c.validate(vaultName, name, param)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -268,16 +268,16 @@ func (c *client) ExportKey(ctx context.Context, group, vaultName, name string, p
return &((*sec)[0]), err
}

func (c *client) validate(ctx context.Context, group, vaultName, name string, param *keyvault.Key) (err error) {
func (c *client) validate(vaultName, name string, param *keyvault.Key) error {
if param == nil {
return errors.Wrapf(errors.InvalidInput, "Invalid Configuration")
}

if len(vaultName) == 0 {
errors.Wrapf(errors.InvalidInput, "Keyvault name is missing")
return errors.Wrapf(errors.InvalidInput, "Keyvault name is missing")
}
if len(name) == 0 {
errors.Wrapf(errors.InvalidInput, "Keyvault name is missing")
return errors.Wrapf(errors.InvalidInput, "Keyvault name is missing")
}

return nil
Expand Down

0 comments on commit 0034fe3

Please sign in to comment.