feat: add secret store credential model

This commit is contained in:
thibaud-leclere 2026-04-10 09:45:35 +02:00
parent 518b2c64d9
commit 4ea1573dc8
3 changed files with 53 additions and 3 deletions

View file

@ -1,10 +1,16 @@
package cli
import "fmt"
import (
"fmt"
type App struct{}
"email-mcp/internal/secretstore"
)
func NewApp() *App {
type App struct {
store secretstore.Store
}
func NewApp(_ ...any) *App {
return &App{}
}

View file

@ -0,0 +1,33 @@
package secretstore
import (
"context"
"fmt"
"strings"
)
const DefaultAccountKey = "default"
type Credential struct {
Host string `json:"host"`
Username string `json:"username"`
Password string `json:"password"`
}
func (c Credential) Validate() error {
if strings.TrimSpace(c.Host) == "" {
return fmt.Errorf("imap host is required")
}
if strings.TrimSpace(c.Username) == "" {
return fmt.Errorf("username is required")
}
if strings.TrimSpace(c.Password) == "" {
return fmt.Errorf("password is required")
}
return nil
}
type Store interface {
Save(ctx context.Context, key string, cred Credential) error
Load(ctx context.Context, key string) (Credential, error)
}

View file

@ -0,0 +1,11 @@
package secretstore
import "testing"
func TestCredentialValidateRequiresAllFields(t *testing.T) {
cred := Credential{Host: "imap.example.com", Username: "alice"}
if err := cred.Validate(); err == nil {
t.Fatal("expected validation error when password is missing")
}
}