Skip to content

Commit

Permalink
Chore | Migrate to GitHub Actions (#36)
Browse files Browse the repository at this point in the history
* Chore | Migrate to GitHub Actions

* add codecov
  • Loading branch information
geototti21 authored Dec 8, 2023
1 parent 6982a69 commit 4071b8a
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 61 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
22 changes: 11 additions & 11 deletions parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@ 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 ""
}
return *p.Value
}

//NewParameters creates a Parameters
// NewParameters creates a Parameters
func NewParameters(basePath string, parameters map[string]*Parameter) *Parameters {
return &Parameters{
basePath: basePath,
parameters: parameters,
}
}

//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
basePath string
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())
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
}
Expand Down
46 changes: 23 additions & 23 deletions parameter_store_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion parameter_store_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down

0 comments on commit 4071b8a

Please sign in to comment.