-
Notifications
You must be signed in to change notification settings - Fork 342
/
model.go
95 lines (80 loc) · 2.09 KB
/
model.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package model
import (
"database/sql/driver"
"encoding/json"
"errors"
"time"
)
const (
StatementEffectAllow = "allow"
StatementEffectDeny = "deny"
)
type PaginationParams struct {
Prefix string
After string
Amount int
}
// Paginator describes the parameters of a slice of data from a database.
type Paginator struct {
Amount int
NextPageToken string
}
type User struct {
ID int `db:"id"`
CreatedAt time.Time `db:"created_at"`
Username string `db:"display_name" json:"display_name"`
}
// SuperuserConfiguration requests a particular configuration for a superuser.
type SuperuserConfiguration struct {
User
AccessKeyID string
SecretAccessKey string
}
type Group struct {
ID int `db:"id"`
CreatedAt time.Time `db:"created_at"`
DisplayName string `db:"display_name" json:"display_name"`
}
type Policy struct {
ID int `db:"id"`
CreatedAt time.Time `db:"created_at"`
DisplayName string `db:"display_name" json:"display_name"`
Statement Statements `db:"statement"`
}
type Statement struct {
Effect string `json:"Effect"`
Action []string `json:"Action"`
Resource string `json:"Resource"`
}
type Statements []Statement
var (
ErrInvalidStatementSrcFormat = errors.New("invalid statements src format")
)
func (s Statements) Value() (driver.Value, error) {
if s == nil {
return json.Marshal([]struct{}{})
}
return json.Marshal(s)
}
func (s *Statements) Scan(src interface{}) error {
if src == nil {
return nil
}
data, ok := src.([]byte)
if !ok {
return ErrInvalidStatementSrcFormat
}
return json.Unmarshal(data, s)
}
type Credential struct {
AccessKeyID string `db:"access_key_id"`
SecretAccessKey string `db:"-" json:"-"`
SecretAccessKeyEncryptedBytes []byte `db:"secret_access_key" json:"-"`
IssuedDate time.Time `db:"issued_date"`
UserID int `db:"user_id"`
}
// For JSON serialization:
type CredentialKeys struct {
AccessKeyID string `json:"access_key_id"`
SecretAccessKey string `json:"secret_access_key"`
}