feat: --demo starts with a few starred and recently used secrets
This commit is contained in:
2 files changed
+52
-2
No files matched your search
@@ -318,9 +318,11 @@ Flags:
|
||||
var providers []provider.Provider
|
||||
if *demo {
|
||||
// Two Azure accounts, like a personal and an admin login in az.
|
||||
alice, admin := "Azure:alice@example.com/demo", "Azure:admin.alice@example.com/demo"
|
||||
fake.Seed(st, alice, admin)
|
||||
providers = []provider.Provider{
|
||||
fake.Azure(400*time.Millisecond).As("Azure:alice@example.com/demo", "Azure · alice"),
|
||||
fake.AzureOps(700*time.Millisecond).As("Azure:admin.alice@example.com/demo", "Azure · admin.alice"),
|
||||
fake.Azure(400*time.Millisecond).As(alice, "Azure · alice"),
|
||||
fake.AzureOps(700*time.Millisecond).As(admin, "Azure · admin.alice"),
|
||||
fake.Databricks(600 * time.Millisecond),
|
||||
fake.Repos(),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package fake
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.kebcloud.no/keb/lazysecrets/internal/store"
|
||||
)
|
||||
|
||||
// Seed stars and uses a few of the demo's secrets, so --demo shows
|
||||
// Favourites (F), Recent (R) and stars in lazysecrets list. alice and
|
||||
// admin are the two Azure accounts' provider IDs.
|
||||
func Seed(st *store.Store, alice, admin string) {
|
||||
type item struct {
|
||||
link, account, source string
|
||||
path []string
|
||||
star bool
|
||||
uses int
|
||||
ago time.Duration
|
||||
}
|
||||
const azure, dbx = "lazysecrets://azure/", "lazysecrets://databricks/adb-1111111111111111.11.azuredatabricks.net/"
|
||||
for _, it := range []item{
|
||||
{link: azure + "kv-app-prod.vault.azure.net/secrets/db-password", account: alice, source: "sub-prod",
|
||||
path: []string{"platform-prod", "kv-app-prod"}, star: true, uses: 12, ago: 20 * time.Minute},
|
||||
{link: azure + "kv-app-prod.vault.azure.net/secrets/api-key", account: alice, source: "sub-prod",
|
||||
path: []string{"platform-prod", "kv-app-prod"}, uses: 4, ago: 2 * time.Hour},
|
||||
{link: azure + "kv-breakglass.vault.azure.net/secrets/emergency-admin", account: admin, source: "sub-prod",
|
||||
path: []string{"platform-prod", "kv-breakglass"}, star: true},
|
||||
{link: azure + "kv-shared-prod.vault.azure.net/secrets/smtp-password", account: alice, source: "sub-prod",
|
||||
path: []string{"platform-prod", "kv-shared-prod"}, uses: 2, ago: 26 * time.Hour},
|
||||
{link: dbx + "app/storage-key", account: "Databricks", source: "dbx-prod",
|
||||
path: []string{"prod", "app"}, star: true, uses: 3, ago: 5 * time.Hour},
|
||||
} {
|
||||
context := func(n *store.Node) {
|
||||
n.Name = it.link[strings.LastIndex(it.link, "/")+1:]
|
||||
n.Path, n.Source, n.Account = it.path, it.source, it.account
|
||||
}
|
||||
if it.star {
|
||||
_ = st.Update(it.link, func(n *store.Node) {
|
||||
context(n)
|
||||
n.ToggleStar(it.account)
|
||||
})
|
||||
}
|
||||
for range it.uses {
|
||||
_ = st.Use(it.link, time.Now().Add(-it.ago), context)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user