use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class GoogleLoginUsersPanel method initializeUsers.
private int initializeUsers() {
Map<String, CredentialedUser> allUsers = Services.getLoginService().getAllUsers();
listModel = new DefaultListModel<>();
int activeUserIndex = allUsers.size();
for (CredentialedUser user : allUsers.values()) {
listModel.addElement(new UsersListItem(user));
if (user.isActive()) {
activeUserIndex = listModel.getSize() - 1;
}
}
if (listModel.getSize() == 0) {
// Add no user panel
listModel.addElement(NoUsersListItem.INSTANCE);
} else if ((activeUserIndex != 0) && (activeUserIndex < listModel.getSize())) {
// Change order of elements in the list so that the
// active user becomes the first element in the list
UsersListItem activeUser = listModel.remove(activeUserIndex);
listModel.add(0, activeUser);
activeUserIndex = 0;
}
return activeUserIndex;
}
use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class ProjectLoader method loadUserProjects.
private List<Project> loadUserProjects(CredentialedUser user) throws IOException {
CloudResourceManager cloudResourceManagerClient = GoogleApiClientFactory.getInstance().getCloudResourceManagerClient(user.getCredential());
final List<Project> result = new ArrayList<>();
ListProjectsResponse response = cloudResourceManagerClient.projects().list().setPageSize(PROJECTS_MAX_PAGE_SIZE).execute();
if (response != null && response.getProjects() != null) {
// Create a sorted set to sort the projects list by project name.
Set<Project> allProjects = new TreeSet<>(Comparator.comparing(project -> project.getName().toLowerCase()));
allProjects.addAll(response.getProjects());
while (!Strings.isNullOrEmpty(response.getNextPageToken())) {
response = cloudResourceManagerClient.projects().list().setPageToken(response.getNextPageToken()).setPageSize(PROJECTS_MAX_PAGE_SIZE).execute();
allProjects.addAll(response.getProjects());
}
allProjects.stream().filter((project) -> !PROJECT_DELETE_REQUESTED.equals(project.getLifecycleState())).filter((project) -> !Strings.isNullOrEmpty(project.getProjectId())).forEach(result::add);
}
return result;
}
use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class ProjectSelectionDialogTest method mockUserList.
/**
* Mocks list of currently signed in users returned by login service. First user is active.
*/
private void mockUserList(List<CredentialedUser> userList) {
Map<String, CredentialedUser> emailUserMap = userList.stream().collect(Collectors.toMap(CredentialedUser::getEmail, Function.identity()));
when(googleLoginService.getAllUsers()).thenReturn(emailUserMap);
when(googleLoginService.getActiveUser()).thenReturn(userList.get(0));
for (CredentialedUser user : userList) {
when(googleLoginService.ensureLoggedIn(user.getEmail())).thenReturn(true);
when(googleLoginService.getLoggedInUser(user.getEmail())).thenReturn(Optional.of(user));
}
}
use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class ProjectSelector method updateCloudProjectSelection.
private void updateCloudProjectSelection(CloudProject selection) {
projectNameLabel.setHyperlinkText(selection.projectName());
projectAccountSeparatorLabel.setVisible(true);
// first just show account email, then expand with name/picture if this account is signed in.
// if not signed in, hide icon and account name completely and prompt to sign in.
accountInfoLabel.setHyperlinkText(selection.googleUsername());
IntegratedGoogleLoginService loginService = Services.getLoginService();
Optional<CredentialedUser> loggedInUser = loginService.getLoggedInUser(selection.googleUsername());
if (!loggedInUser.isPresent()) {
accountInfoLabel.setHyperlinkText(GoogleCloudCoreMessageBundle.message("cloud.project.selector.not.signed.in", selection.googleUsername()));
} else if (loggedInUser.isPresent()) {
accountInfoLabel.setHyperlinkText(String.format("%s (%s)", Strings.nullToEmpty(loggedInUser.get().getName()), loggedInUser.get().getEmail()));
}
accountInfoLabel.setIcon(loginService.isLoggedIn() ? GoogleLoginIcons.getScaledUserIcon(ACCOUNT_ICON_SIZE, loggedInUser.orElse(null)) : null);
}
use of com.google.cloud.tools.intellij.login.CredentialedUser in project google-cloud-intellij by GoogleCloudPlatform.
the class CloneCloudRepositoryDialog method getCurrentUrlText.
@Nullable
private String getCurrentUrlText() {
CloudProject selectedProject = projectSelector.getSelectedProject();
Optional<CredentialedUser> selectedUser = selectedProject == null ? Optional.empty() : Services.getLoginService().getLoggedInUser(selectedProject.googleUsername());
if (selectedProject == null || !selectedUser.isPresent() || StringUtil.isEmpty(repositorySelector.getText())) {
return null;
}
return GcpHttpAuthDataProvider.getGcpUrl(selectedProject.projectId(), repositorySelector.getText());
}
Aggregations