Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,28 +174,38 @@ private static void addCitToApp(CertificateIssuingTemplate cit, Application appl
application.certificateIssuingTemplateAliasIdMap( citAliasIdMap );
}

boolean updateApplication = false;

//if the App doesn't contain the relation to the cit
if ( !citAliasIdMap.containsKey(cit.name()) ) {
//adding the reference to the cit
citAliasIdMap.put(cit.name(), cit.id());
updateApplication = true;
}

//getting the appId because it will be used to invoke the API to update the related Application
String appId = application.id();
// Updating the owners list of the Application
List<Application.OwnerIdsAndType> ownersList = CloudConnectorUtils.resolveUsersToCloudOwners(usersList, apiKey, cloud);
Comment thread
marcos-albornoz marked this conversation as resolved.
if (ownersList.size() > 0){
// application.ownerIdsAndTypes().addAll(ownersList);
List<Application.OwnerIdsAndType> newList = mergeOwnersList(application.ownerIdsAndTypes(), ownersList);
application.ownerIdsAndTypes(newList);
updateApplication = true;
}

//The id, companyId, fqDns and internalFqDns needs to be null in the request to update the Application,
//therefore these attributes are set to null
application.id(null);
application.companyId(null);
application.fqDns(null);
application.internalFqDns(null);
if (updateApplication) {
//getting the appId because it will be used to invoke the API to update the related Application
String appId = application.id();

// Updating the owners list
List<Application.OwnerIdsAndType> ownersList = CloudConnectorUtils.resolveUsersToCloudOwners(usersList, apiKey, cloud);
application.ownerIdsAndTypes(ownersList);
//The id, companyId, fqDns and internalFqDns needs to be null in the request to update the Application,
//therefore these attributes are set to null
application.id(null);
application.companyId(null);
application.fqDns(null);
application.internalFqDns(null);

cloud.updateApplication(application, appId, apiKey);
}
}
cloud.updateApplication(application, appId, apiKey);
}
}

private static List<Application.OwnerIdsAndType> resolveUsersToCloudOwners(String[] usersList, String apiKey, Cloud cloud) {
List<Application.OwnerIdsAndType> ownersList = new ArrayList<>();
Expand Down Expand Up @@ -289,6 +299,19 @@ private static String[] resolveCloudOwnersNames(String policyName, String apiKey
return usersList.toArray(new String[0]);
}

private static List<Application.OwnerIdsAndType> mergeOwnersList(List<Application.OwnerIdsAndType> sourceList, List<Application.OwnerIdsAndType> incomingList) {
sourceList.addAll(incomingList);
Map<String, Application.OwnerIdsAndType> ownerMap = new HashMap<>();

for(Application.OwnerIdsAndType owner : sourceList) {
if (!ownerMap.containsKey(owner.ownerId())){
ownerMap.put(owner.ownerId(), owner);
}
}

return new ArrayList<>(ownerMap.values());
}

private static CertificateIssuingTemplate getPolicy(String policyName, String apiKey, Cloud cloud) throws VCertException {

CloudZone zone = new CloudZone(policyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,30 @@ public void createAndGetPolicyContacts() throws VCertException {
Assertions.assertEquals("pki-admin@opensource.qa.venafi.io", psReturned.users()[0]);
Assertions.assertEquals("resource-owner@opensource.qa.venafi.io", psReturned.users()[1]);
}

@Test
@DisplayName("Cloud - Testing setting contacts that are duplicated on VaaS")
public void testPolicyContactsDuplicated() throws VCertException {
CloudConnector connector = connectorResource.connector();
String policyName = CloudTestUtils.getRandomZone();
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
policySpecification.users(new String[]{"pki-admin@opensource.qa.venafi.io","resource-owner@opensource.qa.venafi.io"});
connector.setPolicy(policyName, policySpecification);
PolicySpecification psReturned = connector.getPolicy(policyName);

Assertions.assertEquals(2, psReturned.users().length);
Assertions.assertEquals("pki-admin@opensource.qa.venafi.io", psReturned.users()[0]);
Assertions.assertEquals("resource-owner@opensource.qa.venafi.io", psReturned.users()[1]);

//Updating the Policy Specification to include the duplicated contacts

PolicySpecification ps2 = CloudTestUtils.getPolicySpecification();
ps2.users(new String[]{"pki-admin@opensource.qa.venafi.io"});
connector.setPolicy(policyName, policySpecification);
PolicySpecification psReturned2 = connector.getPolicy(policyName);

Assertions.assertEquals(2, psReturned2.users().length);
Assertions.assertEquals("pki-admin@opensource.qa.venafi.io", psReturned.users()[0]);
Assertions.assertEquals("resource-owner@opensource.qa.venafi.io", psReturned.users()[1]);
}
}