-
Notifications
You must be signed in to change notification settings - Fork 15
/
termination.go
108 lines (94 loc) · 2.95 KB
/
termination.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 models
import (
"fmt"
"time"
)
type Blacklist uint8
const (
// Involuntary means the caller had access revoked immediately
Involuntary Blacklist = iota
// Voluntary means the caller had limited access then had their access completely revoked
Voluntary
// Limited means the caller has limited access to the service
Limited
)
type Attribution uint8
const (
AttributionHistorical Attribution = iota
AttributionLatest
)
type OptOut uint8
const (
OptOutHistorical OptOut = iota
OptOutLatest
)
type Claims uint8
const (
ClaimsHistorical Claims = iota
ClaimsLatest
)
type Termination struct {
TerminationDate time.Time // When caller moved from full to limited access
CutoffDate time.Time // When caller moved to no access
BlacklistType Blacklist
AttributionStrategy Attribution
OptOutStrategy OptOut
ClaimsStrategy Claims
}
// AttributionDate returns the date that should be used for attribution
// based on the associated attribution strategy.
// The returned date should be used as an upper bound when querying for
// attribution data.
func (t *Termination) AttributionDate() time.Time {
switch t.AttributionStrategy {
case AttributionHistorical:
return t.TerminationDate
case AttributionLatest:
// By returning a zero time, we signal to the caller
// that there should not be an upper bound placed on the
// attribution search.
// If we sent over time.Now(), we may unintentionally exclude results
// because of clock skew.
return time.Time{}
default:
panic(fmt.Sprintf("Unsupported attribution strategy %d supplied.", t.AttributionStrategy))
}
}
// OptOutDate returns the date that should be used for opt-outs
// based on the associated opt-out strategy.
// The returned date should be used as an upper bound when querying for
// opt-out data.
func (t *Termination) OptOutDate() time.Time {
switch t.OptOutStrategy {
case OptOutHistorical:
return t.TerminationDate
case OptOutLatest:
// By returning a zero time, we signal to the caller
// that there should not be an upper bound placed on the
// opt-out search.
// If we sent over time.Now(), we may unintentionally exclude results
// because of clock skew.
return time.Time{}
default:
panic(fmt.Sprintf("Unsupported opt-out strategy %d supplied.", t.OptOutStrategy))
}
}
// ClaimsDate returns the date that should be used for claims
// based on the associated claims strategy.
// The returned date should be used as an upper bound when querying for
// claims data.
func (t *Termination) ClaimsDate() time.Time {
switch t.ClaimsStrategy {
case ClaimsHistorical:
return t.TerminationDate
case ClaimsLatest:
// By returning a zero time, we signal to the caller
// that there should not be an upper bound placed on the
// claims search.
// If we sent over time.Now(), we may unintentionally exclude results
// because of clock skew.
return time.Time{}
default:
panic(fmt.Sprintf("Unsupported claims strategy %d supplied.", t.ClaimsStrategy))
}
}