Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.12.19 #130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -131,22 +130,6 @@ public DelegationResponse executeQueryRemote(String remoteUrl, String skill, Str

}

/**
* URL Validation
*
* @param url URL string for validation
* @return Returns true if the URL is valid, false otherwise.
*/
public static boolean isValid(String url) {
// Try creating a valid URL
try {
new URI(url).toURL();
return true;
} catch (Exception e) { // If there was an Exception while creating URL object
return false;
}
}

/**
* route a get request
*
Expand All @@ -160,7 +143,7 @@ public DelegationResponse sendGetRequest(EndpointDataReference dataReference, St

monitor.debug(String.format("About to delegate GET %s", url));

if (isValid(url.toString())) {
if (Pattern.matches("(http|edc)s?://.*", url.toString())) {

var requestBuilder = new okhttp3.Request.Builder()
.url(url);
Expand Down Expand Up @@ -193,7 +176,7 @@ public DelegationResponse sendPostRequest(EndpointDataReference dataReference, S

monitor.debug(String.format("About to delegate POST %s with content type %s", url, contentType));

if (isValid(url.toString())) {
if (Pattern.matches("(http|edc)s?://.*", url.toString())) {

var requestBuilder = new okhttp3.Request.Builder()
.url(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
import org.eclipse.tractusx.agents.utils.TypeManager;

import java.io.IOException;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;

import static java.lang.String.format;

Expand Down Expand Up @@ -426,34 +426,17 @@ public IdResponse createOrUpdateGraph(String assetId, String name, String descri
return createOrUpdateAsset(assetId, assetSpec);
}

/**
* URL Validation
*
* @param url URL string for validation
* @return Returns true if the URL is valid, false otherwise.
*/
public static boolean isValid(String url) {
// Try creating a valid URL
try {
new URI(url).toURL();
return true;
} catch (Exception e) { // If there was an Exception while creating URL object
return false;
}
}

/**
* deletes an existing aseet
*
* @param assetId key of the asset
* @return idresponse
*/

public IdResponse deleteAsset(String assetId) throws IOException {
String version = "/v3";
var url = String.format(ASSET_UPDATE_CALL, config.getControlPlaneManagementProviderUrl(), version, assetId);

if (isValid(url)) {
if (Pattern.matches("(http|edc)s?://.*", url)) {
var request = new Request.Builder().url(url).delete();
config.getControlPlaneManagementHeaders().forEach(request::addHeader);
try (var response = httpClient.newCall(request.build()).execute()) {
Expand Down
Loading