-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
47 lines (38 loc) · 1.08 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package yeahapi
import (
"context"
"github.com/gofrs/uuid"
)
type ClientID struct {
uuid.UUID
}
type clientType string
var (
ClientInternal clientType = "internal"
ClientConfidential clientType = "confidential"
ClientPublic clientType = "public"
)
type Client struct {
ID ClientID `json:"id"`
Name string `json:"name"`
Secret string
Type clientType `json:"type"`
Active bool `json:"active"`
}
type ClientService interface {
Client(ctx context.Context, id ClientID) (*Client, error)
VerifySecret(client *Client, secret string) error
CreateClient(ctx context.Context, client *Client) (*Client, error)
}
func (c *Client) Ok() error {
if c.Name == "" {
return E(EInvalid, "Client name is required")
} else if c.Type == "" {
return E(EInvalid, "Client type is required")
} else if c.Type != ClientInternal && c.Type != ClientConfidential && c.Type != ClientPublic {
return E(EInvalid, "Unsupported client type")
} else if c.Type != ClientPublic && c.Secret == "" {
return E(EInvalid, "Client secret is required for non-public clients")
}
return nil
}