change owner draft
This commit is contained in:
parent
c15d12de91
commit
a1eb3cce42
@ -28,10 +28,10 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
|
|||||||
import cz.trask.migration.config.ConfigManager;
|
import cz.trask.migration.config.ConfigManager;
|
||||||
import cz.trask.migration.model.APIList;
|
import cz.trask.migration.model.APIList;
|
||||||
import cz.trask.migration.model.ApplicationConfig;
|
import cz.trask.migration.model.ApplicationConfig;
|
||||||
|
import cz.trask.migration.model.ApplicationConfig.Wso2Endpoints;
|
||||||
import cz.trask.migration.model.HttpResponse;
|
import cz.trask.migration.model.HttpResponse;
|
||||||
import cz.trask.migration.model.RegisterResponse;
|
import cz.trask.migration.model.RegisterResponse;
|
||||||
import cz.trask.migration.model.TokenResponse;
|
import cz.trask.migration.model.TokenResponse;
|
||||||
import cz.trask.migration.model.ApplicationConfig.Wso2Endpoints;
|
|
||||||
import io.apicurio.registry.rest.client.RegistryClient;
|
import io.apicurio.registry.rest.client.RegistryClient;
|
||||||
import io.apicurio.registry.rest.client.RegistryClientFactory;
|
import io.apicurio.registry.rest.client.RegistryClientFactory;
|
||||||
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
|
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
|
||||||
@ -241,10 +241,12 @@ public abstract class AbstractProcess {
|
|||||||
|
|
||||||
log.info("Calling URL: " + urlStr);
|
log.info("Calling URL: " + urlStr);
|
||||||
String query = "";
|
String query = "";
|
||||||
|
if (params != null) {
|
||||||
for (String key : params.keySet()) {
|
for (String key : params.keySet()) {
|
||||||
query = query.concat(URLEncoder.encode(key, "UTF-8")).concat("=")
|
query = query.concat(URLEncoder.encode(key, "UTF-8")).concat("=")
|
||||||
.concat(URLEncoder.encode(params.get(key), "UTF-8")).concat("&");
|
.concat(URLEncoder.encode(params.get(key), "UTF-8")).concat("&");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (query.length() > 1 && "GET".equals(method)) {
|
if (query.length() > 1 && "GET".equals(method)) {
|
||||||
urlStr = urlStr.concat("?").concat(query);
|
urlStr = urlStr.concat("?").concat(query);
|
||||||
@ -332,7 +334,20 @@ public abstract class AbstractProcess {
|
|||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
InputStream in = con.getInputStream();
|
InputStream in;
|
||||||
|
|
||||||
|
try {
|
||||||
|
in = con.getInputStream();
|
||||||
|
} catch (Exception e) {
|
||||||
|
in = con.getErrorStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in == null) {
|
||||||
|
HttpResponse resp = new HttpResponse();
|
||||||
|
resp.setHeaders(con.getHeaderFields());
|
||||||
|
resp.setResponseCode(con.getResponseCode());
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
|
||||||
String res = "";
|
String res = "";
|
||||||
byte[] buf = new byte[4096];
|
byte[] buf = new byte[4096];
|
||||||
|
|||||||
@ -14,6 +14,7 @@ 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;
|
||||||
import cz.trask.migration.model.v45.ApplicationCreateRequest;
|
import cz.trask.migration.model.v45.ApplicationCreateRequest;
|
||||||
|
import cz.trask.migration.model.v45.ApplicationCreateResponse;
|
||||||
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;
|
||||||
@ -102,12 +103,21 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
|||||||
HttpResponse response = makeDataRequest(endpoint, httpHeaders, data);
|
HttpResponse response = makeDataRequest(endpoint, httpHeaders, data);
|
||||||
|
|
||||||
if (response.getResponseCode() == 200 || response.getResponseCode() == 201) {
|
if (response.getResponseCode() == 200 || response.getResponseCode() == 201) {
|
||||||
log.info(" - Application version {} imported successfully", ver.getVersion());
|
log.info(" - Application {} imported successfully", appDetail.getName());
|
||||||
} else {
|
|
||||||
log.warn(" - Application version {} import failed with response code {}",
|
ApplicationCreateResponse createdApp = mapper.readValue(response.getResponse(),
|
||||||
ver.getVersion(), response.getResponseCode());
|
ApplicationCreateResponse.class);
|
||||||
|
log.info(" - Created Application ID in WSO2: {}", createdApp.getApplicationId());
|
||||||
|
|
||||||
|
if (!createdApp.getOwner().equals(appDetail.getOwner())) {
|
||||||
|
log.info(" - Changing owner of Application {} to {}", createdApp.getApplicationId(),
|
||||||
|
appDetail.getOwner());
|
||||||
|
changeApplicationOwner(createdApp, appDetail.getOwner(), tokenResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (response.getResponseCode() == 409) {
|
||||||
|
log.warn(" - Application {} already exists in WSO2, skipping import", appDetail.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// String fileName = api.getName() + "-" + ver.getVersion() + ".zip";
|
// String fileName = api.getName() + "-" + ver.getVersion() + ".zip";
|
||||||
@ -138,6 +148,30 @@ public class ExportAppsToWso2FromV32 extends AbstractProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void changeApplicationOwner(ApplicationCreateResponse createdApp, String origOwner,
|
||||||
|
TokenResponse tokenResponse) {
|
||||||
|
String endpoint = config.getTarget().getAdminApiUrl() + "/applications/" + createdApp.getApplicationId()
|
||||||
|
+ "/change-owner?owner=" + origOwner;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Map<String, String> httpHeaders = new HashMap<>();
|
||||||
|
httpHeaders.put("Authorization", "Bearer ".concat(tokenResponse.getAccess_token()));
|
||||||
|
|
||||||
|
HttpResponse response = makeRequest("POST", endpoint, httpHeaders, null);
|
||||||
|
|
||||||
|
if (response.getResponseCode() == 200 || response.getResponseCode() == 201) {
|
||||||
|
log.info(" - Application {} owner changed successfully to {}", createdApp.getApplicationId(),
|
||||||
|
origOwner);
|
||||||
|
} else {
|
||||||
|
log.warn(" - Application {} owner change to {} failed with response code {}",
|
||||||
|
createdApp.getApplicationId(), origOwner, response.getResponseCode());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("IO error while changing owner of Application {}: {}", createdApp.getApplicationId(),
|
||||||
|
e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private ApplicationCreateRequest mapAppDetailToCreateRequest(ApplicationDetail appDetail) {
|
private ApplicationCreateRequest mapAppDetailToCreateRequest(ApplicationDetail appDetail) {
|
||||||
ApplicationCreateRequest request = new ApplicationCreateRequest();
|
ApplicationCreateRequest request = new ApplicationCreateRequest();
|
||||||
request.setName(appDetail.getName());
|
request.setName(appDetail.getName());
|
||||||
|
|||||||
@ -0,0 +1,87 @@
|
|||||||
|
package cz.trask.migration.model.v45;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ApplicationCreateResponse {
|
||||||
|
@JsonProperty("applicationId")
|
||||||
|
private String applicationId;
|
||||||
|
|
||||||
|
@JsonProperty("name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@JsonProperty("throttlingPolicy")
|
||||||
|
private String throttlingPolicy;
|
||||||
|
|
||||||
|
@JsonProperty("description")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@JsonProperty("tokenType")
|
||||||
|
private String tokenType = "JWT";
|
||||||
|
|
||||||
|
@JsonProperty("status")
|
||||||
|
private String status = "";
|
||||||
|
|
||||||
|
@JsonProperty("groups")
|
||||||
|
private List<String> groups;
|
||||||
|
|
||||||
|
@JsonProperty("subscriptionCount")
|
||||||
|
private Integer subscriptionCount;
|
||||||
|
|
||||||
|
@JsonProperty("keys")
|
||||||
|
private List<ApplicationKey> keys;
|
||||||
|
|
||||||
|
@JsonProperty("attributes")
|
||||||
|
private Map<String, Object> attributes;
|
||||||
|
|
||||||
|
@JsonProperty("subscriptionScopes")
|
||||||
|
private List<SubscriptionScope> subscriptionScopes;
|
||||||
|
|
||||||
|
@JsonProperty("owner")
|
||||||
|
private String owner;
|
||||||
|
|
||||||
|
@JsonProperty("hashEnabled")
|
||||||
|
private Boolean hashEnabled;
|
||||||
|
|
||||||
|
@JsonProperty("createdTime")
|
||||||
|
private String createdTime;
|
||||||
|
|
||||||
|
@JsonProperty("updatedTime")
|
||||||
|
private String updatedTime;
|
||||||
|
|
||||||
|
@JsonProperty("visibility")
|
||||||
|
private String visibility;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class ApplicationKey {
|
||||||
|
@JsonProperty("key")
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
@JsonProperty("keyType")
|
||||||
|
private String keyType;
|
||||||
|
|
||||||
|
@JsonProperty("state")
|
||||||
|
private String state;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class SubscriptionScope {
|
||||||
|
@JsonProperty("name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@JsonProperty("description")
|
||||||
|
private String description;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@ source:
|
|||||||
target:
|
target:
|
||||||
registration_api_url: https://localhost:9443/client-registration/v0.17/register
|
registration_api_url: https://localhost:9443/client-registration/v0.17/register
|
||||||
publisher_api_url: https://localhost:9443/api/am/publisher/v4/apis/import
|
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
|
devportal_api_url: https://localhost:9443/api/am/devportal
|
||||||
publisher_token_url: https://localhost:9443/oauth2/token
|
publisher_token_url: https://localhost:9443/oauth2/token
|
||||||
wso2_user: YWRtaW46YWRtaW4=
|
wso2_user: YWRtaW46YWRtaW4=
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user