Private
Public Access
1
0
Files
u-desk/cmd/dbread/main.go

54 lines
1.3 KiB
Go

package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"github.com/glebarez/sqlite"
"gorm.io/gorm"
)
func main() {
home, _ := os.UserHomeDir()
dbPath := filepath.Join(home, ".u-desk", "app.db")
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
if err != nil {
fmt.Fprintln(os.Stderr, "open db:", err)
os.Exit(1)
}
// 所有列
type Profile struct {
ID uint `gorm:"primaryKey"`
Name string `gorm:"column:name"`
Type string `gorm:"column:type"`
Host string `gorm:"column:host"`
Port int `gorm:"column:port"`
Username string `gorm:"column:username"`
Provider string `gorm:"column:provider"`
Token string `gorm:"column:token"`
AccessKey string `gorm:"column:access_key"`
SecretKey string `gorm:"column:secret_key"`
Bucket string `gorm:"column:bucket"`
Region string `gorm:"column:region"`
Endpoint string `gorm:"column:endpoint"`
}
var profiles []Profile
db.Table("connection_profiles").Find(&profiles)
// 脱敏 secret_key
for i := range profiles {
if len(profiles[i].SecretKey) > 8 {
profiles[i].SecretKey = profiles[i].SecretKey[:4] + "****"
}
}
b, _ := json.MarshalIndent(profiles, "", " ")
fmt.Println("=== Connection Profiles ===")
fmt.Println(string(b))
}