Resolves #13. Add a config param to completely disable Mojang textures provider

This commit is contained in:
ErickSkrauch 2020-04-06 17:15:40 +03:00
parent 03c5a03c73
commit 092ea3d4e2
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
6 changed files with 67 additions and 25 deletions

View File

@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] - xxxx-xx-xx ## [Unreleased] - xxxx-xx-xx
### Added ### Added
- Mojang textures queue now can be completely disabled via `MOJANG_TEXTURES_ENABLED` param.
- Remote mode for Mojang's textures queue with a new configuration params: `MOJANG_TEXTURES_UUIDS_PROVIDER_DRIVER` and - Remote mode for Mojang's textures queue with a new configuration params: `MOJANG_TEXTURES_UUIDS_PROVIDER_DRIVER` and
`MOJANG_TEXTURES_UUIDS_PROVIDER_URL`. `MOJANG_TEXTURES_UUIDS_PROVIDER_URL`.

View File

@ -113,6 +113,13 @@ docker-compose up -d app
</td> </td>
<td><code>10</code></td> <td><code>10</code></td>
</tr> </tr>
<tr>
<td>MOJANG_TEXTURES_ENABLED</td>
<td>
Allows to completely disable Mojang textures provider for unknown usernames. Enabled by default.
</td>
<td><code>true</code></td>
</tr>
<tr> <tr>
<td>MOJANG_TEXTURES_UUIDS_PROVIDER_DRIVER</td> <td>MOJANG_TEXTURES_UUIDS_PROVIDER_DRIVER</td>
<td> <td>

View File

@ -1,6 +1,7 @@
package bootstrap package bootstrap
import ( import (
"fmt"
"net/url" "net/url"
"os" "os"
"time" "time"
@ -79,7 +80,7 @@ func CreateMojangUUIDsProvider(emitter http.Emitter) (mojangtextures.UUIDsProvid
if preferredUuidsProvider == "remote" { if preferredUuidsProvider == "remote" {
remoteUrl, err := url.Parse(viper.GetString("mojang_textures.uuids_provider.url")) remoteUrl, err := url.Parse(viper.GetString("mojang_textures.uuids_provider.url"))
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("Unable to parse remote url: %w", err)
} }
uuidsProvider = &mojangtextures.RemoteApiUuidsProvider{ uuidsProvider = &mojangtextures.RemoteApiUuidsProvider{

View File

@ -62,33 +62,39 @@ var serveCmd = &cobra.Command{
} }
logger.Info("Capes repository successfully initialized") logger.Info("Capes repository successfully initialized")
logger.Info("Preparing Mojang's textures queue") var mojangTexturesProvider http.MojangTexturesProvider
mojangUuidsRepository, err := redisFactory.CreateMojangUuidsRepository() if viper.GetBool("mojang_textures.enabled") {
if err != nil { logger.Info("Preparing Mojang's textures queue")
logger.Emergency("Error on creating mojang uuids repo: :err", wd.ErrParam(err)) mojangUuidsRepository, err := redisFactory.CreateMojangUuidsRepository()
os.Exit(1) if err != nil {
} logger.Emergency("Error on creating mojang uuids repo: :err", wd.ErrParam(err))
os.Exit(1)
}
uuidsProvider, err := bootstrap.CreateMojangUUIDsProvider(dispatcher) uuidsProvider, err := bootstrap.CreateMojangUUIDsProvider(dispatcher)
if err != nil { if err != nil {
logger.Emergency("Unable to parse remote url :err", wd.ErrParam(err)) logger.Emergency("Unable to create mojang uuids provider: :err", wd.ErrParam(err))
os.Exit(1) os.Exit(1)
} }
texturesStorage := mojangtextures.NewInMemoryTexturesStorage() texturesStorage := mojangtextures.NewInMemoryTexturesStorage()
texturesStorage.Start() texturesStorage.Start()
mojangTexturesProvider := &mojangtextures.Provider{ mojangTexturesProvider = &mojangtextures.Provider{
Emitter: dispatcher, Emitter: dispatcher,
UUIDsProvider: uuidsProvider, UUIDsProvider: uuidsProvider,
TexturesProvider: &mojangtextures.MojangApiTexturesProvider{ TexturesProvider: &mojangtextures.MojangApiTexturesProvider{
Emitter: dispatcher, Emitter: dispatcher,
}, },
Storage: &mojangtextures.SeparatedStorage{ Storage: &mojangtextures.SeparatedStorage{
UuidsStorage: mojangUuidsRepository, UuidsStorage: mojangUuidsRepository,
TexturesStorage: texturesStorage, TexturesStorage: texturesStorage,
}, },
}
logger.Info("Mojang's textures queue is successfully initialized")
} else {
logger.Info("Mojang's textures queue is disabled")
mojangTexturesProvider = &mojangtextures.NilProvider{}
} }
logger.Info("Mojang's textures queue is successfully initialized")
address := fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port")) address := fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port"))
handler := (&http.Skinsystem{ handler := (&http.Skinsystem{
@ -129,4 +135,5 @@ func init() {
viper.SetDefault("storage.redis.poll", 10) viper.SetDefault("storage.redis.poll", 10)
viper.SetDefault("storage.filesystem.basePath", "data") viper.SetDefault("storage.filesystem.basePath", "data")
viper.SetDefault("storage.filesystem.capesDirName", "capes") viper.SetDefault("storage.filesystem.capesDirName", "capes")
viper.SetDefault("mojang_textures.enabled", true)
} }

View File

@ -0,0 +1,12 @@
package mojangtextures
import (
"github.com/elyby/chrly/api/mojang"
)
type NilProvider struct {
}
func (p *NilProvider) GetForUsername(username string) (*mojang.SignedTexturesResponse, error) {
return nil, nil
}

View File

@ -0,0 +1,14 @@
package mojangtextures
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNilProvider_GetForUsername(t *testing.T) {
provider := &NilProvider{}
result, err := provider.GetForUsername("username")
assert.Nil(t, result)
assert.Nil(t, err)
}