Skip to content

Commit

Permalink
fix: api docs and wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
haveachin committed Feb 1, 2023
1 parent e3186e3 commit 26f5ee4
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 636 deletions.
19 changes: 18 additions & 1 deletion configs/plugins/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,21 @@ api:
#
allowedOrigins:
- "http://*"
- "https://*"
- "https://*"

# Sets this in the allowed methods header
#
allowedMethods:
- GET
- POST
- PUT
- DELETE
- OPTIONS

# Sets this in the allowed headers header
#
allowedHeaders:
- Accept
- Content-Type
- Authorization
- X-CSRF-Token
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/df-mc/atomic v1.10.0
github.com/docker/docker v20.10.20+incompatible
github.com/fsnotify/fsnotify v1.6.0
github.com/gertd/wild v0.0.1
github.com/go-chi/chi/v5 v5.0.7
github.com/go-chi/cors v1.2.1
github.com/go-chi/render v1.0.2
Expand Down
36 changes: 36 additions & 0 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions internal/app/infrared/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net"
"sync"

"github.com/gertd/wild"
"github.com/haveachin/infrared/pkg/event"
"github.com/haveachin/infrared/pkg/wildcard"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -77,7 +77,7 @@ func (sg *ServerGateway) compileDomainExprs() {
func (sg *ServerGateway) findServer(gatewayID, domain string) (Server, string) {
for _, srvID := range sg.gwIDSrvIDs[gatewayID] {
for _, srvExpr := range sg.srvExprs[srvID] {
if wildcard.Match(srvExpr, domain) {
if wild.Match(srvExpr, domain, true) {
return sg.srvs[srvID], srvExpr
}
}
Expand All @@ -103,7 +103,7 @@ func (sg *ServerGateway) Start() {
logger := sg.Logger.With(logProcessedConn(player)...)
logger.Debug("looking up server address")

srv, matchedDomain := sg.findServer(player.GatewayID(), player.MatchedAddr())
srv, matchedDomain := sg.findServer(player.GatewayID(), player.RequestedAddr())
if srv == nil {
logger.Info("failed to find server; disconnecting client")
_ = player.DisconnectServerNotFound()
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/java/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ type ServerConfig struct {
SendProxyProtocol bool `mapstructure:"sendProxyProtocol"`
SendRealIP bool `mapstructure:"sendRealIP"`
OverrideAddress bool `mapstructure:"overrideAddress"`
DialTimeout time.Duration `mapstructure:"dialTimeout"`
DialTimeout time.Duration `mapstructure:"dialTimeout" swaggertype:"primitive,string"`
DialTimeoutMessage string `mapstructure:"dialTimeoutMessage"`
OverrideStatus OverrideServerStatusConfig `mapstructure:"overrideStatus"`
DialTimeoutStatus ServerStatusConfig `mapstructure:"dialTimeoutStatus"`
Gateways []string `mapstructure:"gateways"`
StatusCacheTTL time.Duration `mapstructure:"statusCacheTTL"`
StatusCacheTTL time.Duration `mapstructure:"statusCacheTTL" swaggertype:"primitive,string"`
}

type OverrideServerStatusConfig struct {
Expand Down Expand Up @@ -74,7 +74,7 @@ type GatewayConfig struct {

type ConnProcessorConfig struct {
Count int `mapstructure:"count"`
ClientTimeout time.Duration `mapstructure:"clientTimeout"`
ClientTimeout time.Duration `mapstructure:"clientTimeout" swaggertype:"primitive,string"`
}

type ChanCapsConfig struct {
Expand All @@ -90,7 +90,7 @@ type MiddlewareSettings struct {
type RateLimiterSettings struct {
Enable bool `mapstructure:"enable"`
RequestLimit int `mapstructure:"requestLimit"`
WindowLength time.Duration `mapstructure:"windowLength"`
WindowLength time.Duration `mapstructure:"windowLength" swaggertype:"primitive,string"`
}

type ProxyConfig struct {
Expand Down
6 changes: 4 additions & 2 deletions internal/plugin/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type PluginConfig struct {
Enable bool `mapstructure:"enable"`
Bind string `mapstructure:"bind"`
AllowedOrigins []string `mapstructure:"allowedOrigins"`
AllowedMethods []string `mapstructure:"allowedMethods"`
AllowedHeaders []string `mapstructure:"allowedHeaders"`
} `mapstructure:"api"`
}

Expand Down Expand Up @@ -136,8 +138,8 @@ func (p Plugin) router() http.Handler {
r.Use(middleware.Recoverer)
r.Use(cors.Handler(cors.Options{
AllowedOrigins: p.Config.API.AllowedOrigins,
AllowedMethods: []string{"GET", "DELETE"},
AllowedHeaders: []string{"Accept", "Content-Type"},
AllowedMethods: p.Config.API.AllowedMethods,
AllowedHeaders: p.Config.API.AllowedHeaders,
AllowCredentials: false,
}))

Expand Down
6 changes: 4 additions & 2 deletions internal/plugin/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@ func getConfigs(cfg config.Config) http.HandlerFunc {
// @Summary Create/Update a config
// @Description Create/Update a config via ID
// @Tags Config
// @Accept json
// @Produce json
// @Param configId path string true "Config ID"
// @Success 201 {string} string "See the documentation or configs folder for more info on this complex struct"
// @Param request body map[string]any true "Config"
// @Param configId path string true "Config ID"
// @Success 201 {string} string "See the documentation or configs folder for more info on this complex struct"
// @Failure 400 {object} api.errorDTO
// @Failure 500 {object} api.errorDTO
// @Router /configs/{configId} [put]
Expand Down
69 changes: 0 additions & 69 deletions pkg/wildcard/match.go

This file was deleted.

Loading

0 comments on commit 26f5ee4

Please sign in to comment.