Skip to content

Commit 134ea34

Browse files
committed
add allow/blocklist in info endpoint
1 parent f6ea39d commit 134ea34

File tree

6 files changed

+53
-13
lines changed

6 files changed

+53
-13
lines changed

server/api/read/models/de_web_info.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/api/read/restapi/embedded_spec.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/api/readAPI-V0.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,11 @@ definitions:
6666
chainID:
6767
type: integer
6868
format: int64
69+
allowList:
70+
type: array
71+
items:
72+
type: string
73+
blockList:
74+
type: array
75+
items:
76+
type: string

server/int/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,5 @@ func (a *API) configureAPI() {
124124

125125
a.DewebAPI.GetResourceHandler = operations.GetResourceHandlerFunc(getResourceHandler)
126126
a.DewebAPI.DefaultPageHandler = operations.DefaultPageHandlerFunc(defaultPageHandler)
127-
a.DewebAPI.GetDeWebInfoHandler = NewDewebInfo(a.Conf.MiscPublicInfoJson, a.Conf.NetworkInfos)
127+
a.DewebAPI.GetDeWebInfoHandler = NewDewebInfo(a.Conf)
128128
}

server/int/api/handlers.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/go-openapi/runtime/middleware"
99
"github.com/massalabs/deweb-server/api/read/models"
1010
"github.com/massalabs/deweb-server/api/read/restapi/operations"
11+
userConfig "github.com/massalabs/deweb-server/int/api/config"
1112
config "github.com/massalabs/station/int/config"
1213
"github.com/massalabs/station/pkg/logger"
1314
)
@@ -32,12 +33,11 @@ func defaultPageHandler(params operations.DefaultPageParams) middleware.Responde
3233

3334
/*Handle get deweb public infos*/
3435
type dewebInfo struct {
35-
miscInfo interface{}
36-
networkInfo config.NetworkInfos
36+
conf *userConfig.ServerConfig
3737
}
3838

39-
func NewDewebInfo(miscInfo interface{}, networkInfo config.NetworkInfos) operations.GetDeWebInfoHandler {
40-
return &dewebInfo{miscInfo: miscInfo, networkInfo: networkInfo}
39+
func NewDewebInfo(conf *userConfig.ServerConfig) operations.GetDeWebInfoHandler {
40+
return &dewebInfo{conf}
4141
}
4242

4343
func (dI *dewebInfo) Handle(params operations.GetDeWebInfoParams) middleware.Responder {
@@ -49,12 +49,14 @@ func (dI *dewebInfo) Handle(params operations.GetDeWebInfoParams) middleware.Res
4949
operations.NewGetDeWebInfoOK().WithPayload(&models.DeWebInfo{
5050
App: "deweb",
5151
Version: config.Version,
52-
Misc: dI.miscInfo,
52+
Misc: dI.conf.MiscPublicInfoJson,
5353
Network: &models.DeWebInfoNetwork{
54-
Network: dI.networkInfo.Network,
55-
Version: dI.networkInfo.Version,
56-
ChainID: int64(dI.networkInfo.ChainID),
54+
Network: dI.conf.NetworkInfos.Network,
55+
Version: dI.conf.NetworkInfos.Version,
56+
ChainID: int64(dI.conf.NetworkInfos.ChainID),
5757
},
58+
AllowList: dI.conf.AllowList,
59+
BlockList: dI.conf.BlockList,
5860
}).WriteResponse(w, runtime)
5961
})
6062
}

server/int/api/middlewares.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func SubdomainMiddleware(handler http.Handler, conf *config.ServerConfig) http.H
8282
return
8383
}
8484

85-
if !isWebsiteAllowed(address, subdomain, conf.AllowList, conf.BlockList) {
85+
if !isWebsiteAllowed(address, subdomain, conf) {
8686
logger.Warnf("Subdomain %s or address %s is not allowed", subdomain, address)
8787

8888
localHandler(w, notAvailableZip, path)
@@ -232,13 +232,13 @@ func getWebsiteResource(config *config.ServerConfig, websiteAddress, resourceNam
232232
// isWebsiteAllowed checks the allow and block lists and returns false if the address or domain is not allowed.
233233
// If the allow list is empty, all addresses and domains are allowed, except those in the block list.
234234
// Otherwise, only addresses and domains in the allow list are allowed.
235-
func isWebsiteAllowed(address string, domain string, allowList, blockList []string) bool {
236-
if slices.Contains(blockList, address) || slices.Contains(blockList, domain) {
235+
func isWebsiteAllowed(address string, domain string, config *config.ServerConfig) bool {
236+
if slices.Contains(config.BlockList, address) || slices.Contains(config.BlockList, domain) {
237237
logger.Debugf("Address %s or domain %s is in the block list", address, domain)
238238
return false
239239
}
240240

241-
if len(allowList) > 0 && !slices.Contains(allowList, address) && !slices.Contains(allowList, domain) {
241+
if len(config.AllowList) > 0 && !slices.Contains(config.AllowList, address) && !slices.Contains(config.AllowList, domain) {
242242
logger.Debugf("Address %s or domain %s is not in the allow list", address, domain)
243243
return false
244244
}

0 commit comments

Comments
 (0)