-
Notifications
You must be signed in to change notification settings - Fork 402
/
apikeys.go
75 lines (64 loc) · 2.2 KB
/
apikeys.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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package console
import (
"context"
"time"
"storj.io/common/uuid"
)
// APIKeys is interface for working with api keys store
//
// architecture: Database
type APIKeys interface {
// GetPagedByProjectID is a method for querying API keys from the database by projectID and cursor
GetPagedByProjectID(ctx context.Context, projectID uuid.UUID, cursor APIKeyCursor) (akp *APIKeyPage, err error)
// Get retrieves APIKeyInfo with given ID
Get(ctx context.Context, id uuid.UUID) (*APIKeyInfo, error)
// GetByHead retrieves APIKeyInfo for given key head
GetByHead(ctx context.Context, head []byte) (*APIKeyInfo, error)
// GetByNameAndProjectID retrieves APIKeyInfo for given key name and projectID
GetByNameAndProjectID(ctx context.Context, name string, projectID uuid.UUID) (*APIKeyInfo, error)
// Create creates and stores new APIKeyInfo
Create(ctx context.Context, head []byte, info APIKeyInfo) (*APIKeyInfo, error)
// Update updates APIKeyInfo in store
Update(ctx context.Context, key APIKeyInfo) error
// Delete deletes APIKeyInfo from store
Delete(ctx context.Context, id uuid.UUID) error
}
// APIKeyInfo describing api key model in the database
type APIKeyInfo struct {
ID uuid.UUID `json:"id"`
ProjectID uuid.UUID `json:"projectId"`
PartnerID uuid.UUID `json:"partnerId"`
Name string `json:"name"`
Secret []byte `json:"-"`
CreatedAt time.Time `json:"createdAt"`
}
// APIKeyCursor holds info for api keys cursor pagination
type APIKeyCursor struct {
Search string
Limit uint
Page uint
Order APIKeyOrder
OrderDirection OrderDirection
}
// APIKeyPage represent api key page result
type APIKeyPage struct {
APIKeys []APIKeyInfo
Search string
Limit uint
Order APIKeyOrder
OrderDirection OrderDirection
Offset uint64
PageCount uint
CurrentPage uint
TotalCount uint64
}
// APIKeyOrder is used for querying api keys in specified order
type APIKeyOrder uint8
const (
// KeyName indicates that we should order by key name
KeyName APIKeyOrder = 1
// CreationDate indicates that we should order by creation date
CreationDate APIKeyOrder = 2
)