Skip to content

Commit 1f2ae8f

Browse files
authored
Merge pull request #20 from udon-or-ramen/feat/use-keyring
feat: 平文で保存せずキーチェーンにBase64で保存するように変更
2 parents ebaf9cf + ace8809 commit 1f2ae8f

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ require (
66
github.com/mitchellh/go-homedir v1.1.0
77
github.com/rakyll/goini v0.0.0-20140112234134-907cca0f578a
88
github.com/toqueteos/webbrowser v1.2.0
9+
github.com/zalando/go-keyring v0.2.6
910
gopkg.in/alecthomas/kingpin.v2 v2.2.6
1011
)
1112

1213
require (
14+
al.essio.dev/pkg/shellescape v1.5.1 // indirect
1315
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
1416
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
15-
github.com/davecgh/go-spew v1.1.1 // indirect
16-
github.com/stretchr/testify v1.7.0 // indirect
17+
github.com/danieljoos/wincred v1.2.2 // indirect
18+
github.com/godbus/dbus/v5 v5.1.0 // indirect
19+
golang.org/x/sys v0.26.0 // indirect
1720
)

go.sum

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1+
al.essio.dev/pkg/shellescape v1.5.1 h1:86HrALUujYS/h+GtqoB26SBEdkWfmMI6FubjXlsXyho=
2+
al.essio.dev/pkg/shellescape v1.5.1/go.mod h1:6sIqp7X2P6mThCQ7twERpZTuigpr6KbZWtls1U8I890=
13
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
24
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
35
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
46
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
7+
github.com/danieljoos/wincred v1.2.2 h1:774zMFJrqaeYCK2W57BgAem/MLi6mtSE47MB6BOJ0i0=
8+
github.com/danieljoos/wincred v1.2.2/go.mod h1:w7w4Utbrz8lqeMbDAK0lkNJUv5sAOkFi7nd/ogr0Uh8=
59
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
610
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11+
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
12+
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
13+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
814
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
915
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
1016
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1117
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1218
github.com/rakyll/goini v0.0.0-20140112234134-907cca0f578a h1:3JTBH+06LYYw3LjAsvp2mVXLDayQZxXmfm2zGlzOH1Y=
1319
github.com/rakyll/goini v0.0.0-20140112234134-907cca0f578a/go.mod h1:1pH5e1EQl4shdpnuDQPO1hEzmk/oXrZrnWENs1lZjCk=
1420
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
21+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
1522
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
16-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
17-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
23+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
1824
github.com/toqueteos/webbrowser v1.2.0 h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9rrstGQ=
1925
github.com/toqueteos/webbrowser v1.2.0/go.mod h1:XWoZq4cyp9WeUeak7w7LXRUQf1F1ATJMir8RTqb4ayM=
26+
github.com/zalando/go-keyring v0.2.6 h1:r7Yc3+H+Ux0+M72zacZoItR3UDxeWfKTcabvkI8ua9s=
27+
github.com/zalando/go-keyring v0.2.6/go.mod h1:2TCrxYrbUNYfNS/Kgy/LSrkSQzZ5UPVH85RwfczwvcI=
28+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
29+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
2030
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
2131
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
2232
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2333
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
24-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
25-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
34+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

tokens/tokenresponse.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@ package tokens
33
import (
44
"encoding/json"
55
"errors"
6-
"fmt"
7-
"io/ioutil"
86
"log"
9-
"os"
107
"strings"
118
"time"
129

13-
"github.com/classmethod/aurl/utils"
10+
"github.com/zalando/go-keyring"
1411
)
1512

16-
const TOKEN_STORAGE_DIR = "~/.aurl/token"
17-
const TOKEN_STORAGE_FORMAT = TOKEN_STORAGE_DIR + "/%s.json"
13+
const KEYRING_SERVICE_NAME = "aurl"
1814

1915
type TokenResponse struct {
2016
AccessToken string `json:"access_token"`
@@ -44,21 +40,16 @@ func New(tokenResponseString *string) (TokenResponse, error) {
4440
}
4541

4642
func LoadTokenResponseString(profileName string) (*string, error) {
47-
path := utils.ExpandPath(fmt.Sprintf(TOKEN_STORAGE_FORMAT, profileName))
48-
buf, err := ioutil.ReadFile(path)
49-
if err == nil {
50-
s := string(buf)
51-
return &s, nil
43+
secret, err := keyring.Get(KEYRING_SERVICE_NAME, profileName)
44+
if err != nil {
45+
return nil, err
5246
}
53-
return nil, err
47+
return &secret, nil
5448
}
5549

5650
func SaveTokenResponseString(profileName string, tokenResponseString *string) {
57-
os.Mkdir(utils.ExpandPath(TOKEN_STORAGE_DIR), os.FileMode(0755))
58-
path := utils.ExpandPath(fmt.Sprintf(TOKEN_STORAGE_FORMAT, profileName))
59-
content := []byte(*tokenResponseString)
60-
err := ioutil.WriteFile(path, content, os.FileMode(0600))
51+
err := keyring.Set(KEYRING_SERVICE_NAME, profileName, *tokenResponseString)
6152
if err != nil {
62-
log.Printf("Failed to save token response: %v", err.Error())
53+
log.Printf("Failed to save token response to keyring: %v", err.Error())
6354
}
6455
}

0 commit comments

Comments
 (0)