Move service related filed to services folder

This commit is contained in:
mitchell 2019-07-10 22:33:22 -04:00
parent 347fbe7268
commit 7d770ef150
41 changed files with 50 additions and 50 deletions

View 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
}

View 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:"
)

View 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)
}