Merge pull request #12 from KristianJBorgwarth/feat/current-vault-config-store
feat: vault_store and config
This commit is contained in:
commit
614bf67972
5 changed files with 61 additions and 2 deletions
|
|
@ -3,11 +3,14 @@ package handlers
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/store"
|
||||
)
|
||||
|
||||
type initializeCommand struct {
|
||||
VaultPath string `json:"vaultPath"`
|
||||
VaultPath string `json:"vaultPath"`
|
||||
TemplateDirectory string `json:"templateDirectory"`
|
||||
}
|
||||
|
||||
type InitializeHandler struct{}
|
||||
|
|
@ -23,7 +26,9 @@ func (h InitializeHandler) Handle(ctx context.Context, raw json.RawMessage) (any
|
|||
return nil, err
|
||||
}
|
||||
|
||||
err := persistence.InitializeDBContext(cmd.VaultPath)
|
||||
store := store.NewVaultStore(cmd.VaultPath, cmd.TemplateDirectory)
|
||||
|
||||
err := persistence.InitializeDBContext(store.Config.VaultPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
BIN
dendrite
BIN
dendrite
Binary file not shown.
2
persistence/config/doc.go
Normal file
2
persistence/config/doc.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
// Package persistenceconfig provides configuration for persistence layer
|
||||
package persistenceconfig
|
||||
24
persistence/config/vault_configuration.go
Normal file
24
persistence/config/vault_configuration.go
Normal 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
|
||||
}
|
||||
28
persistence/store/vault_store.go
Normal file
28
persistence/store/vault_store.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue