Merge branch 'main' of
https://gitea.kamma.cz/kamma/apicurio-migration-tool.git into main
This commit is contained in:
commit
bc0c364a8f
@ -20,7 +20,16 @@ import cz.trask.migration.AbstractProcess;
|
|||||||
import cz.trask.migration.model.HttpResponse;
|
import cz.trask.migration.model.HttpResponse;
|
||||||
import cz.trask.migration.model.TokenResponse;
|
import cz.trask.migration.model.TokenResponse;
|
||||||
import cz.trask.migration.model.v32.ApplicationDetail;
|
import cz.trask.migration.model.v32.ApplicationDetail;
|
||||||
|
<<<<<<< HEAD
|
||||||
import cz.trask.migration.model.v45.ApplicationDetail45;
|
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.ArtifactMetaData;
|
||||||
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
|
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
|
||||||
import io.apicurio.registry.rest.v2.beans.SearchedArtifact;
|
import io.apicurio.registry.rest.v2.beans.SearchedArtifact;
|
||||||
@ -121,6 +130,7 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
|||||||
fos.close();
|
fos.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
if (data != null && data.length > 0 && fileName != null && !fileName.isEmpty()) {
|
if (data != null && data.length > 0 && fileName != null && !fileName.isEmpty()) {
|
||||||
int responseCode = publishAppToWso2(fileName, data, tokenResponse);
|
int responseCode = publishAppToWso2(fileName, data, tokenResponse);
|
||||||
if (responseCode == 200 || responseCode == 201) {
|
if (responseCode == 200 || responseCode == 201) {
|
||||||
@ -128,6 +138,59 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
|||||||
} else {
|
} else {
|
||||||
log.warn(" - Application {} import failed with response code: {}", appDetail.getName(),
|
log.warn(" - Application {} import failed with response code: {}", appDetail.getName(),
|
||||||
responseCode);
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +200,46 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
public byte[] prepareAppZipFile32to45(ApplicationDetail45 yamlApp) throws Exception {
|
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() + "-"
|
String baseDir = yamlApp.getData().getApplicationInfo().getOwner() + "-"
|
||||||
+ yamlApp.getData().getApplicationInfo().getName() + "/";
|
+ yamlApp.getData().getApplicationInfo().getName() + "/";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user