2019-04-15 03:56:55 +00:00
|
|
|
package types
|
|
|
|
|
2019-05-06 00:56:27 +00:00
|
|
|
import (
|
2019-05-28 01:16:50 +00:00
|
|
|
"fmt"
|
2019-05-06 00:56:27 +00:00
|
|
|
"time"
|
|
|
|
)
|
2019-04-15 03:56:55 +00:00
|
|
|
|
2019-05-22 15:22:40 +00:00
|
|
|
const TypePrefixCred = "cred"
|
|
|
|
|
2019-04-15 03:56:55 +00:00
|
|
|
type Credential struct {
|
|
|
|
Metadata
|
2019-05-28 01:16:50 +00:00
|
|
|
Username string
|
|
|
|
Email string
|
|
|
|
Password string `json:"-"`
|
|
|
|
OTPSecret string `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Credential) String() string {
|
2019-06-30 04:17:22 +00:00
|
|
|
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...)
|
2019-04-15 03:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type CredentialInput struct {
|
|
|
|
MetadataInput
|
2019-05-28 01:16:50 +00:00
|
|
|
Username string
|
|
|
|
Email string
|
|
|
|
Password string
|
|
|
|
OTPSecret string
|
2019-04-15 03:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Metadata struct {
|
2019-05-06 00:56:27 +00:00
|
|
|
ID string // primary key
|
|
|
|
SourceHost string // sort key
|
2019-04-15 03:56:55 +00:00
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
|
|
|
Primary string
|
|
|
|
LoginURL string
|
2019-05-22 15:22:40 +00:00
|
|
|
Tag string
|
2019-04-15 03:56:55 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 01:16:50 +00:00
|
|
|
func (m Metadata) String() string {
|
2019-06-30 04:17:22 +00:00
|
|
|
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...)
|
2019-05-28 01:16:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 03:56:55 +00:00
|
|
|
type MetadataInput struct {
|
|
|
|
Primary string
|
|
|
|
SourceHost string
|
|
|
|
LoginURL string
|
2019-05-22 15:22:40 +00:00
|
|
|
Tag string
|
2019-04-15 03:56:55 +00:00
|
|
|
}
|