API versioning fixed

This commit is contained in:
rdavidek 2026-02-09 16:19:57 +01:00
parent fe4f766459
commit c066535843
6 changed files with 50 additions and 15 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ bin
/api.yaml /api.yaml
*.zip *.zip
apis apis
tmp

Binary file not shown.

View File

@ -42,7 +42,6 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.38</version> <version>1.18.38</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.swagger</groupId> <groupId>io.swagger</groupId>

View File

@ -5,6 +5,7 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -87,8 +88,6 @@ public abstract class AbstractProcess {
config = ConfigManager.getInstance().getConfig(); config = ConfigManager.getInstance().getConfig();
this.client = RegistryClientFactory.create(config.getApicurio().getApiUrl());
setTrustStoreCredentials(); setTrustStoreCredentials();
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() { javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
@ -96,6 +95,21 @@ public abstract class AbstractProcess {
return true; return true;
} }
}); });
Map<String, Object> clientConfigs = new HashMap<>();
try {
SSLContext sslContext = createSSLContext(
config.getTrustStore().getPath(),
config.getTrustStore().getPassword()
);
clientConfigs.put("io.apicurio.rest.client.jdk.sslContext", sslContext);
} catch (Exception e) {
log.error("Failed to initialize SSL context for Apicurio client", e);
}
this.client = RegistryClientFactory.create(config.getApicurio().getApiUrl(), clientConfigs);
client.listConfigProperties();
} }
protected void setTrustStoreCredentials() { protected void setTrustStoreCredentials() {
@ -388,7 +402,8 @@ public abstract class AbstractProcess {
APIList listOfApis = null; APIList listOfApis = null;
try { try {
String url = publisherurl.concat(String.format("/apis?limit=9999&offset=0")); //String url = publisherurl.concat(String.format("/apis?limit=10&offset=0&query=name:%s", "PTSPaymentHubCZSIT*"));
String url = publisherurl.concat("/apis?limit=9999&offset=0");
log.debug("Getting APIs with token: '" + tokenResponse.getAccess_token() + "' URL: " + url); log.debug("Getting APIs with token: '" + tokenResponse.getAccess_token() + "' URL: " + url);
@ -558,6 +573,12 @@ public abstract class AbstractProcess {
log.debug("Creating artifact reference for entry: {} with artifactId: {}", entry.getName(), artifactId); log.debug("Creating artifact reference for entry: {} with artifactId: {}", entry.getName(), artifactId);
File tmpFile = new File("tmp/api/", entry.getName());
FileOutputStream fos = new FileOutputStream(tmpFile);
fos.write(entry.getContent());
fos.flush();
fos.close();
try (ByteArrayInputStream is = new ByteArrayInputStream(entry.getContent())) { try (ByteArrayInputStream is = new ByteArrayInputStream(entry.getContent())) {
ArtifactMetaData meta = client.createArtifactWithVersion(entry.getType().toString(), artifactId, api.getVersion(), is); ArtifactMetaData meta = client.createArtifactWithVersion(entry.getType().toString(), artifactId, api.getVersion(), is);
Map<String, String> props = new LinkedHashMap<>(); Map<String, String> props = new LinkedHashMap<>();

View File

@ -1,6 +1,8 @@
package cz.trask.migration.impl.v32; package cz.trask.migration.impl.v32;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -108,6 +110,15 @@ public class Wso2v32ToApicurio extends AbstractProcess {
config.getSource().getPublisherApiUrl() + "/apis/export?apiId=" + api.getId(), httpHeaders, config.getSource().getPublisherApiUrl() + "/apis/export?apiId=" + api.getId(), httpHeaders,
Collections.emptyMap(), true); Collections.emptyMap(), true);
if (config.isStoreMigratedArtifacts()) {
File tmpFile = new File("tmp/api/", api.getName() + "_" + api.getVersion() + ".zip");
log.info(" - Storing migrated Api file: {}", tmpFile.getAbsolutePath());
FileOutputStream fos = new FileOutputStream(tmpFile);
fos.write(exportedZip.getResponseBytes());
fos.flush();
fos.close();
}
List<ZipEntryData> zipEntries = ZipUtils.extractFilesFromZip(exportedZip.getResponseBytes()); List<ZipEntryData> zipEntries = ZipUtils.extractFilesFromZip(exportedZip.getResponseBytes());
String swagger = null; String swagger = null;
@ -149,6 +160,9 @@ public class Wso2v32ToApicurio extends AbstractProcess {
ObjectNode swaggerObj = mapperYaml.valueToTree(swaggerMap); ObjectNode swaggerObj = mapperYaml.valueToTree(swaggerMap);
updateSwagger(swaggerObj, apiMap, fullDesc); updateSwagger(swaggerObj, apiMap, fullDesc);
api.setName((String)apiMap.get("name"));
api.setContext((String)apiMap.get("context"));
// 7) Prepare artifact creation/update // 7) Prepare artifact creation/update
String group = config.getApicurio().getDefaultApiGroup(); String group = config.getApicurio().getDefaultApiGroup();
String mainArtifactId = api.getName() + api.getContext(); String mainArtifactId = api.getName() + api.getContext();

View File

@ -1,10 +1,10 @@
source: source:
registration_api_url: https://localhost:9444/client-registration/v0.17/register registration_api_url: https://developerstest.jtfg.com/client-registration/v0.17/register
publisher_api_url: https://localhost:9444/api/am/publisher publisher_api_url: https://developerstest.jtfg.com/api/am/publisher
admin_api_url: https://localhost:9444/api/am/admin/v1 admin_api_url: https://developerstest.jtfg.com/api/am/admin/v1
devportal_api_url: https://localhost:9444/api/am/store devportal_api_url: https://developerstest.jtfg.com/api/am/store
publisher_token_url: https://localhost:9444/oauth2/token publisher_token_url: https://developerstest.jtfg.com/oauth2/token
wso2_user: YWRtaW46YWRtaW4= wso2_user: YWRtaW46UkllSTVBeGN4LXZRQVZsSA==
wso2_apis_dir: apis wso2_apis_dir: apis
target: target:
@ -20,14 +20,14 @@ truststore:
password: wso2carbon password: wso2carbon
patterns: patterns:
publisher_url_pattern: https://api-developers.dev.koop.appl.services/publisher/apis/{API_ID}/overview publisher_url_pattern: https://developers/publisher/apis/{API_ID}/overview
devportal_url_pattern: https://api-developers.dev.koop.appl.services/devportal/apis/{API_ID}/overview devportal_url_pattern: https://developers/devportal/apis/{API_ID}/overview
apicurio: apicurio:
api_url: http://apicurio:8095/apis/registry/v2 api_url: https://apim-apicurio-app-apim-wso2.apps.oshift-akc.jtfg.com/apis/registry/v2
default_api_group: api default_api_group: api
overwrite_existing_application: true overwrite_existing_application: true
max_threads: 1 max_threads: 8
store_migrated_artifacts: true store_migrated_artifacts: true