mirror of
https://github.com/mitchell/selfpass.git
synced 2025-12-14 21:27:22 +00:00
Move service related filed to services folder
This commit is contained in:
parent
347fbe7268
commit
7d770ef150
41 changed files with 50 additions and 50 deletions
75
services/credentials/types/credential.go
Normal file
75
services/credentials/types/credential.go
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const TypePrefixCred = "cred"
|
||||
|
||||
type Credential struct {
|
||||
Metadata
|
||||
Username string
|
||||
Email string
|
||||
Password string `json:"-"`
|
||||
OTPSecret string `json:"-"`
|
||||
}
|
||||
|
||||
func (c Credential) String() string {
|
||||
format := "%s"
|
||||
args := []interface{}{c.Metadata}
|
||||
|
||||
if c.Username != "" {
|
||||
format += "username = %s\n"
|
||||
args = append(args, c.Username)
|
||||
}
|
||||
|
||||
if c.Email != "" {
|
||||
format += "email = %s\n"
|
||||
args = append(args, c.Email)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(format, args...)
|
||||
}
|
||||
|
||||
type CredentialInput struct {
|
||||
MetadataInput
|
||||
Username string
|
||||
Email string
|
||||
Password string
|
||||
OTPSecret string
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
ID string // primary key
|
||||
SourceHost string // sort key
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Primary string
|
||||
LoginURL string
|
||||
Tag string
|
||||
}
|
||||
|
||||
func (m Metadata) String() string {
|
||||
format := "id = %s\ncreatedAt = %s\nupdatedAt = %s\nsourceHost = %s\nprimary = %s\n"
|
||||
args := []interface{}{m.ID, m.CreatedAt, m.UpdatedAt, m.SourceHost, m.Primary}
|
||||
|
||||
if m.LoginURL != "" {
|
||||
format += "loginUrl = %s\n"
|
||||
args = append(args, m.LoginURL)
|
||||
}
|
||||
|
||||
if m.Tag != "" {
|
||||
format += "tag = %s\n"
|
||||
args = append(args, m.Tag)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(format, args...)
|
||||
}
|
||||
|
||||
type MetadataInput struct {
|
||||
Primary string
|
||||
SourceHost string
|
||||
LoginURL string
|
||||
Tag string
|
||||
}
|
||||
8
services/credentials/types/error_prefixes.go
Normal file
8
services/credentials/types/error_prefixes.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package types
|
||||
|
||||
// These constants are the prefixes of errors that should be exposed to the client.
|
||||
// All error encoders should check for them.
|
||||
const (
|
||||
NotFound = "not found:"
|
||||
InvalidArgument = "invalid argument:"
|
||||
)
|
||||
30
services/credentials/types/interfaces.go
Normal file
30
services/credentials/types/interfaces.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package types
|
||||
|
||||
import "context"
|
||||
|
||||
type Service interface {
|
||||
GetAllMetadata(ctx context.Context, sourceHost string) (output <-chan Metadata, errch chan error)
|
||||
Get(ctx context.Context, id string) (output Credential, err error)
|
||||
Create(ctx context.Context, ci CredentialInput) (output Credential, err error)
|
||||
Update(ctx context.Context, id string, ci CredentialInput) (output Credential, err error)
|
||||
Delete(ctx context.Context, id string) (err error)
|
||||
DumpDB(ctx context.Context) (bs []byte, err error)
|
||||
}
|
||||
|
||||
type CredentialRepo interface {
|
||||
GetAllMetadata(ctx context.Context, sourceHost string, errch chan<- error) (output <-chan Metadata)
|
||||
Get(ctx context.Context, id string) (output Credential, err error)
|
||||
Put(ctx context.Context, c Credential) (err error)
|
||||
Delete(ctx context.Context, id string) (err error)
|
||||
DumpDB(ctx context.Context) (bs []byte, err error)
|
||||
}
|
||||
|
||||
type CredentialClientInit func(ctx context.Context, target, ca, cert, key string) (c CredentialClient, err error)
|
||||
|
||||
type CredentialClient interface {
|
||||
GetAllMetadata(ctx context.Context, sourceHost string) (output <-chan Metadata, errch chan error)
|
||||
Get(ctx context.Context, id string) (output Credential, err error)
|
||||
Create(ctx context.Context, ci CredentialInput) (output Credential, err error)
|
||||
Update(ctx context.Context, id string, ci CredentialInput) (output Credential, err error)
|
||||
Delete(ctx context.Context, id string) (err error)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue