-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresponsevalidators.go
137 lines (124 loc) · 3.35 KB
/
responsevalidators.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// QCLauncher by syncore <[email protected]> 2017
// https://github.com/syncore/qclauncher
package qclauncher
import (
"fmt"
"strings"
)
func validateResponse(r remoteResponse) error {
return r.validate()
}
func (r *AuthResponse) validate() error {
msg := "Auth/verify response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil auth/verify response", msg)
}
if r.Token == "" {
return fmt.Errorf("%s got empty auth/verify token", msg)
}
if len(r.EntitlementIDs) == 0 {
return fmt.Errorf("%s no entitlement ids present", msg)
}
hasQc := false
for _, v := range r.EntitlementIDs {
if v == qcEntitlmentID {
hasQc = true
break
}
}
if !hasQc {
return fmt.Errorf("%s user does not have QC access", msg)
}
return nil
}
func (r *EntitlementInfoResponse) validate() error {
msg := "Entitlement info response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil entitlement info response", msg)
}
if len(r.Projects) == 0 {
return fmt.Errorf("%s no project info present", msg)
}
if len(r.Branches) == 0 {
return fmt.Errorf("%s no branch info present", msg)
}
return nil
}
func (r *BuildInfoResponse) validate() error {
msg := "Build info response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil build info response", msg)
}
if len(r.Projects) == 0 {
return fmt.Errorf("%s no project info present", msg)
}
if len(r.Branches) == 0 {
return fmt.Errorf("%s no branch info present", msg)
}
return nil
}
func (r *BranchInfoResponse) validate() error {
msg := "Branch info response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil branch info response", msg)
}
if len(r.LaunchinfoList) == 0 {
return fmt.Errorf("%s no launch info present", msg)
}
return nil
}
func (r *LaunchArgsResponse) validate() error {
msg := "Launch args response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil launch args response", msg)
}
return nil
}
func (r *GameCodeResponse) validate() error {
msg := "Game code response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil game code response", msg)
}
if r.Gamecode == "" {
return fmt.Errorf("%s got empty game code response", msg)
}
return nil
}
func (r *ServerStatusResponse) validate() error {
msg := "Server status response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil server status response", msg)
}
if r.Platform.Message == "" {
return fmt.Errorf("%s got empty platform message response", msg)
}
if !strings.EqualFold(r.Platform.Message, "success") {
return fmt.Errorf("%s returned a non-successful platform message, returned: %s",
msg, r.Platform.Message)
}
return nil
}
func (r *UpdateQCResponse) validate() error {
msg := "QC update check response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil update qc response", msg)
}
if len(r.Hashes) == 0 {
return fmt.Errorf("%s got empty hashes when checking for update", msg)
}
return nil
}
func (r *UpdateLauncherResponse) validate() error {
msg := "QC update launcher response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil update launcher response", msg)
}
return nil
}
func (r *EntitlementCheckAPIResponse) validate() error {
msg := "Entitlement check API response failed validation:"
if r == nil {
return fmt.Errorf("%s got nil entitlement check API response", msg)
}
return nil
}