mirror of
https://github.com/elyby/chrly.git
synced 2024-12-23 13:40:11 +05:30
Resolves #13. Add a config param to completely disable Mojang textures provider
This commit is contained in:
parent
03c5a03c73
commit
092ea3d4e2
@ -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`.
|
||||||
|
|
||||||
|
@ -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>
|
||||||
|
@ -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{
|
||||||
|
55
cmd/serve.go
55
cmd/serve.go
@ -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)
|
||||||
}
|
}
|
||||||
|
12
mojangtextures/nil_mojang_textures.go
Normal file
12
mojangtextures/nil_mojang_textures.go
Normal 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
|
||||||
|
}
|
14
mojangtextures/nil_mojang_textures_test.go
Normal file
14
mojangtextures/nil_mojang_textures_test.go
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user