-
Notifications
You must be signed in to change notification settings - Fork 52
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
SLCORE-1032 Wrong token error during sync - [New design] #1187
base: master
Are you sure you want to change the base?
SLCORE-1032 Wrong token error during sync - [New design] #1187
Conversation
0483733
to
84a4ae9
Compare
Quality Gate passedIssues Measures |
75de64c
to
5361898
Compare
86acfa4
to
bffb584
Compare
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some ideas for improvement, but it looks mostly good to me. You could remove [New design] from the PR title and the commit message. And the last thing, I am not sure we should merge this now, we should maybe make sure the notification is implemented on the IDE side?
@@ -47,19 +53,21 @@ | |||
|
|||
@Named | |||
@Singleton | |||
public class ServerApiProvider { | |||
public class ServerApiProvider implements ConnectionManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a strong reason to keep this interface and have a single implementation. Why about keeping only a ConnectionManager
class?
private final URI sonarCloudUri; | ||
|
||
public ServerApiProvider(ConnectionConfigurationRepository connectionRepository, ConnectionAwareHttpClientProvider awareHttpClientProvider, HttpClientProvider httpClientProvider, | ||
SonarCloudActiveEnvironment sonarCloudActiveEnvironment) { | ||
SonarCloudActiveEnvironment sonarCloudActiveEnvironment, SonarLintRpcClient client) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation issue?
} | ||
cacheConnectionIdPerVersion.put(connectionId, version); | ||
} | ||
serverApiProvider.tryGetConnectionWithoutCredentials(connectionId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked a bit more around this use case. In fact, the api/system/status
call is not authenticated. So instead of having a method at the serverApiProvider
level, I would find it more logical that the decision to not use authentication be made in SystemApi
. But this has some impact in other places
* It's not a big problem because we don't use such requests during scheduled sync. | ||
* They are mostly related to setting up the connection or other user-triggered actions. | ||
*/ | ||
ServerApi getTransientConnection(String token, @Nullable String organization, String baseUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this method should be located in ConnectionManager.
As it's "transient" and by definition we won't keep state for it, and it's not (yet) a connection. I think it would simplify a bit the current ServerApiProvider
which has a lot of entrypoints
return lastNotificationTime.plus(WRONG_TOKEN_NOTIFICATION_INTERVAL).isBefore(Instant.now()); | ||
} | ||
|
||
private void notifyClientAboutWrongTokenIfNeeded() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's the responsibility of the ServerConnection
to notify to the client. I would find it more logical to have it in the ConnectionManager
.
return Optional.empty(); | ||
} | ||
return serverApi.get().hotspot().fetch(hotspotKey, cancelMonitor); | ||
return serverApiProvider.withValidConnectionFlatMapOptionalAndReturn(connectionId,api -> api.hotspot().fetch(hotspotKey, cancelMonitor)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this method is a bit long. In fact this makes me wonder if Api
classes should return Optionals at all, maybe they should instead let the errors bubble up?
@@ -137,4 +145,44 @@ private HttpClient getClientFor(EndpointParams params, Either<TokenDto, Username | |||
userPass -> httpClientProvider.getHttpClientWithPreemptiveAuth(userPass.getUsername(), userPass.getPassword())); | |||
} | |||
|
|||
@Override | |||
public ServerConnection getConnectionOrThrow(String connectionId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As shared earlier, I find the surface of methods quite large, so for people not familiar it might be complex to know which one to use. Do you think there is a way to simplify? Maybe we should at least document the different usages
@VisibleForTesting | ||
public Optional<ServerConnection> getValidConnection(String connectionId) { | ||
return tryGetConnection(connectionId).filter(ServerConnection::isValid); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used only in a single test, couldn't we get rid of it and use another method? I mean at least to not have it public and remove the annotation
|
||
@VisibleForTesting | ||
public Optional<ServerConnection> getValidConnection(String connectionId) { | ||
return tryGetConnection(connectionId).filter(ServerConnection::isValid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A last thing, should we log that the connection is invalid? Maybe too noisy?
SLCORE-1032