Skip to content

Commit

Permalink
Merge pull request #7 from chroju/v0.3.1
Browse files Browse the repository at this point in the history
v0.3.1
  • Loading branch information
chroju committed Apr 14, 2021
2 parents 8c4bcd4 + fdd15b6 commit c036569
Show file tree
Hide file tree
Showing 21 changed files with 907 additions and 227 deletions.
27 changes: 20 additions & 7 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
name: test
on: pull_request
on:
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
test:
name: Test Parade
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@master
- name: Setup go
uses: actions/setup-go@v1
uses: actions/setup-go@v2
with:
go-version: "1.15.6"
go-version: "1.16.0"
- name: Test all
env:
GO111MODULE: on
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go get golang.org/x/lint/golint
make test
make test-coverage
- name: Install goveralls
env:
GO111MODULE: off
run: go get github.com/mattn/goveralls
- name: Send coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: covprofile
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
jobs:
release:
name: Release Parade
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@master
Expand All @@ -19,7 +19,7 @@ jobs:
uses: goreleaser/goreleaser-action@v2
env:
GO111MODULE: on
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
version: latest
args: release --rm-dist
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

**/parade
**/coverage
20 changes: 15 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,18 @@ archives:
files:
- none*
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
skip: true
brews:
- name: parade
tap:
owner: chroju
name: homebrew-tap
token:
url_template: "https://github.com/chroju/parade/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
description: "Parade is a simple CLI tool for AWS SSM parameter store."
homepage: "https://github.com/chroju/parade"
license: "MIT"
test: |
system "#{bin}/parade --version"
install: |
bin.install "parade"
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# CHANGELOG

## 0.3.1 (2021/04/15)

### BUG FIXES

