feat: share env files as encrypted links #54
No files matched your search
@@ -13,6 +13,10 @@
|
|||||||
// version (1) | uvarint length of the header | header (JSON) | age file
|
// version (1) | uvarint length of the header | header (JSON) | age file
|
||||||
//
|
//
|
||||||
// The age file holds the files as deflated JSON.
|
// The age file holds the files as deflated JSON.
|
||||||
|
//
|
||||||
|
// A change to the format gets the next version, and Read keeps reading
|
||||||
|
// every earlier one: links stay in chat and tickets for years. A
|
||||||
|
// version it doesn't know is from a newer lazysecrets.
|
||||||
package share
|
package share
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -36,6 +40,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// version is the format's, written first; see the package doc.
|
||||||
version = 1
|
version = 1
|
||||||
// MaxLink keeps a link short enough for chat and tickets (Teams takes
|
// MaxLink keeps a link short enough for chat and tickets (Teams takes
|
||||||
// about 28 KB) and for passing it to a terminal window.
|
// about 28 KB) and for passing it to a terminal window.
|
||||||
|
|||||||
@@ -137,13 +137,13 @@ func (m *Model) confirmShare(s sharing) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// pickShareKey asks which secret to encrypt with, in Go to.
|
// pickShareKey asks which secret to encrypt with, in Go to, then shares
|
||||||
|
// with it.
|
||||||
func (m *Model) pickShareKey(s sharing) tea.Cmd {
|
func (m *Model) pickShareKey(s sharing) tea.Cmd {
|
||||||
cmd := m.openGoTo(tabSearch, true)
|
cmd := m.openGoTo(tabSearch, true)
|
||||||
m.search.pick = func(m *Model, key ref.Ref) tea.Cmd {
|
m.search.pick = func(m *Model, key ref.Ref) tea.Cmd {
|
||||||
s.key = key
|
s.key = key
|
||||||
m.confirmShare(s)
|
return m.seal(s) // the picker showed what's shared
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
m.search.pickTitle = shareTitle(s)
|
m.search.pickTitle = shareTitle(s)
|
||||||
m.search.pickLines = append(m.sharedFiles(s), "",
|
m.search.pickLines = append(m.sharedFiles(s), "",
|
||||||
|
|||||||
@@ -79,10 +79,7 @@ func shareFrom(t *testing.T, root string, paste bool) string {
|
|||||||
}
|
}
|
||||||
d.keys("enter")
|
d.keys("enter")
|
||||||
}
|
}
|
||||||
if !strings.Contains(d.screen(), ".env") || !strings.Contains(d.screen(), "db-password") {
|
// Picking it shares: the picker said what.
|
||||||
t.Errorf("the files and key aren't shown before sharing:\n%s", d.screen())
|
|
||||||
}
|
|
||||||
d.keys("c")
|
|
||||||
if !strings.HasPrefix(clip.content, "lazysecrets://share/") {
|
if !strings.HasPrefix(clip.content, "lazysecrets://share/") {
|
||||||
t.Fatalf("copied %q (%s)", clip.content, d.m.flash.text)
|
t.Fatalf("copied %q (%s)", clip.content, d.m.flash.text)
|
||||||
}
|
}
|
||||||
@@ -129,6 +126,28 @@ func TestShareFilesRoundTrip(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestShareWithShareKeyConfirms(t *testing.T) {
|
||||||
|
if _, err := exec.LookPath("git"); err != nil {
|
||||||
|
t.Skip("no git")
|
||||||
|
}
|
||||||
|
root := cloneWith(t, map[string]string{
|
||||||
|
".env": "A=1\n",
|
||||||
|
".lazysecrets.yaml": "share:\n key: https://" + kv + "/secrets/db-password\n",
|
||||||
|
})
|
||||||
|
clip := &fakeClipboard{}
|
||||||
|
d := newDriverOpts(t, Options{Clipboard: clip, ShareRules: demoRules}, fake.Azure(0), repo.New(repo.Settings{Dir: root}))
|
||||||
|
d.wait = scryptWait
|
||||||
|
d.keys("S", "f")
|
||||||
|
// The key wasn't picked: it shows which, before sharing.
|
||||||
|
if d.m.search != nil || d.m.prompt == nil || d.m.prompt.title != "Share .env" || !strings.Contains(d.screen(), "db-password") {
|
||||||
|
t.Fatalf("no confirmation:\n%s", d.screen())
|
||||||
|
}
|
||||||
|
d.keys("c")
|
||||||
|
if !strings.HasPrefix(clip.content, "lazysecrets://share/") {
|
||||||
|
t.Errorf("copied %q (%s)", clip.content, d.m.flash.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestShareLinkElsewhereAsksWhere(t *testing.T) {
|
func TestShareLinkElsewhereAsksWhere(t *testing.T) {
|
||||||
if _, err := exec.LookPath("git"); err != nil {
|
if _, err := exec.LookPath("git"); err != nil {
|
||||||
t.Skip("no git")
|
t.Skip("no git")
|
||||||
|
|||||||
Reference in new issue
Block a user