From 5c1dd53ead6b8a688488e48a712a92cf071ca3ef Mon Sep 17 00:00:00 2001 From: Vennekilde Date: Sat, 20 Jul 2024 19:02:23 +0200 Subject: [PATCH] Refactor API key permission verification and add wvw as required permission --- pkg/sync/verify.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pkg/sync/verify.go b/pkg/sync/verify.go index 2c736d4..7d47653 100644 --- a/pkg/sync/verify.go +++ b/pkg/sync/verify.go @@ -154,20 +154,18 @@ func (s *Service) processAPIKeyRestrictions(worldPerspective *int, acc gw2api.Ac return fmt.Errorf("APIKey name incorrect. You need to name your api key \"%s\" instead of \"%s\"", verify.GetAPIKeyName(worldPerspective, platformID, platformUserID), token.Name) } - //freeToPlay := IsFreeToPlay(acc) - - //FreeToPlay restrictions - //if freeToPlay { - //Ensure progression permission is present - hasProgression := Contains(token.Permissions, "progression") - - //Ensure characters permission is present - hasCharacters := Contains(token.Permissions, "characters") + //Check if api key has the correct permissions + requiredPermissions := []string{"progression", "characters", "wvw"} + missingPermissions := make([]string, 0, 3) + for _, perm := range requiredPermissions { + if !Contains(token.Permissions, perm) { + missingPermissions = append(missingPermissions, perm) + } + } - if !hasProgression || !hasCharacters { - return errors.New("missing apikey permission \"characters\" and/or \"progression\"") + if len(missingPermissions) > 0 { + return fmt.Errorf("missing apikey permission(s) %s. Please create a new api key with the following permissions enabled: %s", strings.Join(missingPermissions, ", "), strings.Join(requiredPermissions, ", ")) } - //} return err }