* Fix bug when running `keys` command with no arguments. (#6)
* Fix bugs with aws region and profile set up.
* Fix `get` command usage typos.

## 0.3.0 (2021/02/23)

* Support Apple silicon.
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ test: lint
crossbuild: test
gox -os="linux darwin windows" -arch="386 amd64" -output "bin/remo_{{.OS}}_{{.Arch}}/{{.Dir}}"

mod:
go mod download

clean:
go clean
rm -f $(BINARY_NAME)
rm -f bin/
rm -f bin/

test-coverage: mod
go test -race -covermode atomic -coverprofile=covprofile ./...
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Parade

[![release badge](https://img.shields.io/github/v/release/chroju/parade.svg)](https://github.com/chroju/parade/releases)
[![test badge](https://github.com/chroju/parade/workflows/test/badge.svg)](https://github.com/chroju/parade/actions?workflow=test)
[![Coverage Status](https://coveralls.io/repos/github/chroju/parade/badge.svg?branch=main)](https://coveralls.io/github/chroju/parade?branch=main)


Parade is a simple CLI tool for AWS SSM parameter store. Easy to read and write key values in your parameter store.

Expand Down
70 changes: 48 additions & 22 deletions cmd/del.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,67 @@ package cmd
import (
"bufio"
"fmt"
"io"
"os"

"github.com/chroju/parade/ssmctl"
"github.com/fatih/color"
"github.com/spf13/cobra"
)

var (
isForceDelete bool
// DelCommand is the command to delete key value
DelCommand = &cobra.Command{
Use: "del <key>",
Short: "Delete key and value in your parameter store.",
Args: cobra.ExactArgs(1),
PreRunE: initializeCredential,
type delOption struct {
Key string
IsForceDelete bool

SSMManager ssmctl.SSMManager

Out io.Writer
ErrOut io.Writer
}

func newDelCommand(globalOption *GlobalOption) *cobra.Command {
o := &delOption{}

cmd := &cobra.Command{
Use: "del <key>",
Short: "Delete key and value in your parameter store.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return del(args)
o.SSMManager = globalOption.SSMManager
if o.SSMManager == nil {
ssmManager, err := initializeCredential(globalOption.Profile, globalOption.Region)
if err != nil {
return err
}
o.SSMManager = ssmManager
}

args = cmd.Flags().Args()
o.Key = args[0]

o.Out = globalOption.Out
o.ErrOut = globalOption.ErrOut

return o.del()
},
}
)

func del(args []string) error {
key := args[0]
cmd.PersistentFlags().BoolVarP(&o.IsForceDelete, "force", "f", false, "Force deletion of key and value\nDefault, display a prompt to confirm that you want to delete")
cmd.SetOut(globalOption.Out)
cmd.SetErr(globalOption.ErrOut)

param, err := ssmManager.GetParameter(key, false)
return cmd
}

func (o *delOption) del() error {
param, err := o.SSMManager.GetParameter(o.Key, false)
if err != nil {
fmt.Fprintln(ErrWriter, color.YellowString(fmt.Sprintf("WARN: `%s` is not found. Nothing to do.", key)))
fmt.Fprintln(o.ErrOut, color.YellowString(fmt.Sprintf("WARN: `%s` is not found. Nothing to do.", o.Key)))
return nil
}

if !isForceDelete {
fmt.Fprintf(ErrWriter, "Delete `%s` (value: %s) ? (Y/n)\n", key, param.Value)
if !o.IsForceDelete {
fmt.Fprintf(o.ErrOut, "Delete `%s` (value: %s) ? (Y/n)\n", o.Key, param.Value)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
yn := scanner.Text()
Expand All @@ -43,18 +73,14 @@ func del(args []string) error {
} else if yn == "N" || yn == "n" {
return nil
} else {
fmt.Fprint(ErrWriter, "(Y/n) ?")
fmt.Fprint(o.ErrOut, "(Y/n) ?")
}
}
}

if err := ssmManager.DeleteParameter(key); err != nil {
if err := o.SSMManager.DeleteParameter(o.Key); err != nil {
return fmt.Errorf("%s\n%s", ErrMsgDeleteParameter, err)
}

return nil
}

func init() {
DelCommand.PersistentFlags().BoolVarP(&isForceDelete, "force", "f", false, "Force deletion of key and value\nDefault, display a prompt to confirm that you want to delete")
}
89 changes: 89 additions & 0 deletions cmd/del_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package cmd

import (
"bytes"
"fmt"
"strings"
"testing"

"github.com/chroju/parade/ssmctl"
)

const (
usageDelHelp = " -h, --help help for del\n\n"
)

func Test_delCommand(t *testing.T) {
voidCmd := newDelCommand(
&GlobalOption{
Out: &bytes.Buffer{},
ErrOut: &bytes.Buffer{},
},
)
tests := []struct {
name string
command string
wantOutWriter string
wantErrWriter string
wantErr bool
}{
{
name: "one arg",
command: "/service1/dev/key1",
wantOutWriter: "",
wantErrWriter: "Delete `/service1/dev/key1` (value: dev_value1) ? (Y/n)\n",
wantErr: false,
},
{
name: "one arg with force option",
command: "/service1/dev/key1 --force",
wantOutWriter: "",
wantErrWriter: "",
wantErr: false,
},
{
name: "two args",
command: "dev prod",
wantOutWriter: fmt.Sprintf("Error: accepts 1 arg(s), received 2\n%s%s", voidCmd.UsageString(), usageDelHelp),
wantErrWriter: "",
wantErr: true,
},
{
name: "no args",
command: "",
wantOutWriter: fmt.Sprintf("Error: accepts 1 arg(s), received 0\n%s%s", voidCmd.UsageString(), usageDelHelp),
wantErrWriter: "",
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ssmManager := ssmctl.NewMockSSMManager()
outWriter := &bytes.Buffer{}
errWriter := &bytes.Buffer{}

o := &GlobalOption{
SSMManager: ssmManager,
Out: outWriter,
ErrOut: errWriter,
}

cmd := newDelCommand(o)
if tt.command != "" {
cmd.SetArgs(strings.Split(tt.command, " "))
}

if err := cmd.Execute(); (err != nil) != tt.wantErr {
t.Errorf("get() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotOutWriter := outWriter.String(); gotOutWriter != tt.wantOutWriter {
t.Errorf("get() = %v, want %v", gotOutWriter, tt.wantOutWriter)
}
if gotErrWriter := errWriter.String(); gotErrWriter != tt.wantErrWriter {
t.Errorf("get() = %v, want %v", gotErrWriter, tt.wantErrWriter)
}
})
}
}
Loading

0 comments on commit c036569

Please sign in to comment.