From 4071b8a37c2f3fae08871d5f0aecbec03d816edd Mon Sep 17 00:00:00 2001 From: Ioannis Georgoulas Date: Fri, 8 Dec 2023 11:24:40 +0000 Subject: [PATCH] Chore | Migrate to GitHub Actions (#36) * Chore | Migrate to GitHub Actions * add codecov --- .editorconfig | 14 +++++++++ .github/workflows/go.yml | 25 ++++++++++++++++ .github/workflows/golangci-lint.yml | 21 +++++++++++++ .travis.yml | 22 -------------- README.md | 1 - go.mod | 8 +++-- go.sum | 1 - parameter.go | 22 +++++++------- parameter_store_client.go | 46 ++++++++++++++--------------- parameter_store_client_test.go | 2 +- 10 files changed, 101 insertions(+), 61 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/golangci-lint.yml delete mode 100644 .travis.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..80ece02 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +charset = utf-8 +trim_trailing_whitespace = true +end_of_line = lf +insert_final_newline = true + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 + +[*.{markdown,md}] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..68ad3d9 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,25 @@ +name: go + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '^1.21' + + - name: Install dependencies + run: go mod download + + - name: Build + run: go build -v ./... + + - name: Test + run: go test ./... -v -coverprofile coverage.txt -covermode atomic -coverpkg ./... -race + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..e6d8175 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,21 @@ +name: golangci-lint + +on: [push] + +permissions: + contents: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: '^1.21' + + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.54 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7ca2f56..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: go - -go: - - "1.12.x" - - "1.13.x" - - "tip" - -env: - - GO111MODULE=on - -before_install: - - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0 - -install: - - go mod download - -script: - - go test ./... -v -coverprofile coverage.txt -covermode count -coverpkg ./... - - golangci-lint run ./... - -after_script: - - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/README.md b/README.md index 21d3412..9af0a3f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -[![Build Status](https://travis-ci.com/PaddleHQ/go-aws-ssm.svg?branch=master)](https://travis-ci.com/PaddleHQ/go-aws-ssm) [![codecov](https://codecov.io/gh/PaddleHQ/go-aws-ssm/branch/master/graph/badge.svg)](https://codecov.io/gh/PaddleHQ/go-aws-ssm) [![Go Report Card](https://goreportcard.com/badge/github.com/PaddleHQ/go-aws-ssm)](https://goreportcard.com/report/github.com/PaddleHQ/go-aws-ssm) [![GoDoc](https://godoc.org/github.com/PaddleHQ/go-aws-ssm?status.svg)](https://pkg.go.dev/github.com/PaddleHQ/go-aws-ssm) diff --git a/go.mod b/go.mod index 5333cbd..a9d0862 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,15 @@ module github.com/PaddleHQ/go-aws-ssm -go 1.12 +go 1.21 require ( github.com/aws/aws-sdk-go v1.16.24 - github.com/davecgh/go-spew v1.1.1 // indirect github.com/mitchellh/mapstructure v1.1.2 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect github.com/stretchr/testify v1.3.0 // indirect golang.org/x/net v0.0.0-20190119204137-ed066c81e75e // indirect golang.org/x/text v0.3.0 // indirect diff --git a/go.sum b/go.sum index edb2a80..5702120 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,5 @@ github.com/aws/aws-sdk-go v1.16.24 h1:I/A3Hwbgs3IEAP6v1bFpHKXiT7wZDoToX9cb00nxZnM= github.com/aws/aws-sdk-go v1.16.24/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/parameter.go b/parameter.go index 108d0ed..4798ea0 100644 --- a/parameter.go +++ b/parameter.go @@ -8,12 +8,12 @@ import ( "github.com/mitchellh/mapstructure" ) -//Parameter holds a Systems Manager parameter from AWS Parameter Store +// Parameter holds a Systems Manager parameter from AWS Parameter Store type Parameter struct { Value *string } -//GetValue return the actual Value of the parameter +// GetValue return the actual Value of the parameter func (p *Parameter) GetValue() string { if p.Value == nil { return "" @@ -21,7 +21,7 @@ func (p *Parameter) GetValue() string { return *p.Value } -//NewParameters creates a Parameters +// NewParameters creates a Parameters func NewParameters(basePath string, parameters map[string]*Parameter) *Parameters { return &Parameters{ basePath: basePath, @@ -29,7 +29,7 @@ func NewParameters(basePath string, parameters map[string]*Parameter) *Parameter } } -//Parameters holds the output and all AWS Parameter Store that have the same base path +// Parameters holds the output and all AWS Parameter Store that have the same base path type Parameters struct { readIndex int64 bytesJSON []byte @@ -37,7 +37,7 @@ type Parameters struct { parameters map[string]*Parameter } -//Read implements the io.Reader interface for the key/value pair +// Read implements the io.Reader interface for the key/value pair func (p *Parameters) Read(des []byte) (n int, err error) { if p.bytesJSON == nil { p.bytesJSON, err = json.Marshal(p.getKeyValueMap()) @@ -57,8 +57,8 @@ func (p *Parameters) Read(des []byte) (n int, err error) { return n, nil } -//GetValueByName returns the value based on the name -//so the AWS Parameter Store parameter name is base path + name +// GetValueByName returns the value based on the name +// so the AWS Parameter Store parameter name is base path + name func (p *Parameters) GetValueByName(name string) string { parameter, ok := p.parameters[p.basePath+name] if !ok { @@ -67,7 +67,7 @@ func (p *Parameters) GetValueByName(name string) string { return parameter.GetValue() } -//GetValueByFullPath returns the value based on the full path +// GetValueByFullPath returns the value based on the full path func (p *Parameters) GetValueByFullPath(name string) string { parameter, ok := p.parameters[name] if !ok { @@ -76,9 +76,9 @@ func (p *Parameters) GetValueByFullPath(name string) string { return parameter.GetValue() } -//Decode decodes the parameters into the given struct -//We are using this package to decode the values to the struct https://github.com/mitchellh/mapstructure -//For more details how you can use this check the parameter_test.go file +// Decode decodes the parameters into the given struct +// We are using this package to decode the values to the struct https://github.com/mitchellh/mapstructure +// For more details how you can use this check the parameter_test.go file func (p *Parameters) Decode(output interface{}) error { return mapstructure.Decode(p.getKeyValueMap(), output) } diff --git a/parameter_store_client.go b/parameter_store_client.go index ae79c68..30fd56e 100644 --- a/parameter_store_client.go +++ b/parameter_store_client.go @@ -22,18 +22,18 @@ type ssmClient interface { PutParameter(input *ssm.PutParameterInput) (*ssm.PutParameterOutput, error) } -//ParameterStore holds all the methods tha are supported against AWS Parameter Store +// ParameterStore holds all the methods tha are supported against AWS Parameter Store type ParameterStore struct { ssm ssmClient } -//GetAllParametersByPath is returning all the Parameters that are hierarchy linked to this path -//For example a request with path as /my-service/dev/ -//Will return /my-service/dev/param-a, /my-service/dev/param-b, etc... but will not return recursive paths -//the `ssm:GetAllParametersByPath` permission is required -//to the `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/*` +// GetAllParametersByPath is returning all the Parameters that are hierarchy linked to this path +// For example a request with path as /my-service/dev/ +// Will return /my-service/dev/param-a, /my-service/dev/param-b, etc... but will not return recursive paths +// the `ssm:GetAllParametersByPath` permission is required +// to the `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/*` // -//This will also page through and return all elements in the hierarchy, non-recursively +// This will also page through and return all elements in the hierarchy, non-recursively func (ps *ParameterStore) GetAllParametersByPath(path string, decrypt bool) (*Parameters, error) { var input = &ssm.GetParametersByPathInput{} input.SetWithDecryption(decrypt) @@ -58,11 +58,11 @@ func (ps *ParameterStore) getParameters(input *ssm.GetParametersByPathInput) (*P return parameters, nil } -//GetParameter is returning the parameter with the given name -//For example a request with name as /my-service/dev/param-1 -//Will return the parameter value if exists or ErrParameterInvalidName if parameter cannot be found -//The `ssm:GetParameter` permission is required -//to the `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/param-1` resource +// GetParameter is returning the parameter with the given name +// For example a request with name as /my-service/dev/param-1 +// Will return the parameter value if exists or ErrParameterInvalidName if parameter cannot be found +// The `ssm:GetParameter` permission is required +// to the `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/param-1` resource func (ps *ParameterStore) GetParameter(name string, decrypted bool) (*Parameter, error) { if name == "" { return nil, ErrParameterInvalidName @@ -85,21 +85,21 @@ func (ps *ParameterStore) getParameter(input *ssm.GetParameterInput) (*Parameter }, nil } -//PutSecureParameter is setting the parameter with the given name to a passed in value. -//Allow overwriting the value of the parameter already exists, otherwise an error is returned -//For example a request with name as '/my-service/dev/param-1': -//Will set the parameter value if exists or ErrParameterInvalidName if parameter already exists or is empty +// PutSecureParameter is setting the parameter with the given name to a passed in value. +// Allow overwriting the value of the parameter already exists, otherwise an error is returned +// For example a request with name as '/my-service/dev/param-1': +// Will set the parameter value if exists or ErrParameterInvalidName if parameter already exists or is empty // and `overwrite` is false. The `ssm:PutParameter` permission is required to the -//`arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/param-1` resource +// `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/param-1` resource func (ps *ParameterStore) PutSecureParameter(name, value string, overwrite bool) error { return ps.putSecureParameterWrapper(name, value, "", overwrite) } -//PutSecureParameterWithCMK is the same as PutSecureParameter but with a passed in CMK (Customer Master Key) -//For example a request with name as '/my-service/dev/param-1' and a `kmsID` of 'foo': -//Will set the parameter value if exists or ErrParameterInvalidName if parameter already exists or is empty +// PutSecureParameterWithCMK is the same as PutSecureParameter but with a passed in CMK (Customer Master Key) +// For example a request with name as '/my-service/dev/param-1' and a `kmsID` of 'foo': +// Will set the parameter value if exists or ErrParameterInvalidName if parameter already exists or is empty // and `overwrite` is false. The `ssm:PutParameter` permission is required to the -//`arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/param-1` resource +// `arn:aws:ssm:aws-region:aws-account-id:/my-service/dev/param-1` resource // The `kms:Encrypt` permission is required to the `arn:aws:kms:us-east-1:710015040892:key/foo` func (ps *ParameterStore) PutSecureParameterWithCMK(name, value string, overwrite bool, kmsID string) error { return ps.putSecureParameterWrapper(name, value, kmsID, overwrite) @@ -134,12 +134,12 @@ func (ps *ParameterStore) putParameter(input *ssm.PutParameterInput) error { return nil } -//NewParameterStoreWithClient is creating a new ParameterStore with the given ssm Client +// NewParameterStoreWithClient is creating a new ParameterStore with the given ssm Client func NewParameterStoreWithClient(client ssmClient) *ParameterStore { return &ParameterStore{ssm: client} } -//NewParameterStore is creating a new ParameterStore by creating an AWS Session +// NewParameterStore is creating a new ParameterStore by creating an AWS Session func NewParameterStore(ssmConfig ...*aws.Config) (*ParameterStore, error) { sessionAWS, err := session.NewSession(ssmConfig...) if err != nil { diff --git a/parameter_store_client_test.go b/parameter_store_client_test.go index c03f7bc..4722616 100644 --- a/parameter_store_client_test.go +++ b/parameter_store_client_test.go @@ -19,7 +19,7 @@ var param2 = new(ssm.Parameter). SetValue("rds.something.aws.com"). SetARN("arn:aws:ssm:us-east-2:aws-account-id:/my-service/dev/DB_HOST") -// return s.GetParametersByPathOutput, s.GetParametersByPathError +// return s.GetParametersByPathOutput, s.GetParametersByPathError var param3 = new(ssm.Parameter). SetName("/my-service/dev/DB_USERNAME"). SetValue("username").