-
Notifications
You must be signed in to change notification settings - Fork 2
/
keys.go
108 lines (91 loc) · 3.53 KB
/
keys.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
96
97
98
99
100
101
102
103
104
105
106
107
108
package dynamo
import (
"encoding/base64"
"fmt"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
)
// LpaKey is used as the PK for all Lpa related information.
func LpaKey(s string) string {
return "LPA#" + s
}
// DonorKey is used as the SK (with LpaKey as PK) for donor entered
// information. It is set to PAPER when the donor information has been provided
// from paper forms.
func DonorKey(s string) string {
return "#DONOR#" + s
}
// SubKey is used as the SK (with LpaKey as PK) to allow queries on a OneLogin
// sub against all Lpas an actor may have provided information on.
func SubKey(s string) string {
return "#SUB#" + s
}
// AttorneyKey is used as the SK (with LpaKey as PK) for attorney entered
// information.
func AttorneyKey(s string) string {
return "#ATTORNEY#" + s
}
// CertificateProviderKey is used as the SK (with LpaKey as PK) for certificate
// provider entered information.
func CertificateProviderKey(s string) string {
return "#CERTIFICATE_PROVIDER#" + s
}
// DocumentKey is used as the SK (with LpaKey as PK) for any documents uploaded
// as evidence for reduced fees.
func DocumentKey(s3Key string) string {
return "#DOCUMENT#" + s3Key
}
// EvidenceReceivedKey is used as the SK (with LpaKey as PK) to show that paper
// evidence has been submitted for an Lpa.
func EvidenceReceivedKey() string {
return "#EVIDENCE_RECEIVED"
}
// OrganisationKey is used as the PK to group organisation data; or as the SK
// (with OrganisationKey as PK) for the organisation itself; or as the SK (with
// LpaKey as PK) for the donor information entered by a member of an
// organisation.
func OrganisationKey(organisationID string) string {
return "ORGANISATION#" + organisationID
}
// MemberKey is used as the SK (with OrganisationKey as PK) for a member of an
// organisation.
func MemberKey(sessionID string) string {
return "MEMBER#" + sessionID
}
// MemberInviteKey is used as the SK (with OrganisationKey as PK) for a member
// invite.
func MemberInviteKey(email string) string {
return fmt.Sprintf("MEMBERINVITE#%s", base64.StdEncoding.EncodeToString([]byte(email)))
}
// MemberIDKey is used as the SK (with OrganisationKey as PK) to allow
// retrieving a member using their ID instead of their OneLogin sub.
func MemberIDKey(memberID string) string {
return "MEMBERID#" + memberID
}
// MetadataKey is used as the SK when the value of the SK is not used for any purpose.
func MetadataKey(s string) string {
return "#METADATA#" + s
}
// DonorShareKey is used as the PK for sharing an Lpa with a donor.
func DonorShareKey(code string) string {
return "DONORSHARE#" + code
}
// DonorInviteKey is used as the SK (with DonorShareKey as PK) for an invitation
// to a donor to link an Lpa being created by a member of an organisation.
func DonorInviteKey(organisationID, lpaID string) string {
return "DONORINVITE#" + organisationID + "#" + lpaID
}
// ShareCodeKey is used as the PK for sharing an Lpa with another actor.
func ShareCodeKey(actorType actor.Type, shareCode string) (pk string, err error) {
switch actorType {
case actor.TypeDonor:
return DonorShareKey(shareCode), nil
// As attorneys and replacement attorneys share the same landing page we can't
// differentiate between them
case actor.TypeAttorney, actor.TypeReplacementAttorney, actor.TypeTrustCorporation, actor.TypeReplacementTrustCorporation:
return "ATTORNEYSHARE#" + shareCode, nil
case actor.TypeCertificateProvider:
return "CERTIFICATEPROVIDERSHARE#" + shareCode, nil
default:
return "", fmt.Errorf("cannot have share code for actorType=%v", actorType)
}
}