Skip to content

Commit e995bd9

Browse files
authored
Merge pull request #60 from jobtalk/session
MFAの対応
2 parents a9a797e + 47532dd commit e995bd9

File tree

15 files changed

+278
-415
lines changed

15 files changed

+278
-415
lines changed

circle.yml renamed to .circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jobs:
33
build:
44
working_directory: /go/src/github.com/jobtalk/pnzr
55
docker:
6-
- image: golang:1.8.3
6+
- image: golang:1.9
77
environment:
88
GO15VENDOREXPERIMENT: 1
99
steps:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ tags
6262
vendor/
6363
dev/
6464

65+
.idea/
66+
.pnzr

api/deploy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package api
22

33
import (
4-
"github.com/aws/aws-sdk-go/aws"
4+
"github.com/aws/aws-sdk-go/aws/session"
55
"github.com/jobtalk/pnzr/lib"
66
"github.com/jobtalk/pnzr/lib/iface"
77
"github.com/jobtalk/pnzr/lib/setting"
@@ -33,6 +33,6 @@ func (d *DeployDeps) Deploy(s *setting.Setting) (interface{}, error) {
3333
return result, nil
3434
}
3535

36-
func Deploy(awsConfig *aws.Config, s *setting.Setting) (interface{}, error) {
37-
return (&DeployDeps{ecs: lib.NewECS(awsConfig)}).Deploy(s)
36+
func Deploy(sess *session.Session, s *setting.Setting) (interface{}, error) {
37+
return (&DeployDeps{ecs: lib.NewECS(sess)}).Deploy(s)
3838
}

glide.lock

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package: github.com/jobtalk/pnzr
22
import:
33
- package: github.com/aws/aws-sdk-go
4-
version: ^1.8.12
4+
version: ^1.10.27
55
subpackages:
66
- aws
7-
- aws/credentials
7+
- aws/credentials/stscreds
88
- aws/session
99
- service/ecs
10+
- service/ecs/ecsiface
1011
- service/elbv2
1112
- service/kms
12-
- package: github.com/mitchellh/cli
13+
- package: github.com/ieee0824/getenv
14+
version: ^0.1.0
1315
- package: github.com/joho/godotenv
14-
version: ^1.1
16+
version: ^1.1.0
17+
- package: github.com/mitchellh/cli

lib/ecs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ type ECS struct {
1818
svc ecsiface.ECSAPI
1919
}
2020

21-
func NewECS(awsConfig *aws.Config) *ECS {
21+
func NewECS(sess *session.Session) *ECS {
2222
return &ECS{
23-
svc: ecs.New(session.New(), awsConfig),
23+
svc: ecs.New(sess),
2424
}
2525
}
2626

lib/getenv/getenv.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

lib/getenv/getenv_test.go

Lines changed: 0 additions & 112 deletions
This file was deleted.

lib/kms_vault.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,39 @@ import (
66
"github.com/aws/aws-sdk-go/aws"
77
"github.com/aws/aws-sdk-go/aws/session"
88
"github.com/aws/aws-sdk-go/service/kms"
9+
"github.com/aws/aws-sdk-go/service/kms/kmsiface"
910
)
1011

1112
type KMS struct {
12-
keyID *string
13-
awsConfig *aws.Config
14-
Type *string `json:"type"`
15-
Cipher []byte `json:"cipher"`
13+
keyID *string
14+
svc kmsiface.KMSAPI
15+
Type *string `json:"type"`
16+
Cipher []byte `json:"cipher"`
1617
}
1718

18-
func NewKMS() *KMS {
19+
func NewKMS(sess *session.Session) *KMS {
1920
return &KMS{
20-
awsConfig: &aws.Config{},
21-
Type: aws.String("kms"),
21+
svc: kms.New(sess),
22+
Type: aws.String("kms"),
2223
}
2324
}
2425

25-
func NewKMSFromBinary(bin []byte) *KMS {
26+
func NewKMSFromBinary(bin []byte, sess *session.Session) *KMS {
2627
var ret = KMS{}
2728
err := json.Unmarshal(bin, &ret)
2829
if err != nil {
2930
return nil
3031
}
31-
ret.awsConfig = &aws.Config{}
32+
ret.svc = kms.New(sess)
3233
return &ret
3334
}
3435

3536
func (k *KMS) Encrypt(plainText []byte) ([]byte, error) {
36-
svc := kms.New(session.New(), k.awsConfig)
3737
params := &kms.EncryptInput{
3838
KeyId: k.keyID,
3939
Plaintext: plainText,
4040
}
41-
resp, err := svc.Encrypt(params)
41+
resp, err := k.svc.Encrypt(params)
4242
if err != nil {
4343
return nil, err
4444
}
@@ -48,11 +48,10 @@ func (k *KMS) Encrypt(plainText []byte) ([]byte, error) {
4848
}
4949

5050
func (k *KMS) Decrypt() ([]byte, error) {
51-
svc := kms.New(session.New(), k.awsConfig)
5251
params := &kms.DecryptInput{
5352
CiphertextBlob: k.Cipher,
5453
}
55-
resp, err := svc.Decrypt(params)
54+
resp, err := k.svc.Decrypt(params)
5655
if err != nil {
5756
return nil, err
5857
}
@@ -64,16 +63,6 @@ func (k *KMS) SetKeyID(keyID string) *KMS {
6463
return k
6564
}
6665

67-
func (k *KMS) SetRegion(region string) *KMS {
68-
k.awsConfig.Region = &region
69-
return k
70-
}
71-
72-
func (k *KMS) SetAWSConfig(awsConfig *aws.Config) *KMS {
73-
k.awsConfig = awsConfig
74-
return k
75-
}
76-
7766
func (k *KMS) String() string {
7867
bin, err := json.Marshal(k)
7968
if err != nil {

main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/jobtalk/pnzr/subcmd/vault_edit"
1313
"github.com/jobtalk/pnzr/subcmd/vault_view"
1414
"github.com/jobtalk/pnzr/vars"
15+
"github.com/joho/godotenv"
1516
"github.com/mitchellh/cli"
1617
)
1718

@@ -39,27 +40,28 @@ func init() {
3940

4041
VERSION = generateBuildInfo()
4142
log.SetFlags(log.Llongfile)
42-
43+
godotenv.Load("~/.pnzr")
44+
godotenv.Load(".pnzr")
4345
}
4446

4547
func main() {
4648
c := cli.NewCLI("pnzr", VERSION)
4749
c.Args = os.Args[1:]
4850
c.Commands = map[string]cli.CommandFactory{
4951
"deploy": func() (cli.Command, error) {
50-
return &deploy.Deploy{}, nil
52+
return &deploy.DeployCommand{}, nil
5153
},
5254
"vault": func() (cli.Command, error) {
53-
return &vault.Vault{}, nil
55+
return &vault.VaultCommand{}, nil
5456
},
5557
"update": func() (cli.Command, error) {
56-
return &update.Update{}, nil
58+
return &update.UpdateCommand{}, nil
5759
},
5860
"vault-edit": func() (cli.Command, error) {
59-
return &vedit.VaultEdit{}, nil
61+
return &vedit.VaultEditCommand{}, nil
6062
},
6163
"vault-view": func() (cli.Command, error) {
62-
return &vview.VaultView{}, nil
64+
return &vview.VaultViewCommand{}, nil
6365
},
6466
}
6567
exitCode, err := c.Run()

0 commit comments

Comments
 (0)