Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 580e7cf

Browse files
authored
Merge pull request #108 from Venafi/contacts-support
fix for contacts support
2 parents e86ade2 + 7eb311c commit 580e7cf

2 files changed

Lines changed: 18 additions & 29 deletions

File tree

src/main/java/com/venafi/vcert/sdk/connectors/cloud/CloudConnectorUtils.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,44 +167,36 @@ private static void addCitToApp(CertificateIssuingTemplate cit, Application appl
167167
String apiKey, Cloud cloud) throws VCertException {
168168
Map<String, String> citAliasIdMap = null;
169169

170-
if ( application.certificateIssuingTemplateAliasIdMap() != null )
170+
if ( application.certificateIssuingTemplateAliasIdMap() != null ) {
171171
citAliasIdMap = application.certificateIssuingTemplateAliasIdMap();
172+
}
172173
else {
173174
citAliasIdMap = new HashMap<>();
174175
application.certificateIssuingTemplateAliasIdMap( citAliasIdMap );
175176
}
176177

177-
boolean updateApplication = false;
178-
179178
//if the App doesn't contain the relation to the cit
180179
if ( !citAliasIdMap.containsKey(cit.name()) ) {
181180
//adding the reference to the cit
182181
citAliasIdMap.put(cit.name(), cit.id());
183-
updateApplication = true;
184182
}
185183

186184
// Updating the owners list of the Application
187185
List<Application.OwnerIdsAndType> ownersList = CloudConnectorUtils.resolveUsersToCloudOwners(usersList, apiKey, cloud);
188-
if (ownersList.size() > 0){
189-
// application.ownerIdsAndTypes().addAll(ownersList);
190-
List<Application.OwnerIdsAndType> newList = mergeOwnersList(application.ownerIdsAndTypes(), ownersList);
191-
application.ownerIdsAndTypes(newList);
192-
updateApplication = true;
193-
}
186+
application.ownerIdsAndTypes(ownersList);
194187

195-
if (updateApplication) {
196-
//getting the appId because it will be used to invoke the API to update the related Application
197-
String appId = application.id();
188+
//getting the appId because it will be used to invoke the API to update the related Application
189+
String appId = application.id();
198190

199-
//The id, companyId, fqDns and internalFqDns needs to be null in the request to update the Application,
200-
//therefore these attributes are set to null
201-
application.id(null);
202-
application.companyId(null);
203-
application.fqDns(null);
204-
application.internalFqDns(null);
191+
//The id, companyId, fqDns and internalFqDns needs to be null in the request to update the Application,
192+
//therefore these attributes are set to null
193+
application.id(null);
194+
application.companyId(null);
195+
application.fqDns(null);
196+
application.internalFqDns(null);
197+
198+
cloud.updateApplication(application, appId, apiKey);
205199

206-
cloud.updateApplication(application, appId, apiKey);
207-
}
208200
}
209201

210202
private static List<Application.OwnerIdsAndType> resolveUsersToCloudOwners(String[] usersList, String apiKey, Cloud cloud) {

src/test/java/com/venafi/vcert/sdk/connectors/cloud/CloudConnectorPolicyAT.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void createAndGetPolicyContacts() throws VCertException {
124124

125125
@Test
126126
@DisplayName("Cloud - Testing setting contacts that are duplicated on VaaS")
127-
public void testPolicyContactsDuplicated() throws VCertException {
127+
public void testPolicyContactsUpdated() throws VCertException {
128128
CloudConnector connector = connectorResource.connector();
129129
String policyName = CloudTestUtils.getRandomZone();
130130
PolicySpecification policySpecification = CloudTestUtils.getPolicySpecification();
@@ -136,15 +136,12 @@ public void testPolicyContactsDuplicated() throws VCertException {
136136
Assertions.assertEquals("pki-admin@opensource.qa.venafi.io", psReturned.users()[0]);
137137
Assertions.assertEquals("resource-owner@opensource.qa.venafi.io", psReturned.users()[1]);
138138

139-
//Updating the Policy Specification to include the duplicated contacts
140-
139+
//Updating the Policy Specification to include just one owner
141140
PolicySpecification ps2 = CloudTestUtils.getPolicySpecification();
142-
ps2.users(new String[]{"pki-admin@opensource.qa.venafi.io"});
143-
connector.setPolicy(policyName, policySpecification);
141+
connector.setPolicy(policyName, ps2);
144142
PolicySpecification psReturned2 = connector.getPolicy(policyName);
145143

146-
Assertions.assertEquals(2, psReturned2.users().length);
147-
Assertions.assertEquals("pki-admin@opensource.qa.venafi.io", psReturned.users()[0]);
148-
Assertions.assertEquals("resource-owner@opensource.qa.venafi.io", psReturned.users()[1]);
144+
Assertions.assertEquals(1, psReturned2.users().length);
145+
Assertions.assertEquals("jenkins@opensource.qa.venafi.io", psReturned2.users()[0]);
149146
}
150147
}

0 commit comments

Comments
 (0)