From 57b7c59929723bd10693567e31f4a03ea77cd878 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 6 Jan 2020 00:16:38 +0300 Subject: [PATCH] Make extra property in the signed textures response to be adjusted --- CHANGELOG.md | 1 + README.md | 16 ++++++++++++++++ cmd/serve.go | 14 ++++++++------ http/skinsystem.go | 16 +++++++++++++--- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51e18fc..752e1c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 which is compatible with [Mojang's endpoint](https://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time) to exchange username to its UUID. It can be used with some load balancing software to increase throughput of Mojang's textures proxy by splitting the load across multiple servers with its own IPs. +- Textures extra param is now can be configured via `TEXTURES_EXTRA_PARAM_NAME` and `TEXTURES_EXTRA_PARAM_VALUE`. - New StatsD metrics: - Counters: diff --git a/README.md b/README.md index 2c9d4f5..680e8dc 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,22 @@ docker-compose up -d app http://remote-provider.com/api/worker/mojang-uuid + + TEXTURES_EXTRA_PARAM_NAME + + Sets the name of the extra property in the + signed textures response. + + your-name + + + TEXTURES_EXTRA_PARAM_VALUE + + Sets the value of the extra property in the + signed textures response. + + your awesome joke! + diff --git a/cmd/serve.go b/cmd/serve.go index 01b7c75..3732e33 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -75,12 +75,14 @@ var serveCmd = &cobra.Command{ logger.Info("Mojang's textures queue is successfully initialized") cfg := &http.Skinsystem{ - ListenSpec: fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port")), - SkinsRepo: skinsRepo, - CapesRepo: capesRepo, - MojangTexturesProvider: mojangTexturesProvider, - Logger: logger, - Auth: &auth.JwtAuth{Key: []byte(viper.GetString("chrly.secret"))}, + ListenSpec: fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port")), + SkinsRepo: skinsRepo, + CapesRepo: capesRepo, + MojangTexturesProvider: mojangTexturesProvider, + Logger: logger, + Auth: &auth.JwtAuth{Key: []byte(viper.GetString("chrly.secret"))}, + TexturesExtraParamName: viper.GetString("textures.extra_param_name"), + TexturesExtraParamValue: viper.GetString("textures.extra_param_value"), } finishChan := make(chan bool) diff --git a/http/skinsystem.go b/http/skinsystem.go index 659db29..86d4b04 100644 --- a/http/skinsystem.go +++ b/http/skinsystem.go @@ -87,7 +87,9 @@ type AuthChecker interface { } type Skinsystem struct { - ListenSpec string + ListenSpec string + TexturesExtraParamName string + TexturesExtraParamValue string SkinsRepo SkinsRepository CapesRepo CapesRepository @@ -304,8 +306,8 @@ func (ctx *Skinsystem) SignedTextures(response http.ResponseWriter, request *htt } responseData.Props = append(responseData.Props, &mojang.Property{ - Name: "chrly", - Value: "how do you tame a horse in Minecraft?", + Name: getStringOrDefault(ctx.TexturesExtraParamName, "chrly"), + Value: getStringOrDefault(ctx.TexturesExtraParamValue, "how do you tame a horse in Minecraft?"), }) responseJson, _ := json.Marshal(responseData) @@ -496,3 +498,11 @@ func findIdentity(repo SkinsRepository, identityId int, username string) (*model func parseUsername(username string) string { return strings.TrimSuffix(username, ".png") } + +func getStringOrDefault(value string, def string) string { + if value != "" { + return value + } + + return def +}