Search in sources :

Example 11 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project synopsys-detect by blackducksoftware.

the class CreateBdio2FilesOperation method createBdioFiles.

public List<UploadTarget> createBdioFiles(BdioCodeLocationResult bdioCodeLocationResult, File outputDirectory, NameVersion projectNameVersion) throws DetectUserFriendlyException {
    List<UploadTarget> uploadTargets = new ArrayList<>();
    for (BdioCodeLocation bdioCodeLocation : bdioCodeLocationResult.getBdioCodeLocations()) {
        String codeLocationName = bdioCodeLocation.getCodeLocationName();
        ExternalId externalId = bdioCodeLocation.getDetectCodeLocation().getExternalId();
        DependencyGraph dependencyGraph = bdioCodeLocation.getDetectCodeLocation().getDependencyGraph();
        // Bdio 2
        String detectVersion = detectInfo.getDetectVersion();
        SpdxCreator detectCreator = SpdxCreator.createToolSpdxCreator("Detect", detectVersion);
        BdioMetadata bdioMetadata = bdio2Factory.createBdioMetadata(codeLocationName, ZonedDateTime.now(), new Product.Builder().name(detectCreator.getIdentifier()).build());
        bdioMetadata.scanType(Bdio.ScanType.PACKAGE_MANAGER);
        Project bdio2Project = bdio2Factory.createProject(externalId, projectNameVersion.getName(), projectNameVersion.getVersion(), true);
        Bdio2Document bdio2Document = bdio2Factory.createBdio2Document(bdioMetadata, bdio2Project, dependencyGraph);
        Bdio2Writer bdio2Writer = new Bdio2Writer();
        File bdio2OutputFile = new File(outputDirectory, bdioCodeLocation.getBdioName() + ".bdio");
        try {
            OutputStream outputStream = new FileOutputStream(bdio2OutputFile);
            bdio2Writer.writeBdioDocument(outputStream, bdio2Document);
            logger.debug(String.format("BDIO Generated: %s", bdio2OutputFile.getAbsolutePath()));
            uploadTargets.add(UploadTarget.createDefault(projectNameVersion, codeLocationName, bdio2OutputFile));
        } catch (IOException e) {
            throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
        }
    }
    return uploadTargets;
}
Also used : BdioMetadata(com.blackducksoftware.bdio2.BdioMetadata) Bdio2Writer(com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) Product(com.blackducksoftware.common.value.Product) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException) SpdxCreator(com.synopsys.integration.bdio.model.SpdxCreator) BdioCodeLocation(com.synopsys.integration.detect.workflow.codelocation.BdioCodeLocation) Project(com.blackducksoftware.bdio2.model.Project) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 12 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-cloud-resource-lib by DataBiosphere.

the class IamCowTest method createIamPreparedProject.

/**
 * Create Project then set billing account, enable IAM api
 */
private static Project createIamPreparedProject() throws Exception {
    Project project = ProjectUtils.executeCreateProject();
    CloudBillingUtils.setDefaultProjectBilling(project.getProjectId());
    ServiceUsageUtils.enableServices(project.getProjectId(), ImmutableList.of("iam.googleapis.com"));
    return project;
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project)

Example 13 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-cloud-resource-lib by DataBiosphere.

the class ServiceUsageCowTest method listAndEnableServices.

