diff --git a/.gitignore b/.gitignore index 7f5329a..da6a13b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ bin .vscode /api.yaml *.zip -apis \ No newline at end of file +apis +tmp \ No newline at end of file diff --git a/client-truststore.jks b/client-truststore.jks index a557f3b..f2e5e42 100644 Binary files a/client-truststore.jks and b/client-truststore.jks differ diff --git a/pom.xml b/pom.xml index 68c169e..acba44f 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,6 @@ org.projectlombok lombok 1.18.38 - provided io.swagger diff --git a/src/main/java/cz/trask/migration/AbstractProcess.java b/src/main/java/cz/trask/migration/AbstractProcess.java index 5c46547..6719d38 100644 --- a/src/main/java/cz/trask/migration/AbstractProcess.java +++ b/src/main/java/cz/trask/migration/AbstractProcess.java @@ -5,6 +5,7 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -87,8 +88,6 @@ public abstract class AbstractProcess { config = ConfigManager.getInstance().getConfig(); - this.client = RegistryClientFactory.create(config.getApicurio().getApiUrl()); - setTrustStoreCredentials(); javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() { @@ -96,6 +95,21 @@ public abstract class AbstractProcess { return true; } }); + + Map 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() { @@ -388,7 +402,8 @@ public abstract class AbstractProcess { APIList listOfApis = null; 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); @@ -558,6 +573,12 @@ public abstract class AbstractProcess { 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())) { ArtifactMetaData meta = client.createArtifactWithVersion(entry.getType().toString(), artifactId, api.getVersion(), is); Map props = new LinkedHashMap<>(); diff --git a/src/main/java/cz/trask/migration/impl/v32/Wso2v32ToApicurio.java b/src/main/java/cz/trask/migration/impl/v32/Wso2v32ToApicurio.java index db166a4..e383dfe 100644 --- a/src/main/java/cz/trask/migration/impl/v32/Wso2v32ToApicurio.java +++ b/src/main/java/cz/trask/migration/impl/v32/Wso2v32ToApicurio.java @@ -1,6 +1,8 @@ package cz.trask.migration.impl.v32; import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -108,6 +110,15 @@ public class Wso2v32ToApicurio extends AbstractProcess { config.getSource().getPublisherApiUrl() + "/apis/export?apiId=" + api.getId(), httpHeaders, 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 zipEntries = ZipUtils.extractFilesFromZip(exportedZip.getResponseBytes()); String swagger = null; @@ -148,6 +159,9 @@ public class Wso2v32ToApicurio extends AbstractProcess { Map swaggerMap = mapperYaml.readValue(swagger, Map.class); ObjectNode swaggerObj = mapperYaml.valueToTree(swaggerMap); updateSwagger(swaggerObj, apiMap, fullDesc); + + api.setName((String)apiMap.get("name")); + api.setContext((String)apiMap.get("context")); // 7) Prepare artifact creation/update String group = config.getApicurio().getDefaultApiGroup(); diff --git a/src/main/resources/apicurio-migrator.yaml b/src/main/resources/apicurio-migrator.yaml index 4a21cc7..c253a2d 100644 --- a/src/main/resources/apicurio-migrator.yaml +++ b/src/main/resources/apicurio-migrator.yaml @@ -1,10 +1,10 @@ source: - registration_api_url: https://localhost:9444/client-registration/v0.17/register - publisher_api_url: https://localhost:9444/api/am/publisher - admin_api_url: https://localhost:9444/api/am/admin/v1 - devportal_api_url: https://localhost:9444/api/am/store - publisher_token_url: https://localhost:9444/oauth2/token - wso2_user: YWRtaW46YWRtaW4= + registration_api_url: https://developerstest.jtfg.com/client-registration/v0.17/register + publisher_api_url: https://developerstest.jtfg.com/api/am/publisher + admin_api_url: https://developerstest.jtfg.com/api/am/admin/v1 + devportal_api_url: https://developerstest.jtfg.com/api/am/store + publisher_token_url: https://developerstest.jtfg.com/oauth2/token + wso2_user: YWRtaW46UkllSTVBeGN4LXZRQVZsSA== wso2_apis_dir: apis target: @@ -20,14 +20,14 @@ truststore: password: wso2carbon patterns: - publisher_url_pattern: https://api-developers.dev.koop.appl.services/publisher/apis/{API_ID}/overview - devportal_url_pattern: https://api-developers.dev.koop.appl.services/devportal/apis/{API_ID}/overview + publisher_url_pattern: https://developers/publisher/apis/{API_ID}/overview + devportal_url_pattern: https://developers/devportal/apis/{API_ID}/overview 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 overwrite_existing_application: true -max_threads: 1 +max_threads: 8 store_migrated_artifacts: true \ No newline at end of file