working app migration
This commit is contained in:
parent
bc0c364a8f
commit
f134f6a03f
@ -20,16 +20,7 @@ import cz.trask.migration.AbstractProcess;
|
||||
import cz.trask.migration.model.HttpResponse;
|
||||
import cz.trask.migration.model.TokenResponse;
|
||||
import cz.trask.migration.model.v32.ApplicationDetail;
|
||||
<<<<<<< HEAD
|
||||
import cz.trask.migration.model.v45.ApplicationDetail45;
|
||||
=======
|
||||
import cz.trask.migration.model.v32.ApplicationDetail.KeyManagerApp;
|
||||
import cz.trask.migration.model.v45.ApplicationCreateRequest;
|
||||
import cz.trask.migration.model.v45.ApplicationCreateResponse;
|
||||
import cz.trask.migration.model.v45.ApplicationKeyMappingRequest45;
|
||||
import cz.trask.migration.model.v45.ApplicationKeyMappingResponse45;
|
||||
import cz.trask.migration.model.v45.ApplicationListResponse45;
|
||||
>>>>>>> branch 'main' of https://gitea.kamma.cz/kamma/apicurio-migration-tool.git
|
||||
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
|
||||
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
|
||||
import io.apicurio.registry.rest.v2.beans.SearchedArtifact;
|
||||
@ -130,7 +121,6 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
||||
fos.close();
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
if (data != null && data.length > 0 && fileName != null && !fileName.isEmpty()) {
|
||||
int responseCode = publishAppToWso2(fileName, data, tokenResponse);
|
||||
if (responseCode == 200 || responseCode == 201) {
|
||||
@ -138,59 +128,6 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
||||
} else {
|
||||
log.warn(" - Application {} import failed with response code: {}", appDetail.getName(),
|
||||
responseCode);
|
||||
=======
|
||||
ApplicationCreateRequest appCreateRequest = mapAppDetailToCreateRequest(appDetail);
|
||||
byte[] data = mapper.writeValueAsBytes(appCreateRequest);
|
||||
log.info(" - Application {} with owner {} prepared for WSO2 export", appDetail.getName(),
|
||||
appDetail.getOwner());
|
||||
|
||||
deleteWso2ApplicationIfExists(appDetail, tokenResponse);
|
||||
|
||||
HttpResponse response = publishAppToWso2(appDetail.getName(), data, tokenResponse);
|
||||
|
||||
if (response.getResponseCode() == 200 || response.getResponseCode() == 201) {
|
||||
log.info(" - Application {} imported successfully", appDetail.getName());
|
||||
|
||||
ApplicationCreateResponse createdApp = mapper.readValue(response.getResponse(),
|
||||
ApplicationCreateResponse.class);
|
||||
log.info(" - Created Application ID in WSO2: {}", createdApp.getApplicationId());
|
||||
|
||||
if (appDetail.getKeyManagerWiseOAuthApp() != null
|
||||
&& !appDetail.getKeyManagerWiseOAuthApp().isEmpty()) {
|
||||
log.info(" - Application {} has {} Key Mappings to create", appDetail.getName(),
|
||||
appDetail.getKeyManagerWiseOAuthApp().size());
|
||||
for (Entry<String, Map<String, KeyManagerApp>> entry : appDetail.getKeyManagerWiseOAuthApp()
|
||||
.entrySet()) {
|
||||
String keyType = entry.getKey();
|
||||
|
||||
Map<String, KeyManagerApp> keyManagerApp = entry.getValue();
|
||||
|
||||
for (Entry<String, KeyManagerApp> kmEntry : keyManagerApp.entrySet()) {
|
||||
String keyManager = kmEntry.getKey();
|
||||
KeyManagerApp oauthInfo = kmEntry.getValue();
|
||||
|
||||
log.info(" - Creating Key Mapping for Key Manager: {}", keyManager);
|
||||
// Map to v4.5 request
|
||||
ApplicationKeyMappingRequest45 keyMappingRequest = ApplicationKeyMappingRequest45
|
||||
.builder().consumerKey(oauthInfo.getClientId())
|
||||
.consumerSecret(oauthInfo.getClientSecret()).keyManager(keyManager)
|
||||
.keyType(ApplicationKeyMappingRequest45.KeyType.valueOf(keyType)).build();
|
||||
|
||||
byte[] kmData = mapper.writeValueAsBytes(keyMappingRequest);
|
||||
publishApplicationKeyMappingToWso2(createdApp.getApplicationId(), kmData,
|
||||
tokenResponse);
|
||||
|
||||
ApplicationKeyMappingResponse45 appKeys = generateKeysForApplication(createdApp.getApplicationId(), keyType, keyManager);
|
||||
|
||||
if (appKeys != null && appKeys.getKeyMappingId() != null) {
|
||||
byte[] kmData2 = mapper.writeValueAsBytes(keyMappingRequest);
|
||||
publishApplicationKeyMappingToWso2(createdApp.getApplicationId(), kmData2,
|
||||
tokenResponse);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
>>>>>>> branch 'main' of https://gitea.kamma.cz/kamma/apicurio-migration-tool.git
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,47 +137,7 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
public byte[] prepareAppZipFile32to45(ApplicationDetail45 yamlApp) throws Exception {
|
||||
=======
|
||||
private ApplicationKeyMappingResponse45 generateKeysForApplication(String applicationId, String keyType, String keyManager) {
|
||||
try {
|
||||
String endpoint = config.getTarget().getDevPortalApiUrl() + "/v3/applications/" + applicationId
|
||||
+ "/generate-keys";
|
||||
|
||||
Map<String, String> httpHeaders = createBearerAuthHeaders(
|
||||
authenticateToWso2AndGetToken(config.getTarget()));
|
||||
httpHeaders.put("Content-Type", "application/json");
|
||||
|
||||
Map<String, Object> keyGenRequest = new HashMap<>();
|
||||
keyGenRequest.put("keyType", keyType);
|
||||
keyGenRequest.put("keyManager", keyManager);
|
||||
keyGenRequest.put("grantTypesToBeSupported", List.of("client_credentials","password"));
|
||||
|
||||
byte[] requestData = mapper.writeValueAsBytes(keyGenRequest);
|
||||
|
||||
HttpResponse response = makeDataRequest(endpoint, httpHeaders, requestData);
|
||||
|
||||
if (response.getResponseCode() == 200 || response.getResponseCode() == 201) {
|
||||
log.info(" - Keys generated successfully for Application {}", applicationId);
|
||||
return mapper.readValue(response.getResponse(), ApplicationKeyMappingResponse45.class);
|
||||
} else {
|
||||
log.warn(" - Key generation for Application {} failed with response code {}", applicationId,
|
||||
response.getResponseCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("IO error while generating keys for Application {}: {}", applicationId, e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void publishApplicationKeyMappingToWso2(String applicationId, byte[] kmData, TokenResponse tokenResponse) {
|
||||
try {
|
||||
// Publish the application key mapping data to WSO2
|
||||
Map<String, String> httpHeaders = createBearerAuthHeaders(tokenResponse);
|
||||
httpHeaders.put("Content-Type", "application/json");
|
||||
>>>>>>> branch 'main' of https://gitea.kamma.cz/kamma/apicurio-migration-tool.git
|
||||
|
||||
String baseDir = yamlApp.getData().getApplicationInfo().getOwner() + "-"
|
||||
+ yamlApp.getData().getApplicationInfo().getName() + "/";
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user