Sfoglia il codice sorgente

feat: switch to zalando/go-keyring from 99designs/keyring

rigormorrtiss 4 anni fa
parent
commit
d8c502440b
4 ha cambiato i file con 16 aggiunte e 25 eliminazioni
  1. 3 7
      discordo.go
  2. 1 1
      go.mod
  3. 6 0
      go.sum
  4. 6 17
      util/keyring.go

+ 3 - 7
discordo.go

@@ -5,7 +5,6 @@ import (
 	"sort"
 	"strings"
 
-	"github.com/99designs/keyring"
 	"github.com/atotto/clipboard"
 	"github.com/diamondburned/arikawa/v3/api"
 	"github.com/diamondburned/arikawa/v3/discord"
@@ -25,7 +24,6 @@ var (
 	messageInputField *tview.InputField
 	mainFlex          *tview.Flex
 
-	kr             keyring.Keyring
 	conf           *util.Config
 	discordSession *session.Session
 	clientID       discord.UserID
@@ -47,9 +45,7 @@ func main() {
 	tview.Borders.BottomLeft = ' '
 	tview.Borders.BottomRight = ' '
 
-	kr = util.OpenKeyringBackend()
 	conf = util.NewConfig()
-
 	app = ui.NewApp(onAppInputCapture)
 	guildsTreeView = ui.NewGuildsTreeView(onGuildsTreeViewSelected, conf.Theme)
 	messagesTextView = ui.NewMessagesTextView(app, conf.Theme)
@@ -57,7 +53,7 @@ func main() {
 	mainFlex = ui.NewMainFlex(guildsTreeView, messagesTextView, messageInputField)
 
 	token := os.Getenv("DISCORDO_TOKEN")
-	if t := util.GetItem(kr, "token"); t != "" {
+	if t := util.GetPassword("token"); t != "" {
 		token = t
 	}
 
@@ -274,7 +270,7 @@ func onLoginFormLoginButtonSelected() {
 			SetFocus(guildsTreeView)
 
 		discordSession = newSession(l.Token)
-		go util.SetItem(kr, "token", l.Token)
+		go util.SetPassword("token", l.Token)
 	} else if l.MFA {
 		loginForm = ui.NewMfaLoginForm(func() {
 			code := loginForm.GetFormItem(0).(*tview.InputField).GetText()
@@ -292,7 +288,7 @@ func onLoginFormLoginButtonSelected() {
 				SetFocus(guildsTreeView)
 
 			discordSession = newSession(l.Token)
-			go util.SetItem(kr, "token", l.Token)
+			go util.SetPassword("token", l.Token)
 		})
 
 		app.SetRoot(loginForm, true)

+ 1 - 1
go.mod

@@ -3,9 +3,9 @@ module github.com/rigormorrtiss/discordo
 go 1.16
 
 require (
-	github.com/99designs/keyring v1.1.6
 	github.com/atotto/clipboard v0.1.4
 	github.com/diamondburned/arikawa/v3 v3.0.0-20210817064836-eece98903ab1
 	github.com/gdamore/tcell/v2 v2.4.0
 	github.com/rivo/tview v0.0.0-20210624165335-29d673af0ce2
+	github.com/zalando/go-keyring v0.1.1 // indirect
 )

+ 6 - 0
go.sum

@@ -5,6 +5,8 @@ github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn
 github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
 github.com/danieljoos/wincred v1.0.2 h1:zf4bhty2iLuwgjgpraD2E9UbvO+fe54XXGJbOwe23fU=
 github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U=
+github.com/danieljoos/wincred v1.1.0 h1:3RNcEpBg4IhIChZdFRSdlQt1QjCp1sMAPIrOnm7Yf8g=
+github.com/danieljoos/wincred v1.1.0/go.mod h1:XYlo+eRTsVA9aHGp7NGjFkPla4m+DCL7hqDjlFjiygg=
 github.com/danieljoos/wincred v1.1.1 h1:FgOybUqUGGwgBz+ga92qD4f/ZPvuPryRjashrk/p9IA=
 github.com/danieljoos/wincred v1.1.1/go.mod h1:gSBQmTx6G0VmLowygiA7ZD0p0E09HJ68vta8z/RT2d0=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -29,6 +31,8 @@ github.com/gdamore/tcell/v2 v2.4.0 h1:W6dxJEmaxYvhICFoTY3WrLLEXsQ11SaFnKGVEXW57K
 github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
 github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0=
 github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
+github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
+github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
 github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
 github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
@@ -76,6 +80,8 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/zalando/go-keyring v0.1.1 h1:w2V9lcx/Uj4l+dzAf1m9s+DJ1O8ROkEHnynonHjTcYE=
+github.com/zalando/go-keyring v0.1.1/go.mod h1:OIC+OZ28XbmwFxU/Rp9V7eKzZjamBJwRzC8UFJH9+L8=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

+ 6 - 17
util/keyring.go

@@ -1,29 +1,18 @@
 package util
 
-import (
-	"github.com/99designs/keyring"
-)
+import "github.com/zalando/go-keyring"
 
-func OpenKeyringBackend() (kr keyring.Keyring) {
-	kr, err := keyring.Open(keyring.Config{})
-	if err != nil {
-		panic(err)
-	}
-
-	return
-}
-
-func GetItem(kr keyring.Keyring, k string) string {
-	i, err := kr.Get(k)
+func GetPassword(u string) string {
+	p, err := keyring.Get("discordo", u)
 	if err != nil {
 		return ""
 	}
 
-	return string(i.Data)
+	return p
 }
 
-func SetItem(kr keyring.Keyring, k string, d string) {
-	if err := kr.Set(keyring.Item{Key: k, Data: []byte(d)}); err != nil {
+func SetPassword(u string, p string) {
+	if err := keyring.Set("discordo", u, p); err != nil {
 		panic(err)
 	}
 }