feat: add secret store credential model
This commit is contained in:
parent
518b2c64d9
commit
4ea1573dc8
3 changed files with 53 additions and 3 deletions
|
|
@ -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{}
|
||||
}
|
||||
|
||||
|
|
|
|||
33
internal/secretstore/store.go
Normal file
33
internal/secretstore/store.go
Normal 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)
|
||||
}
|
||||
11
internal/secretstore/store_test.go
Normal file
11
internal/secretstore/store_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue