Skip to content

Commit

Permalink
Remove or change print statement to log statements (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
taldekar authored Nov 21, 2024
1 parent e413706 commit 8f3edeb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

package software.aws.toolkits.eclipse.amazonq.util;

import org.eclipse.ui.services.IDisposable;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.ui.services.IDisposable;

// TODO: May use it later
class QResource implements IDisposable {
private final List<QResource> children = new ArrayList<>();
Expand All @@ -28,7 +28,6 @@ public void dispose() {
child.dispose();
}
// Add actual resource disposal logic here
System.out.println("Resource disposed");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

import java.util.concurrent.Future;
import java.util.stream.Collectors;

import org.eclipse.swt.browser.Browser;

import software.amazon.awssdk.regions.servicemetadata.OidcServiceMetadata;
import software.amazon.awssdk.utils.StringUtils;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.LoginIdcParams;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.LoginParams;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.LoginType;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.util.AwsRegion;
import software.aws.toolkits.eclipse.amazonq.util.JsonHandler;
import software.aws.toolkits.eclipse.amazonq.util.ThemeDetector;
import software.aws.toolkits.eclipse.amazonq.plugin.Activator;
import software.aws.toolkits.eclipse.amazonq.util.ThreadingUtils;
import software.aws.toolkits.eclipse.amazonq.views.model.Command;
import software.aws.toolkits.eclipse.amazonq.views.model.ParsedCommand;
Expand All @@ -30,68 +32,68 @@ public class LoginViewActionHandler implements ViewActionHandler {
public final void handleCommand(final ParsedCommand parsedCommand, final Browser browser) {
Object params = parsedCommand.getParams();
switch (parsedCommand.getCommand()) {
case LOGIN_BUILDER_ID:
case LOGIN_IDC:
if (isLoginTaskRunning) {
loginTask.cancel(true);
}
isLoginTaskRunning = true;
loginTask = ThreadingUtils.executeAsyncTaskAndReturnFuture(() -> {
try {
if (parsedCommand.getCommand() == Command.LOGIN_BUILDER_ID) {
Activator.getLoginService().login(LoginType.BUILDER_ID, new LoginParams()).get();
} else {
LoginIdcParams loginIdcParams = JSON_HANDLER.convertObject(params, LoginIdcParams.class);
var url = loginIdcParams.getUrl();
var region = loginIdcParams.getRegion();
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(region)) {
throw new IllegalArgumentException("Url/Region parameters cannot be null or empty");
}
Activator.getLoginService().login(LoginType.IAM_IDENTITY_CENTER,
new LoginParams().setLoginIdcParams(loginIdcParams)).get();
case LOGIN_BUILDER_ID:
case LOGIN_IDC:
if (isLoginTaskRunning) {
loginTask.cancel(true);
}
isLoginTaskRunning = true;
loginTask = ThreadingUtils.executeAsyncTaskAndReturnFuture(() -> {
try {
if (parsedCommand.getCommand() == Command.LOGIN_BUILDER_ID) {
Activator.getLoginService().login(LoginType.BUILDER_ID, new LoginParams()).get();
} else {
LoginIdcParams loginIdcParams = JSON_HANDLER.convertObject(params, LoginIdcParams.class);
var url = loginIdcParams.getUrl();
var region = loginIdcParams.getRegion();
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(region)) {
throw new IllegalArgumentException("Url/Region parameters cannot be null or empty");
}
isLoginTaskRunning = false;
} catch (Exception e) {
isLoginTaskRunning = false;
Activator.getLogger().error("Failed to update token", e);
Activator.getLoginService().login(LoginType.IAM_IDENTITY_CENTER,
new LoginParams().setLoginIdcParams(loginIdcParams)).get();
}
});
break;
case CANCEL_LOGIN:
if (isLoginTaskRunning) {
loginTask.cancel(true);
isLoginTaskRunning = false;
} catch (Exception e) {
isLoginTaskRunning = false;
Activator.getLogger().error("Failed to update token", e);
}
break;
case ON_LOAD:
OidcServiceMetadata oidcMetadata = new OidcServiceMetadata();
String regions = "[" + oidcMetadata.regions().stream()
.filter(region -> region.metadata().partition().id().equals("aws"))
.map(AwsRegion::from)
.map(AwsRegion::toString)
.collect(Collectors.joining(",")) + "]";
var js = String.format("""
{
stage: '%s',
regions: %s,
cancellable: false,
idcInfo: {
profileName: '',
startUrl: '',
region: 'us-east-1'
},
feature: 'q',
existConnections: []
}
""", "START", regions).stripIndent();
browser.execute("changeTheme(" + THEME_DETECTOR.isDarkTheme() + ");");
browser.execute(String.format("ideClient.prepareUi(%s)", js));
browser.execute("ideClient.updateAuthorization('')");
browser.execute("document.oncontextmenu = e => e.preventDefault();");
break;
default:
System.out.println("Unexpected command received from Amazon Q Login: " + parsedCommand.getCommand());
break;
});
break;
case CANCEL_LOGIN:
if (isLoginTaskRunning) {
loginTask.cancel(true);
isLoginTaskRunning = false;
}
break;
case ON_LOAD:
OidcServiceMetadata oidcMetadata = new OidcServiceMetadata();
String regions = "["
+ oidcMetadata.regions().stream().filter(region -> region.metadata().partition().id().equals("aws"))
.map(AwsRegion::from).map(AwsRegion::toString).collect(Collectors.joining(","))
+ "]";
var js = String.format("""
{
stage: '%s',
regions: %s,
cancellable: false,
idcInfo: {
profileName: '',
startUrl: '',
region: 'us-east-1'
},
feature: 'q',
existConnections: []
}
""", "START", regions).stripIndent();
browser.execute("changeTheme(" + THEME_DETECTOR.isDarkTheme() + ");");
browser.execute(String.format("ideClient.prepareUi(%s)", js));
browser.execute("ideClient.updateAuthorization('')");
browser.execute("document.oncontextmenu = e => e.preventDefault();");
break;
default:
Activator.getLogger()
.error("Unexpected command received from Amazon Q Login: " + parsedCommand.getCommand());
break;
}
}
}

0 comments on commit 8f3edeb

Please sign in to comment.