Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate Limit API Calls issue when building an application #587 #592

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions server/src/dev/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bucket4j:
time: 1
unit: seconds
- cache-name: buckets
url: '/vscode/(?!asset/.*/.*/.*/Microsoft.VisualStudio.Services.Icons.Default).*|/api/(?!(.*/.*/review(/delete)?)|(-/(namespace/create|publish))).*'
url: '/vscode/(?!asset/.*/.*/.*/Microsoft.VisualStudio.Services.Icons.Default).*'
http-response-headers:
Access-Control-Allow-Origin: '*'
Access-Control-Expose-Headers: X-Rate-Limit-Retry-After-Seconds, X-Rate-Limit-Remaining
Expand All @@ -105,7 +105,24 @@ bucket4j:
- capacity: 15
time: 1
unit: seconds

- cache-name: buckets
url: '/api/(?!(.*/.*/review(/delete)?)|(-/(namespace/create|publish))).*'
http-response-headers:
Access-Control-Allow-Origin: '*'
Access-Control-Expose-Headers: X-Rate-Limit-Retry-After-Seconds, X-Rate-Limit-Remaining
rate-limits:
- execute-condition: getParameter("token") != null
expression: getParameter("token")
bandwidths:
- capacity: 15
time: 1
unit: seconds
- execute-condition: getParameter("token") == null
expression: getRemoteAddr()
bandwidths:
- capacity: 15
time: 1
unit: seconds
ovsx:
databasesearch:
enabled: false
Expand Down
18 changes: 10 additions & 8 deletions server/src/main/java/org/eclipse/openvsx/LocalRegistryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,18 @@ private static boolean mismatch(String s1, String s2) {
&& !s1.equalsIgnoreCase(s2);
}

@Transactional(rollbackOn = ErrorResultException.class)
public ResultJson createNamespace(NamespaceJson json, String tokenValue) {
public PersonalAccessToken getAccessToken(String tokenValue) {
var token = users.useAccessToken(tokenValue);
if (token == null) {
throw new ErrorResultException("Invalid access token.");
if (token == null || token.getUser() == null) {
throw new ErrorResultException("Invalid access token.", HttpStatus.UNAUTHORIZED);
}

return token;
}

@Transactional(rollbackOn = ErrorResultException.class)
public ResultJson createNamespace(NamespaceJson json, String tokenValue) {
var token = getAccessToken(tokenValue);
return createNamespace(json, token.getUser());
}

Expand Down Expand Up @@ -465,10 +470,7 @@ public ExtensionJson publish(InputStream content, UserData user) throws ErrorRes

@Transactional(rollbackOn = ErrorResultException.class)
public ExtensionJson publish(InputStream content, String tokenValue) throws ErrorResultException {
var token = users.useAccessToken(tokenValue);
if (token == null || token.getUser() == null) {
throw new ErrorResultException("Invalid access token.");
}
var token = getAccessToken(tokenValue);

// Check whether the user has a valid publisher agreement
eclipse.checkPublisherAgreement(token.getUser());
Expand Down
Loading