Skip to content

Commit

Permalink
Refactor from team-env to team
Browse files Browse the repository at this point in the history
  • Loading branch information
andybar2 committed Nov 26, 2018
1 parent de10002 commit d9d19c3
Show file tree
Hide file tree
Showing 18 changed files with 358 additions and 356 deletions.
27 changes: 0 additions & 27 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.15.81"
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
# team-env
# team

Save your project environment variables in a remote store and easily share them with your team, instead of having to store them in your project repository.
Save your project configuration (environment variables, configuration files, etc) in a remote store and easily share it with your team, instead of having to store it inside your project repository.

This allows you to share the source code of your project without sharing secrets, API keys, etc.
This allows you to securely share the source code of your project without including secrets, API keys, service account files, etc.

Currently only the `ssm` remote store is supported, but the package can be easily extended for adding more stores in the future.
Currently only the `aws` remote store is supported, but the package can be easily extended for adding more stores in the future.

- `ssm`: Store variables in your AWS account, using the [SSM Parameters Store](https://docs.aws.amazon.com/es_es/systems-manager/latest/userguide/systems-manager-paramstore.html).
- `aws`: Stores project configuration in your AWS account. Environment variables are stored in the [SSM Parameters Store](https://docs.aws.amazon.com/es_es/systems-manager/latest/userguide/systems-manager-paramstore.html), and files are stored in [S3](https://docs.aws.amazon.com/s3/index.html#lang/es_es).

## Installation:

```bash
go get -u github.com/andybar2/team-env
go get -u github.com/andybar2/team
```

## Configuration:

Create the `team-env.json` file in your project folder, and set your configuration parameters there. Here is an example using the `ssm` store on AWS.
Create the `team.json` file in your project folder, and set your configuration parameters there.

```json
{
"store": "ssm",
"project": "example",
"store": "aws",
"aws_profile": "myaccount",
"aws_region": "us-east-2"
}
```

The value of `aws_profile` is a reference to your `~/.aws/credentials` file. The keys for the given profile will be used by `team-env` to connect to your AWS account:
The value of `aws_profile` is a reference to your `~/.aws/credentials` file. The keys for the given profile will be used by `team` to connect to your AWS account:

```
[myaccount]
aws_access_key_id = xxxxxxxx
aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxx
```

## Usage:
## Manage environment variables:

### Set variable:

```bash
team-env set --env=development --var=DEBUG --val=1
team env set -s "development" -n "STRIPE_API_KEY" -v "1234567890"
```

### Get variable:

```bash
team-env get --env=development --var=DEBUG
team env get -s "development" -n "STRIPE_API_KEY"
```

### Delete variable:

```bash
team-env del --env=development --var=DEBUG
team env del -s "development" -n "STRIPE_API_KEY"
```

### Print all variables for an environment:

```bash
team-env print --env=development
team env print -s "development"
```

### Configure your local environment with the values of the variables in the remote store:

```bash
export $(team-env print --env=development)
export $(team env print -s "development")
```
43 changes: 0 additions & 43 deletions cmd/del.go

This file was deleted.

43 changes: 43 additions & 0 deletions cmd/env/del.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package env

import (
"errors"

"github.com/andybar2/team/store"
"github.com/spf13/cobra"
)

var delParams struct {
Stage string
Name string
}

var delCmd = &cobra.Command{
Use: "del",
Short: "Delete an environment variable",
RunE: runDelCmd,
}

func init() {
delCmd.Flags().StringVarP(&delParams.Stage, "stage", "s", "", "Stage name")
delCmd.Flags().StringVarP(&delParams.Name, "name", "n", "", "Variable name")

EnvCmd.AddCommand(delCmd)
}

func runDelCmd(cmd *cobra.Command, args []string) error {
if delParams.Stage == "" {
return errors.New("invalid stage name")
}

if delParams.Name == "" {
return errors.New("invalid variable name")
}

s, err := store.New()
if err != nil {
return err
}

return s.EnvDel(delParams.Stage, delParams.Name)
}
11 changes: 11 additions & 0 deletions cmd/env/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package env

import (
"github.com/spf13/cobra"
)

// EnvCmd is the sub-command to manage environment veriables
var EnvCmd = &cobra.Command{
Use: "env [command]",
Short: "Manage environment variables",
}
51 changes: 51 additions & 0 deletions cmd/env/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package env

import (
"errors"
"fmt"

"github.com/andybar2/team/store"
"github.com/spf13/cobra"
)

var getParams struct {
Stage string
Name string
}

var getCmd = &cobra.Command{
Use: "get",
Short: "Get an environment variable",
RunE: runGetCmd,
}

func init() {
getCmd.Flags().StringVarP(&getParams.Stage, "stage", "s", "", "Stage name")
getCmd.Flags().StringVarP(&getParams.Name, "name", "n", "", "Variable name")

EnvCmd.AddCommand(getCmd)
}

func runGetCmd(cmd *cobra.Command, args []string) error {
if getParams.Stage == "" {
return errors.New("invalid stage name")
}

if getParams.Name == "" {
return errors.New("invalid variable name")
}

s, err := store.New()
if err != nil {
return err
}

value, err := s.EnvGet(getParams.Stage, getParams.Name)
if err != nil {
return err
}

fmt.Printf("%s=%s\n", getParams.Name, value)

return nil
}
37 changes: 37 additions & 0 deletions cmd/env/print.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package env

import (
"errors"

"github.com/andybar2/team/store"
"github.com/spf13/cobra"
)

var printParams struct {
Stage string
}

var printCmd = &cobra.Command{
Use: "print",
Short: "Print all the environment variables for a stage",
RunE: runPrintCmd,
}

func init() {
printCmd.Flags().StringVarP(&printParams.Stage, "stage", "s", "", "Stage name")

EnvCmd.AddCommand(printCmd)
}

func runPrintCmd(cmd *cobra.Command, args []string) error {
if printParams.Stage == "" {
return errors.New("invalid stage name")
}

s, err := store.New()
if err != nil {
return err
}

return s.EnvPrint(printParams.Stage)
}
45 changes: 45 additions & 0 deletions cmd/env/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package env

import (
"errors"

"github.com/andybar2/team/store"
"github.com/spf13/cobra"
)

var setParams struct {
Stage string
Name string
Value string
}

var setCmd = &cobra.Command{
Use: "set",
Short: "Set an environment variable",
RunE: runSetCmd,
}

func init() {
setCmd.Flags().StringVarP(&setParams.Stage, "stage", "s", "", "Stage name")
setCmd.Flags().StringVarP(&setParams.Name, "name", "n", "", "Variable name")
setCmd.Flags().StringVarP(&setParams.Value, "value", "v", "", "Variable value")

EnvCmd.AddCommand(setCmd)
}

func runSetCmd(cmd *cobra.Command, args []string) error {
if setParams.Stage == "" {
return errors.New("invalid stage name")
}

if setParams.Name == "" {
return errors.New("invalid variable name")
}

s, err := store.New()
if err != nil {
return err
}

return s.EnvSet(setParams.Stage, setParams.Name, setParams.Value)
}
Loading

0 comments on commit d9d19c3

Please sign in to comment.