Merge pull request #12 from KristianJBorgwarth/feat/current-vault-config-store

feat: vault_store and config
This commit is contained in:
Kristian 2026-04-06 11:59:59 +02:00 committed by GitHub
commit 614bf67972
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 61 additions and 2 deletions

View file

@ -3,11 +3,14 @@ package handlers
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence" "github.com/KristianJBorgwarth/dendrite.daemon/persistence"
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/store"
) )
type initializeCommand struct { type initializeCommand struct {
VaultPath string `json:"vaultPath"` VaultPath string `json:"vaultPath"`
TemplateDirectory string `json:"templateDirectory"`
} }
type InitializeHandler struct{} type InitializeHandler struct{}
@ -23,7 +26,9 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
return nil, err return nil, err
} }
err := persistence.InitializeDBContext(cmd.VaultPath) store := store.NewVaultStore(cmd.VaultPath, cmd.TemplateDirectory)
err := persistence.InitializeDBContext(store.Config.VaultPath())
if err != nil { if err != nil {
return nil, err return nil, err
} }

BIN
dendrite

Binary file not shown.

View file

@ -0,0 +1,2 @@
// Package persistenceconfig provides configuration for persistence layer
package persistenceconfig

View file

@ -0,0 +1,24 @@
package persistenceconfig
import "path"
type VaultConfiguration struct {
path string
templateDirectory string
}
func NewVaultConfiguration(vaultPath, templateDirectory string) *VaultConfiguration {
return &VaultConfiguration{path: vaultPath, templateDirectory: templateDirectory}
}
func (vc *VaultConfiguration) VaultPath() string {
return vc.path
}
func (vc *VaultConfiguration) fileTypeCheck(templateName string) string {
fileType := path.Ext(templateName)
if fileType != ".md" {
return templateName + ".md"
}
return templateName
}

View file

@ -0,0 +1,28 @@
package store
import persistenceconfig "github.com/KristianJBorgwarth/dendrite.daemon/persistence/config"
type VaultStore struct {
Config *persistenceconfig.VaultConfiguration
}
var vaultStore *VaultStore
func NewVaultStore(vault, templateDir string) *VaultStore {
if vaultStore != nil {
return vaultStore
}
vaultStore = &VaultStore{Config: persistenceconfig.NewVaultConfiguration(vault, templateDir)}
return vaultStore
}
func GetVaultStore() *VaultStore {
if vaultStore == nil {
panic("VaultStore not initialized. Call NewVaultStore first.")
}
return vaultStore
}
func (vs *VaultStore) SetConfig(config persistenceconfig.VaultConfiguration) {
vs.Config = &config
}