Skip to content

Commit

Permalink
Refactor API key permission verification and add wvw as required perm…
Browse files Browse the repository at this point in the history
…ission
  • Loading branch information
vennekilde committed Jul 20, 2024
1 parent d1b9476 commit 5c1dd53
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pkg/sync/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5c1dd53

Please sign in to comment.