Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Github WorkFlows to enable lint check #55

Merged
merged 3 commits into from
Aug 2, 2022
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
19 changes: 12 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
name: ci

on: pull_request
on: [pull_request]
jobs:

ci:
runs-on: [self-hosted, Linux, ubuntu]
runs-on: ubuntu-20.04
strategy:
matrix:
go: [ '1.17' ]
steps:

- name: Checkout workspace
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.17

- name: Install necessary tools
run: make tools

- name: Validate lint
run: make lint

- name: Run unit tests
run: make test

- name: Build the code
run: make build

- name: Validate lint
run: make lint
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ all: lint test
.PHONY: all

tools:
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0
.PHONY: tools
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[![CircleCI](https://circleci.com/gh/hpe-hcss/vmaas-cmp-go-sdk.svg?style=svg&circle-token=18e112d5ef6c20a7dc516fc320b8cd2e329af629)](https://circleci.com/gh/hpe-hcss/vmaas-cmp-go-sdk)

# vmaas-cmp-go-sdk
# hpegl-vmaas-cmp-go-sdk

This package provides the official [Go](https://golang.org/) library for the [CMP API](https://docs.greenlake.hpe.com/docs/greenlake/services/private-cloud/internal/openapi/private-cloud-cmp-latest/overview/).
This package provides the official [Go](https://golang.org/) library for the [CMP API](https://developer.greenlake.hpe.com/docs/greenlake/services/private-cloud/internal/openapi/private-cloud-cmp-latest/overview/).

This is being developed in conjunction with the [VMaaS Terraform Provider](https://github.com/hpe-hcss/vmaas-terraform-resources).
This is being developed in conjunction with the [VMaaS Terraform Provider](https://github.com/HewlettPackard/hpegl-vmaas-terraform-resources).

## Sample Usage
```go
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/antihax/optional v1.0.0
github.com/golang/mock v1.6.0
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
golang.org/x/tools v0.1.4 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwc
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/yuin/goldmark v1.3.5 h1:dPmz1Snjq0kmkz159iL7S6WzdahUTHnHB5M56WFVifs=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
Expand All @@ -14,18 +12,15 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
12 changes: 7 additions & 5 deletions golangci-lint-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ linters:
- gomnd
- gochecknoinits
- gochecknoglobals
# - exhaustivestruct
# - forbidigo
- testpackage
- nolintlint
- dupl
- maligned
# Temporarily disabling paralleltest
# - paralleltest
#Temporarily disabling wrapcheck
# - wrapcheck
#Temporarily disabling wrapcheck, exhaustivestruct, forbidigo, tagliatelle
- wrapcheck
- exhaustivestruct
- forbidigo
- tagliatelle
- forcetypeassert
# Disable the 'cyclop' cyclometric complexity linter. 'gocyclo' already
# covers cyclometric complexity, and 'cyclop' has no documentation to
# help with resolving the flagged lints
# - cyclop
- cyclop

issues:

Expand Down
4 changes: 2 additions & 2 deletions pkg/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func (a *api) do(ctx context.Context, request interface{}, queryParams map[strin
// set Accept header
localVarHeaderParams["Accept"] = consts.ContentType

r, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, request,
req, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, request,
localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
if err != nil {
return err
}

localVarHTTPResponse, err := a.client.callAPI(r)
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *APIClient) SetMeta(meta interface{}, fn SetScmClientToken) error {
}
versionInt, err := parseVersion(statusResp.Appliance.BuildVersion)
if err != nil {
return fmt.Errorf("failed to parse cmp build, error: %v", err)
return fmt.Errorf("failed to parse cmp build, error: %w", err)
}
c.cmpVersion = versionInt

Expand Down Expand Up @@ -256,15 +256,15 @@ func (c *APIClient) prepareRequest(
return localVarRequest, nil
}

func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) {
func (c *APIClient) decode(content interface{}, bytes []byte, contentType string) (err error) {
if strings.Contains(contentType, "application/xml") {
if err = xml.Unmarshal(b, v); err != nil {
if err = xml.Unmarshal(bytes, content); err != nil {
return err
}

return nil
} else if strings.Contains(contentType, "application/json") {
if err = json.Unmarshal(b, v); err != nil {
if err = json.Unmarshal(bytes, content); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/client/clouds.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ func (a *CloudsAPIService) GetSpecificCloudDataStores(
func (a *CloudsAPIService) GetSpecificCloudResourcePool(
ctx context.Context,
cloudID int,
id int,
resourcePoolID int,
) (models.GetSpecificCloudResourcePool, error) {
resp := models.GetSpecificCloudResourcePool{}

api := &api{
method: "GET",
path: fmt.Sprintf("%s/%d/%s/%d",
consts.ZonePath, cloudID, consts.ResourcePoolPath, id),
consts.ZonePath, cloudID, consts.ResourcePoolPath, resourcePoolID),
client: a.Client,
jsonParser: func(body []byte) error {
return json.Unmarshal(body, &resp)
Expand Down
14 changes: 7 additions & 7 deletions pkg/client/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ func parseVersion(version string) (int, error) {
}

// Add a file to the multipart request
func addFile(w *multipart.Writer, fieldName, path string) error {
func addFile(writer *multipart.Writer, fieldName, path string) error {
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()

part, err := w.CreateFormFile(fieldName, filepath.Base(path))
part, err := writer.CreateFormFile(fieldName, filepath.Base(path))
if err != nil {
return err
}
Expand All @@ -117,15 +117,15 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
bodyBuf = &bytes.Buffer{}
}

switch v := body.(type) {
switch bodyType := body.(type) {
case io.Reader:
_, err = bodyBuf.ReadFrom(v)
_, err = bodyBuf.ReadFrom(bodyType)
case []byte:
_, err = bodyBuf.Write(v)
_, err = bodyBuf.Write(bodyType)
case string:
_, err = bodyBuf.WriteString(v)
_, err = bodyBuf.WriteString(bodyType)
case *string:
_, err = bodyBuf.WriteString(*v)
_, err = bodyBuf.WriteString(*bodyType)
default:
if jsonCheck.MatchString(contentType) {
err = json.NewEncoder(bodyBuf).Encode(body)
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/virtual_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func (a *VirtualImagesAPIService) GetAllVirtualImages(ctx context.Context,

func (a *VirtualImagesAPIService) GetSpecificVirtualImage(
ctx context.Context,
id int,
virtualImageID int,
) (models.GetSpecificVirtualImage, error) {
response := models.GetSpecificVirtualImage{}

api := &api{
method: "GET",
path: fmt.Sprintf("%s/%d", consts.VirtualImagePath, id),
path: fmt.Sprintf("%s/%d", consts.VirtualImagePath, virtualImageID),
client: a.Client,

jsonParser: func(body []byte) error {
Expand Down