Skip to content

Commit

Permalink
Merge pull request #23 from tonedefdev/dependabot/go_modules/golang.o…
Browse files Browse the repository at this point in the history
…rg/x/text-0.3.8

Bump golang.org/x/text from 0.3.7 to 0.3.8
  • Loading branch information
tonedefdev authored Feb 24, 2023
2 parents 2e4becb + ed1d9a7 commit c099e89
Show file tree
Hide file tree
Showing 22 changed files with 200 additions and 494 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: macOS Build

on:
push:
branches:
- main
pull_request:
branches:
- main
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/ubuntu-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Ubuntu Build

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test-mac:
name: Build and Test Ubuntu
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.19
id: go
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Build
run: |
mkdir $HOME/.terraform.d
go build .
env:
HOME: /home/runner
- name: Test
run: |
export PATH=$PATH:$PWD
cd cmd
go test -v -cover
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Windows Build

on:
push:
branches:
- main
pull_request:
branches:
- main
Expand Down
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![macOS Build](https://github.com/tonedefdev/terracreds/actions/workflows/macos-pr-build-test.yml/badge.svg?branch=hotfix)](https://github.com/tonedefdev/terracreds/actions/workflows/macos-pr-build-test.yml) [![Windows Build](https://github.com/tonedefdev/terracreds/actions/workflows/win-pr-build-test.yml/badge.svg?branch=hotfix)](https://github.com/tonedefdev/terracreds/actions/workflows/win-pr-build-test.yml)
[![macOS Build](https://github.com/tonedefdev/terracreds/actions/workflows/macos-build.yml/badge.svg?branch=main)](https://github.com/tonedefdev/terracreds/actions/workflows/macos-build.yml) [![Ubuntu Build](https://github.com/tonedefdev/terracreds/actions/workflows/ubuntu-build.yml/badge.svg?branch=main)](https://github.com/tonedefdev/terracreds/actions/workflows/ubuntu-build.yml) [![Windows Build](https://github.com/tonedefdev/terracreds/actions/workflows/windows-build.yml/badge.svg?branch=main)](https://github.com/tonedefdev/terracreds/actions/workflows/window-build.yml)

<img src="./img/terracreds.png" align="right" width="350" height="350">

Expand Down Expand Up @@ -78,10 +78,16 @@ brew install tonedefdev/terracreds/terracreds
You'll need to download the latest binary from our release page and place it anywhere on `$PATH` of your system. You can also copy and run the following commands:

```bash
wget https://github.com/tonedefdev/terracreds/releases/download/v2.1.3/terracreds_2.1.3_linux_amd64.tar.gz && \
tar -xvf terracreds_2.1.3_linux_amd64.tar.gz && \
VERSION="<REPLACE_WITH_DESIRED_VERSION_FROM_GITHUB_RELEASES>" \
wget https://github.com/tonedefdev/terracreds/releases/download/v${VERSION}/terracreds_${VERSION}_linux_amd64.tar.gz && \
tar -xvf terracreds_${VERSION}_linux_amd64.tar.gz && \
sudo mv -f terracreds /usr/bin/terracreds && \
rm -f terracreds_2.1.3_linux_amd64.tar.gz README.md
rm -f terracreds_${VERSION}_linux_amd64.tar.gz README.md
```

You can also use `homebrew` to install on `Ubuntu` machines where `brew` is available:
```bash
brew install tonedefdev/terracreds/terracreds
```

The `terracreds` Linux implementation uses `gnome-keyring` in conjunction with `gnome-keyring-daemon`
Expand Down Expand Up @@ -132,12 +138,12 @@ go install -v
Navigate to the root of the project directory and you should see the `terracreds.exe` binary for Windows or `terracreds` for macOS and Linux. On Windows, copy the `.exe` to any directory of your choosing. Be sure to add the directory on `$env:PATH` for Windows to make using the application easier. On macOS and Linux we recommend you place the binary in `/usr/bin` as this directory should already be on the `$PATH` environment variable.

## Upgrading
If you're upgrading to the latest version of `terracreds` from a previous version use one of the methods above to install the latest binary. Once successfully installed on your system you just need to run `terracreds generate` to copy the latest version to the correct `plugins` directory for your operating system.
If you're upgrading to the latest version of `terracreds` from a previous version use one of the methods above to either install the latest binary or use the package manager for your specific operating system. Once successfully installed on your system you just need to run `terracreds generate` to copy the latest version to the correct `plugins` directory for your operating system.

## Initial Configuration
In order for `terracreds` to act as your credential provider you'll need to generate the binary and the plugin directory in the default location that Terraform looks for plugins. Specifically, for credential helpers, and for Windows, the directory is `%APPDATA%\terraform.d\plugins` and for macOS and Linux `$HOME/.terraform.d/.terraformrc`.

To make things as simple as possible we created a helper command to generate everthing needed to use the app. All you need to do is run the following command in `terracreds` to generate the plugin directory, and the correctly formatted binary that Terraform will use:
To make things as simple as possible we created a helper command to generate everything needed to use the app. All you need to do is run the following command in `terracreds` to generate the plugin directory, and the correctly formatted binary that Terraform will use:
```bash
terracreds generate
```
Expand Down Expand Up @@ -262,7 +268,7 @@ The above example would maintain the dash `[-]` in the output of the formatted T
Additionally, you can use `--as-json` to return the secret names and values as a JSON string. This is printed to standard output so you can make use of shell pipes and other commands to ingest the data.

## Setting Up a Vault Provider
> We have example [terraform](https://github.com/tonedefdev/terracreds/tree/main/terraform) code you can reference in order to setup your `AWS` or `Azure` VMs to use `terracreds` for a CI/CD piepline agent or a development workstation.
> We have example [terraform](https://github.com/tonedefdev/terracreds/tree/main/terraform) code you can reference in order to setup your `AWS` or `Azure` VMs to use `terracreds` for a CI/CD pipeline agent or a development workstation.
> New in version `2.1.0`
Expand Down
7 changes: 6 additions & 1 deletion cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/tonedefdev/terracreds/api"
"github.com/urfave/cli/v2"
"github.com/zalando/go-keyring"
)

func app() *cli.App {
Expand All @@ -23,7 +24,11 @@ func config() Config {
ConfigFile: ConfigFile{
Path: path,
},
TerraCreds: NewTerraCreds(runtime.GOOS),
TerraCreds: NewTerraCreds(),
}

if runtime.GOOS == "linux" {
keyring.MockInit()
}

return config
Expand Down
12 changes: 8 additions & 4 deletions cmd/create.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package cmd

import (
"fmt"
"os"
"os/user"

"github.com/fatih/color"
"github.com/tonedefdev/terracreds/pkg/errors"
"github.com/tonedefdev/terracreds/pkg/helpers"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -42,8 +41,13 @@ func (cmd *Config) NewCommandCreate() *cli.Command {
// newCommandActionCreate creates the secret based on the OS and type of vault
func (cmd *Config) newCommandActionCreate(c *cli.Context) error {
if len(os.Args) == 2 {
fmt.Fprintf(color.Output, "%s: No secret name or secret was specified. Use 'terracreds create -h' to print help info\n", color.RedString("ERROR"))
return nil
err := &errors.CustomError{
Message: "No secret name or secret was specified. Use 'terracreds create -h' to print help info",
Level: "ERROR",
}

helpers.Logging(cmd.Cfg, err.Message, err.Level)
return err
}

terraVault := cmd.NewTerraVault(c.String("name"))
Expand Down
10 changes: 8 additions & 2 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/fatih/color"
"github.com/tonedefdev/terracreds/pkg/errors"
"github.com/tonedefdev/terracreds/pkg/helpers"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -36,8 +37,13 @@ func (cmd *Config) NewCommandDelete() *cli.Command {
// newCommandActionDelete deletes the secret based on the type of vault
func (cmd *Config) newCommandActionDelete(c *cli.Context) error {
if len(os.Args) == 2 {
fmt.Fprintf(color.Output, "%s: No secret name was specified. Use 'terracreds delete -h' for help info\n", color.RedString("ERROR"))
return nil
err := &errors.CustomError{
Message: "No secret name was specified. Use 'terracreds delete -h' to print help info",
Level: "ERROR",
}

helpers.Logging(cmd.Cfg, err.Message, err.Level)
return err
}

if !strings.Contains(os.Args[2], "-n") && !strings.Contains(os.Args[2], "--name") {
Expand Down
5 changes: 5 additions & 0 deletions cmd/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ func TestNewCommandActionDelete(t *testing.T) {
terracreds := config()
app := app()
app.Commands = []*cli.Command{
terracreds.NewCommandCreate(),
terracreds.NewCommandDelete(),
}

args := os.Args[0:1]
args = append(args, "create", "--name=test", "--secret=password")
app.Run(args)

args = os.Args[0:1]
args = append(args, "delete", "--name=test")
app.Run(args)
}
12 changes: 8 additions & 4 deletions cmd/forget.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package cmd

import (
"fmt"
"os"
"os/user"

"github.com/fatih/color"
"github.com/tonedefdev/terracreds/pkg/errors"
"github.com/tonedefdev/terracreds/pkg/helpers"
"github.com/urfave/cli/v2"
)
Expand All @@ -26,8 +25,13 @@ func (cmd *Config) NewCommandForget() *cli.Command {
// newCommandActionForget deletes the requested secret in the vault when called by 'terraform logout'
func (cmd *Config) newCommandActionForget(c *cli.Context) error {
if len(os.Args) == 2 {
fmt.Fprintf(color.Output, "%s: No secret name or secret was specified. Use 'terracreds create -h' to print help info\n", color.RedString("ERROR"))
return nil
err := &errors.CustomError{
Message: "No secret name or secret was specified. Use 'terracreds forget -h' to print help info",
Level: "ERROR",
}

helpers.Logging(cmd.Cfg, err.Message, err.Level)
return err
}

terraVault := cmd.NewTerraVault(os.Args[2])
Expand Down
13 changes: 3 additions & 10 deletions cmd/forget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,19 @@ import (
"github.com/urfave/cli/v2"
)

func TestNewCommandActionCreateTemp(t *testing.T) {
func TestNewCommandActionForget(t *testing.T) {
terracreds := config()
app := app()
app.Commands = []*cli.Command{
terracreds.NewCommandCreate(),
terracreds.NewCommandForget(),
}

args := os.Args[0:1]
args = append(args, "create", "--name=test", "--secret=password")
app.Run(args)
}

func TestNewCommandActionForget(t *testing.T) {
terracreds := config()
app := app()
app.Commands = []*cli.Command{
terracreds.NewCommandForget(),
}

args := os.Args[0:1]
args = os.Args[0:1]
args = append(args, "forget", "test")
app.Run(args)
}
13 changes: 8 additions & 5 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"os/user"

"github.com/fatih/color"
"github.com/tonedefdev/terracreds/pkg/errors"
"github.com/tonedefdev/terracreds/pkg/helpers"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -42,8 +42,11 @@ func (cmd *Config) newCommandActionGet() error {
return err
}

msg := "A secret name was expected after the 'get' command but no argument was provided"
helpers.Logging(cmd.Cfg, msg, "ERROR")
fmt.Fprintf(color.Output, "%s: %s\n", color.RedString("ERROR"), msg)
return nil
err := &errors.CustomError{
Message: "A secret name was expected after the 'get' command but no argument was provided",
Level: "ERROR",
}

helpers.Logging(cmd.Cfg, err.Message, err.Level)
return err
}
21 changes: 15 additions & 6 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os/user"
"strings"

"github.com/fatih/color"
"github.com/tonedefdev/terracreds/pkg/errors"
"github.com/tonedefdev/terracreds/pkg/helpers"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -63,8 +63,13 @@ func (cmd *Config) NewCommandList() *cli.Command {
// newCommandActionList returns the secret names from the vault either as a string, TF_VARs, or JSON
func (cmd *Config) newCommandActionList(c *cli.Context) error {
if len(os.Args) == 2 {
fmt.Fprintf(color.Output, "%s: No list command was specified. Use 'terracreds list -h' to print help info\n", color.RedString("ERROR"))
return nil
err := &errors.CustomError{
Message: "No list command was specified. Use 'terracreds list -h' to print help info",
Level: "ERROR",
}

helpers.Logging(cmd.Cfg, err.Message, err.Level)
return err
}

if len(os.Args) > 1 {
Expand All @@ -79,9 +84,13 @@ func (cmd *Config) newCommandActionList(c *cli.Context) error {
}

if len(cmd.Cfg.Secrets) < 1 && c.String("secret-names") == "" {
verbiage := "A list of secrets must be provided. Use '--secret-names' and pass it a comma separated list of secrets, or setup the 'secrets' block in the terracreds config file to use this command\n"
fmt.Fprintf(color.Output, "%s: %s", color.RedString("ERROR"), verbiage)
return nil
err := &errors.CustomError{
Message: "A list of secrets must be provided. Use '--secret-names' and pass it a comma separated list of secrets, or setup the 'secrets' block in the terracreds config file to use this command",
Level: "ERROR",
}

helpers.Logging(cmd.Cfg, err.Message, err.Level)
return err
}

user, err := user.Current()
Expand Down
12 changes: 8 additions & 4 deletions cmd/store.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package cmd

import (
"fmt"
"os"
"os/user"

"github.com/fatih/color"
"github.com/tonedefdev/terracreds/pkg/errors"
"github.com/tonedefdev/terracreds/pkg/helpers"
"github.com/urfave/cli/v2"
)
Expand All @@ -27,8 +26,13 @@ func (cmd *Config) NewCommandStore() *cli.Command {
// newCommandActionStore creates the secret in the vault when 'terraform login' is called
func (cmd *Config) newCommandActionStore(c *cli.Context) error {
if len(os.Args) == 2 {
fmt.Fprintf(color.Output, "%s: No hostname was specified. Use 'terracreds store -h' to print help info\n", color.RedString("ERROR"))
return nil
err := &errors.CustomError{
Message: "No hostname was specified. Use 'terracreds store -h' to print help info",
Level: "ERROR",
}

helpers.Logging(cmd.Cfg, err.Message, err.Level)
return err
}

terraVault := cmd.NewTerraVault(os.Args[2])
Expand Down
21 changes: 12 additions & 9 deletions cmd/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ import (
"bytes"
"os"
"os/exec"
"runtime"
"testing"
)

func TestNewCommandActionStore(t *testing.T) {
store := exec.Command("terracreds", "store", "test")
if runtime.GOOS != "linux" {
store := exec.Command("terracreds", "store", "test")

buffer := bytes.Buffer{}
buffer.Write([]byte("{\"token\":\"test\"}"))
store.Stdin = &buffer
buffer := bytes.Buffer{}
buffer.Write([]byte("{\"token\":\"test\"}"))
store.Stdin = &buffer

store.Stdout = os.Stdout
store.Stderr = os.Stderr
store.Stdout = os.Stdout
store.Stderr = os.Stderr

err := store.Run()
if err != nil {
t.Fatal(err)
err := store.Run()
if err != nil {
t.Fatal(err)
}
}
}
Loading

0 comments on commit c099e89

Please sign in to comment.