diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4728b3..78f172e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 \ No newline at end of file diff --git a/Makefile b/Makefile index 34f4c27..52c108a 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 70de11c..914e293 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/go.mod b/go.mod index ed9547f..bd8c7dc 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 7fb2ffb..57593db 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -14,7 +12,6 @@ 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= @@ -22,10 +19,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w 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= diff --git a/golangci-lint-config.yaml b/golangci-lint-config.yaml index c78720b..5b23ce4 100644 --- a/golangci-lint-config.yaml +++ b/golangci-lint-config.yaml @@ -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: diff --git a/pkg/client/api.go b/pkg/client/api.go index ad63436..19dd963 100644 --- a/pkg/client/api.go +++ b/pkg/client/api.go @@ -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 } diff --git a/pkg/client/client.go b/pkg/client/client.go index e6c63d8..7e5a514 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -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 @@ -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 } diff --git a/pkg/client/clouds.go b/pkg/client/clouds.go index c46d29b..f1cf3af 100644 --- a/pkg/client/clouds.go +++ b/pkg/client/clouds.go @@ -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) diff --git a/pkg/client/helper.go b/pkg/client/helper.go index 5da9482..1b00d18 100644 --- a/pkg/client/helper.go +++ b/pkg/client/helper.go @@ -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 } @@ -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) diff --git a/pkg/client/virtual_images.go b/pkg/client/virtual_images.go index ceb8592..f1bff69 100644 --- a/pkg/client/virtual_images.go +++ b/pkg/client/virtual_images.go @@ -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 {