-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
results.go
90 lines (77 loc) · 3.31 KB
/
results.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
// Copyright 2020 - Offen Authors <hioffen@posteo.de>
// SPDX-License-Identifier: Apache-2.0
package persistence
import "time"
// SecretResult contains information about a single secret record
type SecretResult struct {
SecretID string `json:"secretId"`
EncryptedSecret string `json:"encryptedSecret"`
}
// EventsResult contains all data that is returned to a user requesting their
// data
type EventsResult struct {
Events *EventsByAccountID `json:"events,omitempty"`
DeletedEvents []string `json:"deletedEvents,omitempty"`
Sequence string `json:"sequence,omitempty"`
RetentionPeriod string `json:"retentionPeriod,omitempty"`
}
// EventResult is an element returned from a query. It contains all data that
// is stored about an atomic event.
type EventResult struct {
AccountID string `json:"accountId,omitempty"`
SecretID *string `json:"secretId,omitempty"`
EventID string `json:"eventId"`
Payload string `json:"payload"`
}
// EventsByAccountID groups a list of events by AccountID in a response
type EventsByAccountID map[string][]EventResult
// EncryptedSecretsByID is a map of secret IDs and their respective
// encrypted user secrets
type EncryptedSecretsByID map[string]string
// AccountResult is the data returned from looking up an account by id
type AccountResult struct {
AccountID string `json:"accountId"`
Name string `json:"name"`
PublicKey interface{} `json:"publicKey,omitempty"`
EncryptedPrivateKey string `json:"encryptedPrivateKey,omitempty"`
Events *EventsByAccountID `json:"events,omitempty"`
DeletedEvents []string `json:"deletedEvents,omitempty"`
Sequence string `json:"sequence,omitempty"`
Secrets *EncryptedSecretsByID `json:"secrets,omitempty"`
AccountStyles string `json:"accountStyles,omitempty"`
Created time.Time `json:"created,omitempty"`
RetentionPeriod string `json:"retentionPeriod,omitempty"`
}
// ShareAccountResult is a successful invitation of a user
type ShareAccountResult struct {
UserExistsWithPassword bool
AccountNames []string
}
// LoginResult is a successful account user authentication response.
type LoginResult struct {
AccountUserID string `json:"accountUserId"`
AdminLevel AccountUserAdminLevel `json:"adminLevel"`
Accounts []LoginAccountResult `json:"accounts"`
}
// CanAccessAccount checks whether the login result is allowed to access the
// account of the given identifier.
func (l *LoginResult) CanAccessAccount(accountID string) bool {
for _, account := range l.Accounts {
if accountID == account.AccountID {
return true
}
}
return false
}
// IsSuperAdmin checks whether the login result is a SuperAdmin.
func (l *LoginResult) IsSuperAdmin() bool {
return l.AdminLevel == AccountUserAdminLevelSuperAdmin
}
// LoginAccountResult contains information for the client to handle an account
// in the client at runtime.
type LoginAccountResult struct {
AccountName string `json:"accountName"`
AccountID string `json:"accountId"`
KeyEncryptionKey interface{} `json:"keyEncryptionKey"`
Created time.Time `json:"created"`
}