Skip to content

Commit

Permalink
update export certs flows
Browse files Browse the repository at this point in the history
  • Loading branch information
RusJaI committed Jul 2, 2024
1 parent 5567a34 commit bb88304
Showing 1 changed file with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1019,35 +1019,40 @@ public static void addClientCertificatesToArchive(String archivePath, Identifier
APIProvider provider, ExportFormat exportFormat, String organization)
throws APIImportExportException {

List<ClientCertificateDTO> certificateMetadataDTOs;
try {
if (identifier instanceof APIProductIdentifier) {
certificateMetadataDTOs = provider
.searchClientCertificates(tenantId, null, null,
(APIProductIdentifier) identifier, organization);
} else {
certificateMetadataDTOs = provider
.searchClientCertificates(tenantId, null, null,
(APIIdentifier) identifier, organization);
}
if (!certificateMetadataDTOs.isEmpty()) {
String clientCertsDirectoryPath =
archivePath + File.separator + ImportExportConstants.CLIENT_CERTIFICATES_DIRECTORY;
CommonUtil.createDirectory(clientCertsDirectoryPath);
String[] keyTypes = new String[] {APIConstants.API_KEY_TYPE_PRODUCTION, APIConstants.API_KEY_TYPE_SANDBOX};

JsonArray certificateList = getClientCertificateContentAndMetaData(certificateMetadataDTOs,
clientCertsDirectoryPath);
for (String keyType : keyTypes) {

if (certificateList.size() > 0) {
CommonUtil.writeDtoToFile(clientCertsDirectoryPath + ImportExportConstants.CLIENT_CERTIFICATE_FILE,
exportFormat, ImportExportConstants.TYPE_CLIENT_CERTIFICATES, certificateList);
List<ClientCertificateDTO> certificateMetadataDTOs;
try {
if (identifier instanceof APIProductIdentifier) {
certificateMetadataDTOs = provider
.searchClientCertificates(tenantId, null, keyType,
(APIProductIdentifier) identifier, organization);
} else {
certificateMetadataDTOs = provider
.searchClientCertificates(tenantId, null, keyType,
(APIIdentifier) identifier, organization);
}
if (!certificateMetadataDTOs.isEmpty()) {
String clientCertsDirectoryPath = archivePath + File.separator +
ImportExportConstants.CLIENT_CERTIFICATES_DIRECTORY + File.separator + keyType;
CommonUtil.createDirectory(clientCertsDirectoryPath);

JsonArray certificateList = getClientCertificateContentAndMetaData(certificateMetadataDTOs,
clientCertsDirectoryPath);

if (certificateList.size() > 0) {
CommonUtil.writeDtoToFile(clientCertsDirectoryPath + ImportExportConstants.CLIENT_CERTIFICATE_FILE,
exportFormat, ImportExportConstants.TYPE_CLIENT_CERTIFICATES, certificateList);
}
}
} catch (IOException e) {
throw new APIImportExportException("Error while saving as YAML or JSON", e);
} catch (APIManagementException e) {
throw new APIImportExportException(
"Error retrieving certificate meta data. tenantId [" + tenantId + "] api [" + tenantId + "]", e);
}
} catch (IOException e) {
throw new APIImportExportException("Error while saving as YAML or JSON", e);
} catch (APIManagementException e) {
throw new APIImportExportException(
"Error retrieving certificate meta data. tenantId [" + tenantId + "] api [" + tenantId + "]", e);
}
}

Expand Down

0 comments on commit bb88304

Please sign in to comment.