endpoint security fixes, refactor
This commit is contained in:
parent
e26477e8d1
commit
f7da49a36c
Binary file not shown.
@ -38,7 +38,7 @@ import cz.trask.migration.config.ConfigManager;
|
||||
import cz.trask.migration.model.APIInfo;
|
||||
import cz.trask.migration.model.APIList;
|
||||
import cz.trask.migration.model.ApplicationConfig;
|
||||
import cz.trask.migration.model.ApplicationConfig.Wso2Endpoints;
|
||||
import cz.trask.migration.model.ApplicationConfig.Wso2Settings;
|
||||
import cz.trask.migration.model.HttpResponse;
|
||||
import cz.trask.migration.model.RegisterResponse;
|
||||
import cz.trask.migration.model.TokenResponse;
|
||||
@ -58,8 +58,6 @@ public abstract class AbstractProcess {
|
||||
protected static final String PARAM_SOURCE_APIM = "source_apim";
|
||||
protected static final String VERSION_32 = "v32";
|
||||
|
||||
public static final String PRIVATE_KEY_APIM_32 = "wso2apim32-pk.pem";
|
||||
|
||||
public static final String ARTIFACT_GROUP_SUBSCRIPTIONS = "SUBSCRIPTIONS";
|
||||
public static final String ARTIFACT_NAME_SUBSCRIPTIONS = "subs.yaml";
|
||||
|
||||
@ -155,7 +153,7 @@ public abstract class AbstractProcess {
|
||||
connection.setSSLSocketFactory(sslContext.getSocketFactory());
|
||||
}
|
||||
|
||||
protected TokenResponse authenticateToWso2AndGetToken(Wso2Endpoints endpoints) throws Exception {
|
||||
protected TokenResponse authenticateToWso2AndGetToken(Wso2Settings endpoints) throws Exception {
|
||||
RegisterResponse register = register(endpoints.getRegistrationApiUrl(), endpoints.getWso2User());
|
||||
|
||||
String clientId = register.getClientId();
|
||||
@ -282,7 +280,7 @@ public abstract class AbstractProcess {
|
||||
|
||||
URL url = new URL(urlStr);
|
||||
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(proxy!=null ? proxy : Proxy.NO_PROXY);
|
||||
con.setRequestMethod(method);
|
||||
con.setDoInput(true);
|
||||
configureHttpsConnection(con);
|
||||
@ -345,7 +343,7 @@ public abstract class AbstractProcess {
|
||||
|
||||
URL url = new URL(urlStr);
|
||||
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(proxy);
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(proxy!=null ? proxy : Proxy.NO_PROXY);
|
||||
con.setRequestMethod("POST");
|
||||
con.setDoInput(true);
|
||||
con.setDoOutput(true);
|
||||
@ -457,7 +455,7 @@ public abstract class AbstractProcess {
|
||||
|
||||
URL url = new URL(urlStr);
|
||||
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(proxy);
|
||||
HttpsURLConnection con = (HttpsURLConnection) url.openConnection(proxy!=null ? proxy : Proxy.NO_PROXY);
|
||||
con.setUseCaches(false);
|
||||
con.setDoOutput(true);
|
||||
configureHttpsConnection(con);
|
||||
@ -510,6 +508,31 @@ public abstract class AbstractProcess {
|
||||
return resp;
|
||||
}
|
||||
|
||||
protected int publishApiToWso2(String fileName, byte[] data, TokenResponse tokenResponse) {
|
||||
int responseCode = -1;
|
||||
try {
|
||||
String url = config.getTarget().getPublisherApiUrl()
|
||||
.concat(String.format("?preserveProvider=false&overwrite=true"));
|
||||
|
||||
log.info("API Import URL: " + url);
|
||||
|
||||
Map<String, String> httpHeaders = new HashMap<>();
|
||||
|
||||
httpHeaders.put("Authorization", "Bearer " + tokenResponse.getAccess_token());
|
||||
|
||||
HttpResponse response = makeFileRequest("POST", url, httpHeaders, data, fileName);
|
||||
|
||||
responseCode = response.getResponseCode();
|
||||
|
||||
if (response.getResponseCode() != 201 && response.getResponseCode() != 200) {
|
||||
log.info("Cannot import API file: " + fileName + ", response code: " + response.getResponseCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("IO error while importing API file: " + fileName + ", error: " + e.getMessage(), e);
|
||||
}
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
protected void setArtifactMetaData(ArtifactMetaData meta, String name, String description, Map<String, String> props) {
|
||||
EditableMetaData metaData = new EditableMetaData();
|
||||
metaData.setName(name);
|
||||
|
||||
@ -6,6 +6,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import cz.trask.migration.impl.v32.Wso2AppsToApicurio;
|
||||
import cz.trask.migration.impl.v32.Wso2v32ToApicurio;
|
||||
import cz.trask.migration.impl.v32.Wso2v32ToApicurioFromDir;
|
||||
import cz.trask.migration.impl.v45.ApiFilesToWso2;
|
||||
import cz.trask.migration.impl.v45.ExportApisToWso2FromV32;
|
||||
import cz.trask.migration.impl.v45.ExportAppsToWso2FromV32;
|
||||
import cz.trask.migration.model.StartParameters;
|
||||
@ -44,6 +45,10 @@ public class ApiSync {
|
||||
log.info("apicurioAppsToWso2 command selected.");
|
||||
ExportAppsToWso2FromV32 exp = new ExportAppsToWso2FromV32();
|
||||
exp.process();
|
||||
} else if (sp.getCommand().equalsIgnoreCase("apiFilesToWso2")) {
|
||||
log.info("apiFilesToWso2 command selected.");
|
||||
ApiFilesToWso2 imp = new ApiFilesToWso2();
|
||||
imp.process();
|
||||
} else {
|
||||
log.error("Unknown command: " + sp.getCommand());
|
||||
printHelp();
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
package cz.trask.migration.impl.v45;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import cz.trask.migration.AbstractProcess;
|
||||
import cz.trask.migration.model.TokenResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
@Log4j2
|
||||
public class ApiFilesToWso2 extends AbstractProcess {
|
||||
|
||||
private final AtomicInteger apiCounter = new AtomicInteger(1);
|
||||
|
||||
/**
|
||||
* Main entry point for the import process.
|
||||
*
|
||||
* @throws RuntimeException if any error occurs
|
||||
*/
|
||||
public void process() {
|
||||
try {
|
||||
log.info("Starting API import to WSO2 from directory...");
|
||||
|
||||
TokenResponse token = authenticateToWso2AndGetToken(config.getTarget());
|
||||
|
||||
File root = new File(config.getSource().getWso2ApisDir());
|
||||
|
||||
File[] apiFiles = root.listFiles((dir, name) -> name.endsWith(".zip"));
|
||||
if (apiFiles == null || apiFiles.length == 0) {
|
||||
log.warn("No API zip files found in directory: {}", config.getSource().getWso2ApisDir());
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("Found {} APIs", apiFiles.length);
|
||||
|
||||
for (File api : apiFiles) {
|
||||
final int index = apiCounter.getAndIncrement();
|
||||
processApi(api, token, index, apiFiles.length);
|
||||
}
|
||||
|
||||
log.info("Finished processing APIs.");
|
||||
} catch (Exception e) {
|
||||
log.error("Error while importing APIs.", e);
|
||||
throw new RuntimeException("Import failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a single API – fetches the data, creates or updates the corresponding
|
||||
* artifact in WSO2.
|
||||
*/
|
||||
private void processApi(File apiFile, TokenResponse token, int index, int total) {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
log.info("Processing API {} of {}", index, total);
|
||||
|
||||
String fileName = apiFile.getName();
|
||||
byte[] data = null;
|
||||
try {
|
||||
data = Files.readAllBytes(apiFile.toPath());
|
||||
} catch (IOException e) {
|
||||
log.error("Failed to read API file '{}': {}", apiFile.getName(), e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
if (data != null && data.length > 0 && fileName != null && !fileName.isEmpty()) {
|
||||
int responseCode = publishApiToWso2(fileName, data, token);
|
||||
if (responseCode == 200 || responseCode == 201) {
|
||||
log.info(" - API version {} imported successfully", fileName);
|
||||
} else {
|
||||
log.warn(" - API version {} import failed with response code {}", fileName,
|
||||
responseCode);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Successfully imported API '{}' ({}). Took {} ms", apiFile.getName(),
|
||||
apiFile.getName(),
|
||||
System.currentTimeMillis() - start);
|
||||
} catch (Exception e) {
|
||||
log.error("Cannot export API '{}': {}", apiFile.getName(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,9 +5,7 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -23,7 +21,6 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import cz.trask.migration.AbstractProcess;
|
||||
import cz.trask.migration.mapper.ApiDefinitionMapper32to45;
|
||||
import cz.trask.migration.model.FileType;
|
||||
import cz.trask.migration.model.HttpResponse;
|
||||
import cz.trask.migration.model.TokenResponse;
|
||||
import cz.trask.migration.model.v32.ApiDefinition32;
|
||||
import cz.trask.migration.model.v32.Documents32;
|
||||
@ -136,31 +133,6 @@ public class ExportApisToWso2FromV32 extends AbstractProcess {
|
||||
/* Helper methods */
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
private int publishApiToWso2(String fileName, byte[] data, TokenResponse tokenResponse) {
|
||||
int responseCode = -1;
|
||||
try {
|
||||
String url = config.getTarget().getPublisherApiUrl()
|
||||
.concat(String.format("?preserveProvider=false&overwrite=true"));
|
||||
|
||||
log.info("API Import URL: " + url);
|
||||
|
||||
Map<String, String> httpHeaders = new HashMap<>();
|
||||
|
||||
httpHeaders.put("Authorization", "Bearer " + tokenResponse.getAccess_token());
|
||||
|
||||
HttpResponse response = makeFileRequest("POST", url, httpHeaders, data, fileName);
|
||||
|
||||
responseCode = response.getResponseCode();
|
||||
|
||||
if (response.getResponseCode() != 201 && response.getResponseCode() != 200) {
|
||||
log.info("Cannot import API file: " + fileName + ", response code: " + response.getResponseCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("IO error while importing API file: " + fileName + ", error: " + e.getMessage(), e);
|
||||
}
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
public byte[] prepareApiZipFile32to45(SearchedVersion ver, List<ArtifactReference> ref) throws Exception {
|
||||
|
||||
String baseDir = ver.getName() + "-" + ver.getVersion() + "/";
|
||||
|
||||
@ -17,6 +17,7 @@ import cz.trask.migration.model.v45.ApiDefinition45;
|
||||
import cz.trask.migration.model.v45.ApiDefinition45.ApiPolicies;
|
||||
import cz.trask.migration.model.v45.ApiDefinition45.Operation;
|
||||
import cz.trask.migration.model.v45.ApiDefinition45.OperationPolicies;
|
||||
import cz.trask.migration.util.CredentialsDecoder;
|
||||
|
||||
public class ApiDefinitionMapper32to45 {
|
||||
|
||||
@ -54,13 +55,15 @@ public class ApiDefinitionMapper32to45 {
|
||||
oldApi.getTransports() != null ? List.of(oldApi.getTransports().split(",")) : Collections.emptyList());
|
||||
data.setTags(oldApi.getTags());
|
||||
data.setVisibility(oldApi.getVisibility().toUpperCase());
|
||||
//data.setVisibleRoles(oldApi.getVisibleRoles()!=null ? List.of(oldApi.getVisibleRoles().split(",")) : Collections.emptyList());
|
||||
// data.setVisibleRoles(oldApi.getVisibleRoles()!=null ?
|
||||
// List.of(oldApi.getVisibleRoles().split(",")) : Collections.emptyList());
|
||||
data.setVisibleRoles(List.of("Internal/publisher"));
|
||||
data.setVisibleTenants(Collections.emptyList());
|
||||
data.setAccessControl("NONE");
|
||||
//data.setAccessControlRoles(Collections.emptyList());
|
||||
// data.setAccessControlRoles(Collections.emptyList());
|
||||
data.setOrganizationPolicies(Collections.emptyList());
|
||||
data.setType(oldApi.getType()!=null && !oldApi.getType().toLowerCase().equals("null") ? oldApi.getType() : "HTTP");
|
||||
data.setType(
|
||||
oldApi.getType() != null && !oldApi.getType().toLowerCase().equals("null") ? oldApi.getType() : "HTTP");
|
||||
data.setAudiences(Arrays.asList("all"));
|
||||
|
||||
List<String> policies = new ArrayList<>();
|
||||
@ -102,7 +105,7 @@ public class ApiDefinitionMapper32to45 {
|
||||
data.setCorsConfiguration(mapCors(oldApi.getCorsConfiguration()));
|
||||
|
||||
// ---------- endpoint ----------
|
||||
data.setEndpointConfig(fixEndpointConfig(oldApi.getEndpointConfig()));
|
||||
data.setEndpointConfig(mapEndpointConfig(oldApi.getEndpointConfig()));
|
||||
data.setEndpointImplementationType(oldApi.getImplementation());
|
||||
|
||||
// ---------- API policies ----------
|
||||
@ -155,23 +158,67 @@ public class ApiDefinitionMapper32to45 {
|
||||
return newApi;
|
||||
}
|
||||
|
||||
private static Map fixEndpointConfig(Map endpointConfig) {
|
||||
private static Map mapEndpointConfig(Map endpointConfig) {
|
||||
if (endpointConfig == null || endpointConfig.isEmpty())
|
||||
return new HashMap();
|
||||
|
||||
Map<String, Object> endpointProd = (Map<String, Object>) endpointConfig.get("production_endpoints");
|
||||
if (endpointProd != null && endpointProd.containsKey("config")) {
|
||||
Object value = endpointProd.get("config");
|
||||
if (value==null) {
|
||||
endpointProd.remove("config");
|
||||
if (endpointConfig.get("production_endpoints") != null
|
||||
&& (endpointConfig.get("production_endpoints") instanceof Map)) {
|
||||
Map<String, Object> endpointProd = (Map<String, Object>) endpointConfig.get("production_endpoints");
|
||||
if (endpointProd != null && endpointProd.containsKey("config")) {
|
||||
Object value = endpointProd.get("config");
|
||||
if (value == null) {
|
||||
endpointProd.remove("config");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> endpointSand = (Map<String, Object>) endpointConfig.get("sandbox_endpoints");
|
||||
if (endpointSand != null && endpointSand.containsKey("config")) {
|
||||
Object value = endpointSand.get("config");
|
||||
if (value==null) {
|
||||
endpointSand.remove("config");
|
||||
if (endpointConfig.get("sandbox_endpoints") != null && (endpointConfig.get("sandbox_endpoints") instanceof Map)) {
|
||||
Map<String, Object> endpointSand = (Map<String, Object>) endpointConfig.get("sandbox_endpoints");
|
||||
if (endpointSand != null && endpointSand.containsKey("config")) {
|
||||
Object value = endpointSand.get("config");
|
||||
if (value == null) {
|
||||
endpointSand.remove("config");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (endpointConfig.get("endpoint_security") != null && (endpointConfig.get("endpoint_security") instanceof Map)) {
|
||||
Map<String, Object> endpointSecurity = (Map<String, Object>) endpointConfig.get("endpoint_security");
|
||||
Map<String, Object> sandbox = endpointSecurity.get("sandbox") != null
|
||||
&& endpointSecurity.get("sandbox") instanceof Map
|
||||
? (Map<String, Object>) endpointSecurity.get("sandbox")
|
||||
: null;
|
||||
Map<String, Object> production = endpointSecurity.get("production") != null
|
||||
&& endpointSecurity.get("production") instanceof Map
|
||||
? (Map<String, Object>) endpointSecurity.get("production")
|
||||
: null;
|
||||
|
||||
if (sandbox != null && sandbox.containsKey("clientSecret") && sandbox.get("clientSecret") != null) {
|
||||
String encodedSecret = sandbox.get("clientSecret").toString();
|
||||
sandbox.put("clientSecret", CredentialsDecoder.decodeCredentials(encodedSecret));
|
||||
}
|
||||
if (production != null && production.containsKey("clientSecret") && production.get("clientSecret") != null) {
|
||||
String encodedSecret = production.get("clientSecret").toString();
|
||||
production.put("clientSecret", CredentialsDecoder.decodeCredentials(encodedSecret));
|
||||
}
|
||||
if (sandbox != null && sandbox.containsKey("customParameters") && sandbox.get("customParameters") != null) {
|
||||
String customParamsStr = sandbox.get("customParameters").toString();
|
||||
try {
|
||||
Map<String, Object> customParams = AbstractProcess.mapperYaml.readValue(customParamsStr, Map.class);
|
||||
sandbox.put("customParameters", customParams);
|
||||
} catch (Exception e) {
|
||||
sandbox.put("customParameters", Collections.emptyMap());
|
||||
}
|
||||
}
|
||||
if (production != null && production.containsKey("customParameters") && production.get("customParameters") != null) {
|
||||
String customParamsStr = production.get("customParameters").toString();
|
||||
try {
|
||||
Map<String, Object> customParams = AbstractProcess.mapperYaml.readValue(customParamsStr, Map.class);
|
||||
production.put("customParameters", customParams);
|
||||
} catch (Exception e) {
|
||||
production.put("customParameters", Collections.emptyMap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,73 +306,81 @@ public class ApiDefinitionMapper32to45 {
|
||||
return cors;
|
||||
}
|
||||
|
||||
// private static ApiDefinition45.EndpointConfig mapEndpointConfig(ApiDefinition32.EndpointConfig oldEndpoint) {
|
||||
// if (oldEndpoint == null)
|
||||
// return null;
|
||||
//
|
||||
// ApiDefinition45.EndpointConfig newEndpoint = new ApiDefinition45.EndpointConfig();
|
||||
// newEndpoint.setEndpoint_type(oldEndpoint.getEndpointType());
|
||||
//
|
||||
// if (oldEndpoint.getSandboxEndpoints() != null) {
|
||||
// ApiDefinition45.EndpointGroup sandbox = new ApiDefinition45.EndpointGroup();
|
||||
// sandbox.setUrl(oldEndpoint.getSandboxEndpoints().getUrl());
|
||||
// newEndpoint.setSandbox_endpoints(sandbox);
|
||||
// }
|
||||
//
|
||||
// if (oldEndpoint.getProductionEndpoints() != null) {
|
||||
// ApiDefinition45.EndpointGroup production = new ApiDefinition45.EndpointGroup();
|
||||
// production.setUrl(oldEndpoint.getProductionEndpoints().getUrl());
|
||||
// newEndpoint.setProduction_endpoints(production);
|
||||
// }
|
||||
//
|
||||
// if (oldEndpoint.getEndpointSecurity() != null) {
|
||||
// ApiDefinition45.EndpointSecurity security = new ApiDefinition45.EndpointSecurity();
|
||||
// security.setSandbox(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getSandbox()));
|
||||
// security.setProduction(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getProduction()));
|
||||
// newEndpoint.setEndpoint_security(security);
|
||||
// }
|
||||
//
|
||||
// return newEndpoint;
|
||||
// }
|
||||
//
|
||||
// private static ApiDefinition45.SecurityEnv mapSecurityEnv(ApiDefinition32.SecurityEnvironment oldSec) {
|
||||
// if (oldSec == null)
|
||||
// return null;
|
||||
//
|
||||
// ApiDefinition45.SecurityEnv newSec = new ApiDefinition45.SecurityEnv();
|
||||
// newSec.setType(oldSec.getType());
|
||||
// newSec.setTokenUrl(oldSec.getTokenUrl());
|
||||
// newSec.setClientId(oldSec.getClientId());
|
||||
// newSec.setClientSecret(
|
||||
// CredentialsDecoder.decodeCredentials(oldSec.getClientSecret(), AbstractProcess.PRIVATE_KEY_APIM_32));
|
||||
// newSec.setUsername(oldSec.getUsername());
|
||||
// newSec.setPassword(oldSec.getPassword());
|
||||
// newSec.setGrantType(oldSec.getGrantType());
|
||||
// newSec.setEnabled(oldSec.isEnabled());
|
||||
// newSec.setConnectionTimeoutDuration(0);
|
||||
// newSec.setSocketTimeoutDuration(0);
|
||||
// newSec.setConnectionRequestTimeoutDuration(0);
|
||||
// newSec.setProxyConfigs(new ApiDefinition45.ProxyConfigs());
|
||||
//
|
||||
// // ---------- parse customParameters JSON string ----------
|
||||
// if (oldSec.getCustomParameters() != null && !oldSec.getCustomParameters().isEmpty()) {
|
||||
// try {
|
||||
// Map<String, Object> map = AbstractProcess.mapperYaml.readValue(oldSec.getCustomParameters(),
|
||||
// new TypeReference<>() {
|
||||
// });
|
||||
// newSec.setCustomParameters(map);
|
||||
// } catch (Exception e) {
|
||||
// newSec.setCustomParameters(Collections.emptyMap());
|
||||
// }
|
||||
// } else {
|
||||
// newSec.setCustomParameters(Collections.emptyMap());
|
||||
// }
|
||||
//
|
||||
// // ---------- parse additionalProperties JSON string ----------
|
||||
// newSec.setAdditionalProperties(Collections.emptyMap());
|
||||
//
|
||||
// return newSec;
|
||||
// }
|
||||
// private static ApiDefinition45.EndpointConfig
|
||||
// mapEndpointConfig(ApiDefinition32.EndpointConfig oldEndpoint) {
|
||||
// if (oldEndpoint == null)
|
||||
// return null;
|
||||
//
|
||||
// ApiDefinition45.EndpointConfig newEndpoint = new
|
||||
// ApiDefinition45.EndpointConfig();
|
||||
// newEndpoint.setEndpoint_type(oldEndpoint.getEndpointType());
|
||||
//
|
||||
// if (oldEndpoint.getSandboxEndpoints() != null) {
|
||||
// ApiDefinition45.EndpointGroup sandbox = new ApiDefinition45.EndpointGroup();
|
||||
// sandbox.setUrl(oldEndpoint.getSandboxEndpoints().getUrl());
|
||||
// newEndpoint.setSandbox_endpoints(sandbox);
|
||||
// }
|
||||
//
|
||||
// if (oldEndpoint.getProductionEndpoints() != null) {
|
||||
// ApiDefinition45.EndpointGroup production = new
|
||||
// ApiDefinition45.EndpointGroup();
|
||||
// production.setUrl(oldEndpoint.getProductionEndpoints().getUrl());
|
||||
// newEndpoint.setProduction_endpoints(production);
|
||||
// }
|
||||
//
|
||||
// if (oldEndpoint.getEndpointSecurity() != null) {
|
||||
// ApiDefinition45.EndpointSecurity security = new
|
||||
// ApiDefinition45.EndpointSecurity();
|
||||
// security.setSandbox(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getSandbox()));
|
||||
// security.setProduction(mapSecurityEnv(oldEndpoint.getEndpointSecurity().getProduction()));
|
||||
// newEndpoint.setEndpoint_security(security);
|
||||
// }
|
||||
//
|
||||
// return newEndpoint;
|
||||
// }
|
||||
//
|
||||
// private static ApiDefinition45.SecurityEnv
|
||||
// mapSecurityEnv(ApiDefinition32.SecurityEnvironment oldSec) {
|
||||
// if (oldSec == null)
|
||||
// return null;
|
||||
//
|
||||
// ApiDefinition45.SecurityEnv newSec = new ApiDefinition45.SecurityEnv();
|
||||
// newSec.setType(oldSec.getType());
|
||||
// newSec.setTokenUrl(oldSec.getTokenUrl());
|
||||
// newSec.setClientId(oldSec.getClientId());
|
||||
// newSec.setClientSecret(
|
||||
// CredentialsDecoder.decodeCredentials(oldSec.getClientSecret(),
|
||||
// AbstractProcess.PRIVATE_KEY_APIM_32));
|
||||
// newSec.setUsername(oldSec.getUsername());
|
||||
// newSec.setPassword(oldSec.getPassword());
|
||||
// newSec.setGrantType(oldSec.getGrantType());
|
||||
// newSec.setEnabled(oldSec.isEnabled());
|
||||
// newSec.setConnectionTimeoutDuration(0);
|
||||
// newSec.setSocketTimeoutDuration(0);
|
||||
// newSec.setConnectionRequestTimeoutDuration(0);
|
||||
// newSec.setProxyConfigs(new ApiDefinition45.ProxyConfigs());
|
||||
//
|
||||
// // ---------- parse customParameters JSON string ----------
|
||||
// if (oldSec.getCustomParameters() != null &&
|
||||
// !oldSec.getCustomParameters().isEmpty()) {
|
||||
// try {
|
||||
// Map<String, Object> map =
|
||||
// AbstractProcess.mapperYaml.readValue(oldSec.getCustomParameters(),
|
||||
// new TypeReference<>() {
|
||||
// });
|
||||
// newSec.setCustomParameters(map);
|
||||
// } catch (Exception e) {
|
||||
// newSec.setCustomParameters(Collections.emptyMap());
|
||||
// }
|
||||
// } else {
|
||||
// newSec.setCustomParameters(Collections.emptyMap());
|
||||
// }
|
||||
//
|
||||
// // ---------- parse additionalProperties JSON string ----------
|
||||
// newSec.setAdditionalProperties(Collections.emptyMap());
|
||||
//
|
||||
// return newSec;
|
||||
// }
|
||||
|
||||
public static List<Operation> mapOperations(String swaggerYamlString) throws Exception {
|
||||
JsonNode root = AbstractProcess.mapperYaml.readTree(swaggerYamlString);
|
||||
|
||||
@ -8,9 +8,9 @@ import lombok.Data;
|
||||
public class ApplicationConfig {
|
||||
|
||||
@JsonProperty("source")
|
||||
private Wso2Endpoints source;
|
||||
private Wso2Settings source;
|
||||
@JsonProperty("target")
|
||||
private Wso2Endpoints target;
|
||||
private Wso2Settings target;
|
||||
@JsonProperty("truststore")
|
||||
private TrustStore trustStore;
|
||||
@JsonProperty("patterns")
|
||||
@ -51,7 +51,7 @@ public class ApplicationConfig {
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Wso2Endpoints {
|
||||
public static class Wso2Settings {
|
||||
@JsonProperty("registration_api_url")
|
||||
private String registrationApiUrl;
|
||||
@JsonProperty("publisher_api_url")
|
||||
@ -66,7 +66,8 @@ public class ApplicationConfig {
|
||||
private String wso2User;
|
||||
@JsonProperty("wso2_apis_dir")
|
||||
private String wso2ApisDir;
|
||||
|
||||
@JsonProperty("secrets_decryption_cert")
|
||||
private String secretsDecryptionCert;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@ -12,12 +12,13 @@ import javax.crypto.Cipher;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import cz.trask.migration.config.ConfigManager;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
@Log4j2
|
||||
public class CredentialsDecoder {
|
||||
|
||||
public static String decodeCredentials(String credentials, String pkFile) {
|
||||
public static String decodeCredentials(String credentials) {
|
||||
if (credentials == null || credentials.isEmpty()) {
|
||||
log.warn("No credentials provided to decode.");
|
||||
return null;
|
||||
@ -33,7 +34,7 @@ public class CredentialsDecoder {
|
||||
String transformation = jsonMap.get("t");
|
||||
log.debug("Used algorithm: {}", transformation);
|
||||
|
||||
String privateKeyPEM = new String(Files.readAllBytes(Paths.get(pkFile)))
|
||||
String privateKeyPEM = new String(Files.readAllBytes(Paths.get(ConfigManager.getInstance().getConfig().getSource().getSecretsDecryptionCert())))
|
||||
.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "")
|
||||
.replaceAll("\\s+", "");
|
||||
byte[] privateKeyBytes = Base64.getDecoder().decode(privateKeyPEM);
|
||||
|
||||
@ -1,23 +1,24 @@
|
||||
proxy:
|
||||
host: proxy.jtfg.com
|
||||
port: 3128
|
||||
#proxy:
|
||||
# host: proxy.jtfg.com
|
||||
# port: 3128
|
||||
|
||||
source:
|
||||
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
|
||||
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
|
||||
secrets_decryption_cert: wso2apim32-pk.pem
|
||||
wso2_user: YWRtaW46YWRtaW4=
|
||||
wso2_apis_dir: ./apis
|
||||
|
||||
target:
|
||||
registration_api_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/client-registration/v0.17/register
|
||||
publisher_api_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/api/am/publisher/v4/apis/import
|
||||
admin_api_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/api/am/admin/v4
|
||||
devportal_api_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/api/am/devportal
|
||||
publisher_token_url: https://wso2apiportal-int.apps.oshift-int.jtfg.com/oauth2/token
|
||||
wso2_user: YWRtaW46Tiw5YzEpeFh0NTNr
|
||||
registration_api_url: https://localhost:9443/client-registration/v0.17/register
|
||||
publisher_api_url: https://localhost:9443/api/am/publisher/v4/apis/import
|
||||
admin_api_url: https://localhost:9443/api/am/admin/v4
|
||||
devportal_api_url: https://localhost:9443/api/am/devportal
|
||||
publisher_token_url: https://localhost:9443/oauth2/token
|
||||
wso2_user: YWRtaW46YWRtaW4=
|
||||
|
||||
truststore:
|
||||
path: client-truststore.jks
|
||||
@ -28,7 +29,7 @@ patterns:
|
||||
devportal_url_pattern: https://developers/devportal/apis/{API_ID}/overview
|
||||
|
||||
apicurio:
|
||||
api_url: https://apim-apicurio-app-apim-wso2.apps.oshift-akc.jtfg.com/apis/registry/v2
|
||||
api_url: http://apicurio:8095/apis/registry/v2
|
||||
default_api_group: api
|
||||
overwrite_existing_application: true
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user