-
Notifications
You must be signed in to change notification settings - Fork 40
/
router.go
295 lines (234 loc) · 17.2 KB
/
router.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package gater
import (
"io"
"net/http"
"github.com/gorilla/mux"
"github.com/bnb-chain/greenfield-storage-provider/base/gfspapp"
"github.com/bnb-chain/greenfield-storage-provider/pkg/log"
mwhttp "github.com/bnb-chain/greenfield-storage-provider/pkg/middleware/http"
)
const (
approvalRouterName = "GetApproval"
putObjectRouterName = "PutObject"
resumablePutObjectRouterName = "ResumablePutObject"
queryResumeOffsetName = "QueryResumeOffsetName"
getObjectRouterName = "GetObject"
getChallengeInfoRouterName = "GetChallengeInfo"
getChallengeInfoV2RouterName = "GetChallengeInfoV2"
replicateObjectPieceRouterName = "ReplicateObjectPiece"
getUserBucketsRouterName = "GetUserBuckets"
listObjectsByBucketRouterName = "ListObjectsByBucketName"
verifyPermissionRouterName = "VerifyPermission"
getBucketReadQuotaRouterName = "GetBucketReadQuota"
listBucketReadRecordRouterName = "ListBucketReadRecord"
requestNonceRouterName = "RequestNonce"
updateUserPublicKeyRouterName = "UpdateUserPublicKey"
queryUploadProgressRouterName = "QueryUploadProgress"
downloadObjectByUniversalEndpointName = "DownloadObjectByUniversalEndpoint"
viewObjectByUniversalEndpointName = "ViewObjectByUniversalEndpoint"
getObjectMetaRouterName = "GetObjectMeta"
getBucketMetaRouterName = "GetBucketMeta"
getGroupListRouterName = "GetGroupList"
listBucketsByIDsRouterName = "ListBucketsByIDs"
listObjectsByIDsRouterName = "ListObjectsByIDs"
recoveryPieceRouterName = "RecoveryObjectPiece"
getPieceFromSecondaryRouterName = "GetPieceFromSecondary"
getPaymentByBucketIDRouterName = "GetPaymentByBucketID"
getPaymentByBucketNameRouterName = "GetPaymentByBucketName"
getBucketByBucketNameRouterName = "GetBucketByBucketName"
getBucketByBucketIDRouterName = "GetBucketByBucketID"
listDeletedObjectsByBlockNumberRangeRouterName = "ListDeletedObjectsByBlockNumberRange"
getUserBucketsCountRouterName = "GetUserBucketsCount"
listExpiredBucketsBySpRouterName = "ListExpiredBucketsBySp"
notifyMigrateSwapOutRouterName = "NotifyMigrateSwapOut"
migratePieceRouterName = "MigratePiece"
migrationBucketApprovalName = "MigrationBucketApproval"
swapOutApprovalName = "SwapOutApproval"
listVirtualGroupFamiliesBySpIDRouterName = "ListVirtualGroupFamiliesBySpID"
getVirtualGroupFamilyRouterName = "GetVirtualGroupFamily"
getGlobalVirtualGroupByGvgIDRouterName = "GetGlobalVirtualGroupByGvgID"
getGlobalVirtualGroupRouterName = "GetGlobalVirtualGroup"
listGlobalVirtualGroupsBySecondarySPRouterName = "ListGlobalVirtualGroupsBySecondarySP"
listGlobalVirtualGroupsByBucketRouterName = "ListGlobalVirtualGroupsByBucket"
listObjectsInGVGAndBucketRouterName = "ListObjectsInGVGAndBucket"
listObjectsByGVGAndBucketForGCRouterName = "ListObjectsByGVGAndBucketForGC"
listObjectsInGVGRouterName = "ListObjectsInGVG"
listMigrateBucketEventsRouterName = "ListMigrateBucketEvents"
listSwapOutEventsRouterName = "ListSwapOutEvents"
listSpExitEventsRouterName = "ListSpExitEvents"
verifyPermissionByIDRouterName = "VerifyPermissionByID"
getSPInfoRouterName = "GetSPInfo"
getStatusRouterName = "GetStatus"
getUserGroupsRouterName = "GetUserGroups"
getGroupMembersRouterName = "GetGroupMembers"
getUserOwnedGroupsRouterName = "GetUserOwnedGroups"
listObjectPoliciesRouterName = "ListObjectPolicies"
listUserPaymentAccountsRouterName = "ListUserPaymentAccounts"
listPaymentAccountStreamsRouterName = "ListPaymentAccountStreams"
listGroupsByIDsRouterName = "ListGroupsByIDs"
getSPMigratingBucketNumberRouterName = "GetSPMigratingBucketNumber"
verifyMigrateGVGPermissionRouterName = "VerifyMigrateGVGPermission"
)
const (
createBucketApprovalAction = "CreateBucket"
createObjectApprovalAction = "CreateObject"
migrateBucketApprovalAction = "MigrateBucket"
)
// notFoundHandler log not found request info.
func (g *GateModular) notFoundHandler(w http.ResponseWriter, r *http.Request) {
log.Errorw("failed to find the corresponding handler", "method", r.Method, "host", r.Host, "url", r.URL)
if _, err := io.ReadAll(r.Body); err != nil {
log.Errorw("failed to read the unknown request", "error", err)
}
}
// RegisterHandler registers the handlers to the gateway router.
func (g *GateModular) RegisterHandler(router *mux.Router) {
// off-chain-auth router
router.Path(AuthRequestNoncePath).Name(requestNonceRouterName).Methods(http.MethodGet).HandlerFunc(g.requestNonceHandler)
router.Path(AuthUpdateKeyPath).Name(updateUserPublicKeyRouterName).Methods(http.MethodPost).HandlerFunc(g.updateUserPublicKeyHandler)
// verify permission router
router.Path("/permission/{operator:.+}/{bucket:[^/]*}/{action-type:.+}").Name(verifyPermissionRouterName).
Methods(http.MethodGet).HandlerFunc(g.verifyPermissionHandler)
// admin router, path style
// Get Approval
router.Path(GetApprovalPath).Name(approvalRouterName).Methods(http.MethodGet).HandlerFunc(g.getApprovalHandler).
Queries(ActionQuery, "{action}")
// get challenge info
router.Path(GetChallengeInfoPath).Name(getChallengeInfoRouterName).Methods(http.MethodGet).HandlerFunc(g.getChallengeInfoHandler)
router.Path(GetChallengeInfoV2Path).Name(getChallengeInfoV2RouterName).Methods(http.MethodGet).HandlerFunc(g.getChallengeInfoV2Handler)
// replicate piece to receiver
router.Path(ReplicateObjectPiecePath).Name(replicateObjectPieceRouterName).Methods(http.MethodPut).HandlerFunc(g.replicateHandler)
// data recovery
router.Path(RecoverObjectPiecePath).Name(recoveryPieceRouterName).Methods(http.MethodGet).HandlerFunc(g.getRecoverDataHandler)
// dest sp receive swap out notify from src sp.
router.Path(NotifyMigrateSwapOutTaskPath).Name(notifyMigrateSwapOutRouterName).Methods(http.MethodPost).HandlerFunc(g.notifyMigrateSwapOutHandler)
// dest sp pull piece data from src sp, for sp exit and bucket migrate.
router.Path(MigratePiecePath).Name(migratePieceRouterName).Methods(http.MethodGet).HandlerFunc(g.migratePieceHandler)
// migration bucket approval for secondary sp bls signature.
router.Path(SecondarySPMigrationBucketApprovalPath).Name(migrationBucketApprovalName).Methods(http.MethodGet).HandlerFunc(g.getSecondaryBlsMigrationBucketApprovalHandler)
// swap out approval for sp exiting.
router.Path(SwapOutApprovalPath).Name(swapOutApprovalName).Methods(http.MethodGet).HandlerFunc(g.getSwapOutApproval)
// universal endpoint download
router.Path("/download/{bucket:[^/]*}/{object:.+}").Name(downloadObjectByUniversalEndpointName).Methods(http.MethodGet).
HandlerFunc(g.downloadObjectByUniversalEndpointHandler)
router.Path("/download").Name(downloadObjectByUniversalEndpointName).Methods(http.MethodGet).
Queries(UniversalEndpointSpecialSuffixQuery, "{bucket:[^/]*}/{object:.+}").HandlerFunc(g.downloadObjectByUniversalEndpointHandler)
// universal endpoint view
router.Path("/view/{bucket:[^/]*}/{object:.+}").Name(viewObjectByUniversalEndpointName).Methods(http.MethodGet).
HandlerFunc(g.viewObjectByUniversalEndpointHandler)
router.Path("/view").Name(viewObjectByUniversalEndpointName).Methods(http.MethodGet).
Queries(UniversalEndpointSpecialSuffixQuery, "{bucket:[^/]*}/{object:.+}").HandlerFunc(g.viewObjectByUniversalEndpointHandler)
router.Path(StatusPath).Name(getStatusRouterName).Methods(http.MethodGet).HandlerFunc(g.getStatusHandler)
var routers []*mux.Router
routers = append(routers, router.Host("{bucket:.+}."+g.domain).Subrouter())
routers = append(routers, router.PathPrefix("/{bucket}").Subrouter())
for _, r := range routers {
// Put Object By Offset
r.NewRoute().Name(resumablePutObjectRouterName).Methods(http.MethodPost).Path("/{object:.+}").HandlerFunc(g.resumablePutObjectHandler).
Queries("offset", "{offset}", "complete", "{complete}")
// Put Object
r.NewRoute().Name(putObjectRouterName).Methods(http.MethodPut).Path("/{object:.+}").HandlerFunc(g.putObjectHandler)
// QueryPutObjectOffset
r.NewRoute().Name(queryResumeOffsetName).Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(g.queryResumeOffsetHandler).
Queries(UploadContextQuery, "")
// Query upload progress
r.NewRoute().Name(queryUploadProgressRouterName).Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(g.queryUploadProgressHandler).
Queries(UploadProgressQuery, "")
// Get Bucket Meta
r.NewRoute().Name(getBucketMetaRouterName).Methods(http.MethodGet).Queries(GetBucketMetaQuery, "").HandlerFunc(g.getBucketMetaHandler)
// Get Object Meta
r.NewRoute().Name(getObjectMetaRouterName).Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(g.getObjectMetaHandler).
Queries(GetObjectMetaQuery, "")
// List Object Policies
r.NewRoute().Name(listObjectPoliciesRouterName).Methods(http.MethodGet).Path("/{object:.+}").Queries(ListObjectPoliciesQuery, "").
HandlerFunc(g.listObjectPoliciesHandler)
// Get Object
r.NewRoute().Name(getObjectRouterName).Methods(http.MethodGet).Path("/{object:.+}").HandlerFunc(g.getObjectHandler)
// Get Bucket Read Quota
r.NewRoute().Name(getBucketReadQuotaRouterName).Methods(http.MethodGet).HandlerFunc(g.getBucketReadQuotaHandler).Queries(
GetBucketReadQuotaQuery, "", GetBucketReadQuotaMonthQuery, "{year_month}")
if g.env != gfspapp.EnvMainnet {
// Get Bucket By Bucket Name
r.NewRoute().Name(getBucketByBucketNameRouterName).Methods(http.MethodGet).Queries(GetBucketByBucketNameQuery, "").HandlerFunc(g.getBucketByBucketNameHandler)
// Get Payment By Bucket Name
r.NewRoute().Name(getPaymentByBucketNameRouterName).Methods(http.MethodGet).Queries(GetPaymentByBucketNameQuery, "").HandlerFunc(g.getPaymentByBucketNameHandler)
}
// List Bucket Read Record
r.NewRoute().Name(listBucketReadRecordRouterName).Methods(http.MethodGet).HandlerFunc(g.listBucketReadRecordHandler).Queries(
ListBucketReadRecordQuery, "", ListBucketReadRecordMaxRecordsQuery, "{max_records}",
StartTimestampUs, "{start_ts}", EndTimestampUs, "{end_ts}")
// List Objects by bucket
r.NewRoute().Name(listObjectsByBucketRouterName).Methods(http.MethodGet).Path("/").HandlerFunc(g.listObjectsByBucketNameHandler)
// Not found
r.NotFoundHandler = http.HandlerFunc(g.notFoundHandler)
}
// Get Group List
router.Path("/").Name(getGroupListRouterName).Methods(http.MethodGet).Queries(GetGroupListGroupQuery, "").HandlerFunc(g.getGroupListHandler)
// List Objects By IDs
router.Path("/").Name(listObjectsByIDsRouterName).Methods(http.MethodGet).Queries(ListObjectsByIDsQuery, "").HandlerFunc(g.listObjectsByIDsHandler)
// List Buckets By IDs
router.Path("/").Name(listBucketsByIDsRouterName).Methods(http.MethodGet).Queries(ListBucketsByIDsQuery, "").HandlerFunc(g.listBucketsByIDsHandler)
// Verify Permission By ID
router.Path("/").Name(verifyPermissionByIDRouterName).Methods(http.MethodGet).Queries(VerifyPermissionByIDQuery, "").HandlerFunc(g.verifyPermissionByIDHandler)
// Get User Groups
router.Path("/").Name(getUserGroupsRouterName).Methods(http.MethodGet).Queries(GetUserGroupsQuery, "").HandlerFunc(g.getUserGroupsHandler)
// Get Group Members
router.Path("/").Name(getGroupMembersRouterName).Methods(http.MethodGet).Queries(GetGroupMembersQuery, "").HandlerFunc(g.getGroupMembersHandler)
// Get User Owned Groups
router.Path("/").Name(getUserOwnedGroupsRouterName).Methods(http.MethodGet).Queries(GetUserOwnedGroupsQuery, "").HandlerFunc(g.getUserOwnedGroupsHandler)
// List Payment Account Streams
router.Path("/").Name(listPaymentAccountStreamsRouterName).Methods(http.MethodGet).Queries(ListPaymentAccountStreamsQuery, "").HandlerFunc(g.listPaymentAccountStreamsHandler)
// List User Payment Accounts
router.Path("/").Name(listUserPaymentAccountsRouterName).Methods(http.MethodGet).Queries(ListUserPaymentAccountsQuery, "").HandlerFunc(g.listUserPaymentAccountsHandler)
// List Groups By IDs
router.Path("/").Name(listGroupsByIDsRouterName).Methods(http.MethodGet).Queries(ListGroupsByIDsQuery, "").HandlerFunc(g.listGroupsByIDsHandler)
if g.env != gfspapp.EnvMainnet {
// Get Payment By Bucket ID
router.Path("/").Name(getPaymentByBucketIDRouterName).Methods(http.MethodGet).Queries(GetPaymentByBucketIDQuery, "").HandlerFunc(g.getPaymentByBucketIDHandler)
// Get Bucket By Bucket ID
router.Path("/").Name(getBucketByBucketIDRouterName).Methods(http.MethodGet).Queries(GetBucketByBucketIDQuery, "").HandlerFunc(g.getBucketByBucketIDHandler)
// List Deleted Objects
router.Path("/").Name(listDeletedObjectsByBlockNumberRangeRouterName).Methods(http.MethodGet).Queries(ListDeletedObjectsQuery, "").HandlerFunc(g.listDeletedObjectsByBlockNumberRangeHandler)
// Get User Buckets Count
router.Path("/").Name(getUserBucketsCountRouterName).Methods(http.MethodGet).Queries(GetUserBucketsCountQuery, "").HandlerFunc(g.getUserBucketsCountHandler)
// List Expired Buckets By Sp
router.Path("/").Name(listExpiredBucketsBySpRouterName).Methods(http.MethodGet).Queries(ListExpiredBucketsBySpQuery, "").HandlerFunc(g.listExpiredBucketsBySpHandler)
// List Virtual Group Families By Sp ID
router.Path("/").Name(listVirtualGroupFamiliesBySpIDRouterName).Methods(http.MethodGet).Queries(ListVirtualGroupFamiliesBySpIDQuery, "").HandlerFunc(g.listVirtualGroupFamiliesBySpIDHandler)
// Get Virtual Group Families By Vgf ID
router.Path("/").Name(getVirtualGroupFamilyRouterName).Methods(http.MethodGet).Queries(GetVirtualGroupFamilyQuery, "").HandlerFunc(g.getVirtualGroupFamilyHandler)
// Get Global Virtual Group By Gvg ID
router.Path("/").Name(getGlobalVirtualGroupByGvgIDRouterName).Methods(http.MethodGet).Queries(GetGlobalVirtualGroupByGvgIDQuery, "").HandlerFunc(g.getGlobalVirtualGroupByGvgIDHandler)
// Get Global Virtual Group By Lvg ID And Bucket ID
router.Path("/").Name(getGlobalVirtualGroupRouterName).Methods(http.MethodGet).Queries(GetGlobalVirtualGroupQuery, "").HandlerFunc(g.getGlobalVirtualGroupHandler)
// List Global Virtual Group By Secondary Sp ID
router.Path("/").Name(listGlobalVirtualGroupsBySecondarySPRouterName).Methods(http.MethodGet).Queries(ListGlobalVirtualGroupsBySecondarySPQuery, "").HandlerFunc(g.listGlobalVirtualGroupsBySecondarySPHandler)
// List Global Virtual Group By Bucket ID
router.Path("/").Name(listGlobalVirtualGroupsByBucketRouterName).Methods(http.MethodGet).Queries(ListGlobalVirtualGroupsByBucketQuery, "").HandlerFunc(g.listGlobalVirtualGroupsByBucketHandler)
// List Objects By Gvg And Bucket ID
router.Path("/").Name(listObjectsInGVGAndBucketRouterName).Methods(http.MethodGet).Queries(ListObjectsInGVGAndBucketQuery, "").HandlerFunc(g.listObjectsInGVGAndBucketHandler)
// List Objects By Gvg And Bucket ID
router.Path("/").Name(listObjectsByGVGAndBucketForGCRouterName).Methods(http.MethodGet).Queries(ListObjectsByGVGAndBucketForGCQuery, "").HandlerFunc(g.listObjectsByGVGAndBucketForGCHandler)
// List Objects By Gvg And Bucket ID
router.Path("/").Name(listObjectsInGVGRouterName).Methods(http.MethodGet).Queries(ListObjectsInGVGQuery, "").HandlerFunc(g.listObjectsInGVGHandler)
// List Migrate Bucket Events
router.Path("/").Name(listMigrateBucketEventsRouterName).Methods(http.MethodGet).Queries(ListMigrateBucketEventsQuery, "").HandlerFunc(g.listMigrateBucketEventsHandler)
// List Swap Out Events
router.Path("/").Name(listSwapOutEventsRouterName).Methods(http.MethodGet).Queries(ListSwapOutEventsQuery, "").HandlerFunc(g.listSwapOutEventsHandler)
// List Sp Exit Events
router.Path("/").Name(listSpExitEventsRouterName).Methods(http.MethodGet).Queries(ListSpExitEventsQuery, "").HandlerFunc(g.listSpExitEventsHandler)
// Get Sp info by operator address
router.Path("/").Name(getSPInfoRouterName).Methods(http.MethodGet).Queries(GetSPInfoQuery, "").HandlerFunc(g.getSPInfoHandler)
// Get SP Migrate Bucket Number
router.Path("/").Name(getSPMigratingBucketNumberRouterName).Methods(http.MethodGet).Queries(GetSPMigratingBucketNumberQuery, "").HandlerFunc(g.getSPMigratingBucketNumberHandler)
// Verify the destination sp id of bucket migration & swap out
router.Path("/").Name(verifyMigrateGVGPermissionRouterName).Methods(http.MethodGet).Queries(VerifyMigrateGVGPermissionQuery, "").HandlerFunc(g.verifyMigrateGVGPermissionHandler)
}
router.Path("/").Name(getUserBucketsRouterName).Methods(http.MethodGet).HandlerFunc(g.getUserBucketsHandler)
// bucket list router, path style
router.Path("/").Name(getUserBucketsRouterName).Methods(http.MethodGet).HandlerFunc(g.getUserBucketsHandler)
// redirect for universal endpoint
http.Handle("/", router)
router.NotFoundHandler = http.HandlerFunc(g.notFoundHandler)
router.Use(mwhttp.Limit(g.domain))
}