Skip to content

Commit

Permalink
Merge pull request #60 from jobtalk/session
Browse files Browse the repository at this point in the history
MFAの対応
  • Loading branch information
ieee0824 authored Aug 30, 2017
2 parents a9a797e + 47532dd commit e995bd9
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 415 deletions.
2 changes: 1 addition & 1 deletion circle.yml → .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: /go/src/github.com/jobtalk/pnzr
docker:
- image: golang:1.8.3
- image: golang:1.9
environment:
GO15VENDOREXPERIMENT: 1
steps:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ tags
vendor/
dev/

.idea/
.pnzr
6 changes: 3 additions & 3 deletions api/deploy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package api

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/jobtalk/pnzr/lib"
"github.com/jobtalk/pnzr/lib/iface"
"github.com/jobtalk/pnzr/lib/setting"
Expand Down Expand Up @@ -33,6 +33,6 @@ func (d *DeployDeps) Deploy(s *setting.Setting) (interface{}, error) {
return result, nil
}

func Deploy(awsConfig *aws.Config, s *setting.Setting) (interface{}, error) {
return (&DeployDeps{ecs: lib.NewECS(awsConfig)}).Deploy(s)
func Deploy(sess *session.Session, s *setting.Setting) (interface{}, error) {
return (&DeployDeps{ecs: lib.NewECS(sess)}).Deploy(s)
}
9 changes: 6 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package: github.com/jobtalk/pnzr
import:
- package: github.com/aws/aws-sdk-go
version: ^1.8.12
version: ^1.10.27
subpackages:
- aws
- aws/credentials
- aws/credentials/stscreds
- aws/session
- service/ecs
- service/ecs/ecsiface
- service/elbv2
- service/kms
- package: github.com/mitchellh/cli
- package: github.com/ieee0824/getenv
version: ^0.1.0
- package: github.com/joho/godotenv
version: ^1.1
version: ^1.1.0
- package: github.com/mitchellh/cli
4 changes: 2 additions & 2 deletions lib/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type ECS struct {
svc ecsiface.ECSAPI
}

func NewECS(awsConfig *aws.Config) *ECS {
func NewECS(sess *session.Session) *ECS {
return &ECS{
svc: ecs.New(session.New(), awsConfig),
svc: ecs.New(sess),
}
}

Expand Down
52 changes: 0 additions & 52 deletions lib/getenv/getenv.go

This file was deleted.

112 changes: 0 additions & 112 deletions lib/getenv/getenv_test.go

This file was deleted.

35 changes: 12 additions & 23 deletions lib/kms_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,39 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/kms"
"github.com/aws/aws-sdk-go/service/kms/kmsiface"
)

type KMS struct {
keyID *string
awsConfig *aws.Config
Type *string `json:"type"`
Cipher []byte `json:"cipher"`
keyID *string
svc kmsiface.KMSAPI
Type *string `json:"type"`
Cipher []byte `json:"cipher"`
}

func NewKMS() *KMS {
func NewKMS(sess *session.Session) *KMS {
return &KMS{
awsConfig: &aws.Config{},
Type: aws.String("kms"),
svc: kms.New(sess),
Type: aws.String("kms"),
}
}

func NewKMSFromBinary(bin []byte) *KMS {
func NewKMSFromBinary(bin []byte, sess *session.Session) *KMS {
var ret = KMS{}
err := json.Unmarshal(bin, &ret)
if err != nil {
return nil
}
ret.awsConfig = &aws.Config{}
ret.svc = kms.New(sess)
return &ret
}

func (k *KMS) Encrypt(plainText []byte) ([]byte, error) {
svc := kms.New(session.New(), k.awsConfig)
params := &kms.EncryptInput{
KeyId: k.keyID,
Plaintext: plainText,
}
resp, err := svc.Encrypt(params)
resp, err := k.svc.Encrypt(params)
if err != nil {
return nil, err
}
Expand All @@ -48,11 +48,10 @@ func (k *KMS) Encrypt(plainText []byte) ([]byte, error) {
}

func (k *KMS) Decrypt() ([]byte, error) {
svc := kms.New(session.New(), k.awsConfig)
params := &kms.DecryptInput{
CiphertextBlob: k.Cipher,
}
resp, err := svc.Decrypt(params)
resp, err := k.svc.Decrypt(params)
if err != nil {
return nil, err
}
Expand All @@ -64,16 +63,6 @@ func (k *KMS) SetKeyID(keyID string) *KMS {
return k
}

func (k *KMS) SetRegion(region string) *KMS {
k.awsConfig.Region = &region
return k
}

func (k *KMS) SetAWSConfig(awsConfig *aws.Config) *KMS {
k.awsConfig = awsConfig
return k
}

func (k *KMS) String() string {
bin, err := json.Marshal(k)
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/jobtalk/pnzr/subcmd/vault_edit"
"github.com/jobtalk/pnzr/subcmd/vault_view"
"github.com/jobtalk/pnzr/vars"
"github.com/joho/godotenv"
"github.com/mitchellh/cli"
)

Expand Down Expand Up @@ -39,27 +40,28 @@ func init() {

VERSION = generateBuildInfo()
log.SetFlags(log.Llongfile)

godotenv.Load("~/.pnzr")
godotenv.Load(".pnzr")
}

func main() {
c := cli.NewCLI("pnzr", VERSION)
c.Args = os.Args[1:]
c.Commands = map[string]cli.CommandFactory{
"deploy": func() (cli.Command, error) {
return &deploy.Deploy{}, nil
return &deploy.DeployCommand{}, nil
},
"vault": func() (cli.Command, error) {
return &vault.Vault{}, nil
return &vault.VaultCommand{}, nil
},
"update": func() (cli.Command, error) {
return &update.Update{}, nil
return &update.UpdateCommand{}, nil
},
"vault-edit": func() (cli.Command, error) {
return &vedit.VaultEdit{}, nil
return &vedit.VaultEditCommand{}, nil
},
"vault-view": func() (cli.Command, error) {
return &vview.VaultView{}, nil
return &vview.VaultViewCommand{}, nil
},
}
exitCode, err := c.Run()
Expand Down
Loading

0 comments on commit e995bd9

Please sign in to comment.