use of com.google.api.services.iam.v1.model.ListServiceAccountsResponse in project cloudbreak by hortonworks.
the class GcpPlatformResources method accessConfigs.
@Override
public CloudAccessConfigs accessConfigs(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters) {
Iam iam = gcpIamFactory.buildIam(cloudCredential);
String projectId = gcpStackUtil.getProjectId(cloudCredential);
Set<CloudAccessConfig> collect = new HashSet<>();
try {
Iam.Projects.ServiceAccounts.List listServiceAccountEmailsRequest = iam.projects().serviceAccounts().list("projects/" + projectId).setPageSize(DEFAULT_PAGE_SIZE);
ListServiceAccountsResponse response;
do {
response = listServiceAccountEmailsRequest.execute();
Set<CloudAccessConfig> accessConfigs = response.getAccounts().stream().map(e -> new CloudAccessConfig(e.getName(), e.getEmail(), new HashMap<>())).collect(Collectors.toSet());
collect.addAll(accessConfigs);
listServiceAccountEmailsRequest.setPageToken(response.getNextPageToken());
} while (response.getNextPageToken() != null);
return new CloudAccessConfigs(collect);
} catch (Exception ex) {
return new CloudAccessConfigs(collect);
}
}
use of com.google.api.services.iam.v1.model.ListServiceAccountsResponse in project platinum by hartwigmedical.
the class EphemeralPipelineServiceAccountTest method setUp.
@Before
public void setUp() throws Exception {
final Iam iam = mock(Iam.class);
Iam.Projects projects = mock(Iam.Projects.class);
serviceAccounts = mock(Iam.Projects.ServiceAccounts.class);
Iam.Projects.ServiceAccounts.List listServiceAccounts = mock(Iam.Projects.ServiceAccounts.List.class);
listServiceAccountsResponse = mock(ListServiceAccountsResponse.class);
when(iam.projects()).thenReturn(projects);
when(projects.serviceAccounts()).thenReturn(serviceAccounts);
when(serviceAccounts.list(PROJECT_RESOURCE_NAME)).thenReturn(listServiceAccounts);
when(listServiceAccounts.execute()).thenReturn(listServiceAccountsResponse);
Iam.Projects.ServiceAccounts.Create create = mock(Iam.Projects.ServiceAccounts.Create.class);
serviceAccount = mock(ServiceAccount.class);
projectArgumentCaptor = ArgumentCaptor.forClass(String.class);
createServiceAccountRequestArgumentCaptor = ArgumentCaptor.forClass(CreateServiceAccountRequest.class);
when(create.execute()).thenReturn(serviceAccount);
when(serviceAccounts.create(projectArgumentCaptor.capture(), createServiceAccountRequestArgumentCaptor.capture())).thenReturn(create);
when(serviceAccount.getEmail()).thenReturn(EMAIL);
iamPolicy = mock(PipelineIamPolicy.class);
victim = new EphemeralPipelineServiceAccount(iam, iamPolicy, RUN_NAME, PROJECT);
}
use of com.google.api.services.iam.v1.model.ListServiceAccountsResponse in project java-docs-samples by GoogleCloudPlatform.
the class ListServiceAccounts method listServiceAccounts.
// Lists all service accounts for the current project.
public static void listServiceAccounts(String projectId) {
// String projectId = "my-project-id"
Iam service = null;
try {
service = initService();
} catch (IOException | GeneralSecurityException e) {
System.out.println("Unable to initialize service: \n" + e.toString());
return;
}
try {
ListServiceAccountsResponse response = service.projects().serviceAccounts().list("projects/" + projectId).execute();
List<ServiceAccount> serviceAccounts = response.getAccounts();
for (ServiceAccount account : serviceAccounts) {
System.out.println("Name: " + account.getName());
System.out.println("Display Name: " + account.getDisplayName());
System.out.println("Email: " + account.getEmail());
System.out.println();
}
} catch (IOException e) {
System.out.println("Unable to list service accounts: \n" + e.toString());
}
}
use of com.google.api.services.iam.v1.model.ListServiceAccountsResponse in project cloudbreak by hortonworks.
the class GcpServiceAccountObjectStorageValidator method validateObjectStorage.
public ValidationResultBuilder validateObjectStorage(CloudCredential cloudCredential, SpiFileSystem spiFileSystem, ValidationResultBuilder resultBuilder) throws IOException {
LOGGER.info("Validating Gcp identities...");
Iam iam = gcpIamFactory.buildIam(cloudCredential);
List<CloudFileSystemView> cloudFileSystems = spiFileSystem.getCloudFileSystems();
if (Objects.nonNull(cloudFileSystems) && cloudFileSystems.size() > 0) {
String projectId = gcpStackUtil.getProjectId(cloudCredential);
Set<String> serviceAccountEmailsToFind = cloudFileSystems.stream().map(cloudFileSystemView -> ((CloudGcsView) cloudFileSystemView).getServiceAccountEmail()).collect(Collectors.toSet());
Iam.Projects.ServiceAccounts.List listServiceAccountEmailsRequest = iam.projects().serviceAccounts().list("projects/" + projectId).setPageSize(DEFAULT_PAGE_SIZE);
ListServiceAccountsResponse response;
do {
response = listServiceAccountEmailsRequest.execute();
response.getAccounts().forEach(serviceAccount -> serviceAccountEmailsToFind.remove(serviceAccount.getEmail()));
listServiceAccountEmailsRequest.setPageToken(response.getNextPageToken());
} while (response.getNextPageToken() != null && !serviceAccountEmailsToFind.isEmpty());
if (!serviceAccountEmailsToFind.isEmpty()) {
addError(resultBuilder, String.format("Service Account with email(s) '%s' could not be found in the configured Google Cloud project '%s'.", String.join(", ", serviceAccountEmailsToFind), projectId));
}
}
return resultBuilder;
}
use of com.google.api.services.iam.v1.model.ListServiceAccountsResponse in project platinum by hartwigmedical.
the class EphemeralPipelineServiceAccount method projectServiceAccounts.
private static List<ServiceAccount> projectServiceAccounts(final Iam iam, final String projectResourceName) throws IOException {
ListServiceAccountsResponse response = iam.projects().serviceAccounts().list(projectResourceName).execute();
List<ServiceAccount> accounts = response.getAccounts();
while (response.getNextPageToken() != null) {
response = iam.projects().serviceAccounts().list(projectResourceName).setPageSize(100).setPageToken(response.getNextPageToken()).execute();
if (response.getAccounts() != null) {
accounts.addAll(response.getAccounts());
}
}
return accounts;
}
Aggregations