@Test
public void listAndEnableServices() throws Exception {
    ServiceUsageCow serviceUsage = defaultServiceUsage();
    Project project = ProjectUtils.executeCreateProject();
    String projectName = projectIdToName(project.getProjectId());
    String storageServiceName = serviceName(project, STORAGE_SERVICE_ID);
    ListServicesResponse response1 = serviceUsage.services().list(projectName).setFilter(ENABLED_FILTER).execute();
    assertNull(response1.getServices());
    Operation operation = serviceUsage.services().batchEnable(projectName, new BatchEnableServicesRequest().setServiceIds(ImmutableList.of(STORAGE_SERVICE_ID))).execute();
    OperationTestUtils.pollAndAssertSuccess(serviceUsage.operations().operationCow(operation), Duration.ofSeconds(5), Duration.ofSeconds(60));
    ListServicesResponse response2 = serviceUsage.services().list(projectName).setFilter(ENABLED_FILTER).execute();
    List<String> services2 = response2.getServices().stream().map(GoogleApiServiceusageV1Service::getName).collect(Collectors.toList());
    assertThat(services2, Matchers.hasItem(storageServiceName));
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ListServicesResponse(com.google.api.services.serviceusage.v1.model.ListServicesResponse) Operation(com.google.api.services.serviceusage.v1.model.Operation) BatchEnableServicesRequest(com.google.api.services.serviceusage.v1.model.BatchEnableServicesRequest) Test(org.junit.jupiter.api.Test)

Example 14 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-cloud-resource-lib by DataBiosphere.

the class DnsCowTest method createAndGetZone.

@Test
public void createAndGetZone() throws Exception {
    Project project = ProjectUtils.executeCreateProject();
    String projectId = project.getProjectId();
    CloudBillingUtils.setDefaultProjectBilling(projectId);
    ServiceUsageUtils.enableServices(projectId, SERVICE_IDS);
    DnsCow dnsCow = defaultDns();
    String zoneName = "zone-name";
    String dnsName = "googleapis.com.";
    String visibility = "private";
    ManagedZone managedZone = new ManagedZone().setName(zoneName).setDnsName(dnsName).setVisibility(visibility).setDescription("description");
    dnsCow.managedZones().create(project.getProjectId(), managedZone).execute();
    ManagedZone createdManagedZone = dnsCow.managedZones().get(projectId, zoneName).execute();
    assertEquals(dnsName, createdManagedZone.getDnsName());
    assertEquals(zoneName, createdManagedZone.getName());
    assertEquals(visibility, createdManagedZone.getVisibility());
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ManagedZone(com.google.api.services.dns.model.ManagedZone) Test(org.junit.jupiter.api.Test)

Example 15 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_createsConsumerOverride.

@Test
public void testCreateGoogleProject_createsConsumerOverride() throws Exception {
    FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(LatchBeforeAssertResourceStep.class), stairwayComponent, transactionTemplate);
    GcpProjectConfig gcpProjectConfig = newBasicGcpConfig().serviceUsage(new ServiceUsage().bigQuery(new BigQueryQuotas().overrideBigQueryDailyUsageQuota(true).bigQueryDailyUsageQuotaOverrideValueMebibytes(new BigDecimal(CONSUMER_QUOTA_OVERRIDE_VALUE_MEBIBYTES))));
    Pool pool = preparePool(bufferDao, gcpProjectConfig);
    String flightId = manager.submitCreationFlight(pool).orElseThrow();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    String projectNumber = getProjectNumberFromName(project.getName());
    String parent = String.format("projects/%s/services/bigquery.googleapis.com/consumerQuotaMetrics/" + "bigquery.googleapis.com%%2Fquota%%2Fquery%%2Fusage/limits/%%2Fd%%2Fproject", projectNumber);
    ServiceUsageCow.Services.ConsumerQuotaMetrics.Limits.ConsumerOverrides.List list = serviceUsageCow.services().consumerQuotaMetrics().limits().consumerOverrides().list(parent);
    ListConsumerOverridesResponse response = list.execute();
    assertEquals(1, response.getOverrides().size(), "single override expected");
    QuotaOverride quotaOverride = response.getOverrides().get(0);
    assertEquals(CONSUMER_QUOTA_OVERRIDE_VALUE_MEBIBYTES, quotaOverride.getOverrideValue());
}
Also used : ListConsumerOverridesResponse(com.google.api.services.serviceusage.v1beta1.model.ListConsumerOverridesResponse) FlightManager(bio.terra.buffer.service.resource.FlightManager) StubSubmissionFlightFactory(bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory) BigDecimal(java.math.BigDecimal) Project(com.google.api.services.cloudresourcemanager.v3.model.Project) QuotaOverride(com.google.api.services.serviceusage.v1beta1.model.QuotaOverride) ResourceId(bio.terra.buffer.common.ResourceId) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) ServiceUsageCow(bio.terra.cloudres.google.serviceusage.ServiceUsageCow) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Aggregations

Project (com.google.api.services.cloudresourcemanager.v3.model.Project)37 Test (org.junit.jupiter.api.Test)29 BaseIntegrationTest (bio.terra.buffer.common.BaseIntegrationTest)15 Pool (bio.terra.buffer.common.Pool)15 ResourceId (bio.terra.buffer.common.ResourceId)15 IntegrationUtils.preparePool (bio.terra.buffer.integration.IntegrationUtils.preparePool)15 FlightManager (bio.terra.buffer.service.resource.FlightManager)15 IOException (java.io.IOException)14 Binding (com.google.api.services.cloudresourcemanager.v3.model.Binding)10 StepStatus (bio.terra.stairway.StepStatus)9 ArrayList (java.util.ArrayList)9 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)8 List (java.util.List)8 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)8 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)7 FlightState (bio.terra.stairway.FlightState)7 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)7 Project (com.blackducksoftware.bdio2.model.Project)7 GetIamPolicyRequest (com.google.api.services.cloudresourcemanager.v3.model.GetIamPolicyRequest)7 FlightMap (bio.terra.stairway.FlightMap)6