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

fix: initialize Connector without IONOS Account #84

Merged
merged 2 commits into from
Dec 20, 2024
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 @@ -66,7 +66,26 @@ public S3Regions retrieveRegions(String token) {
throw new EdcException("Error retrieving S3 accesskey", e);
}
}
public boolean verifyToken(String token) {
if(token == null || token.isEmpty())
return false;

String url = "https://api.ionos.com/cloudapi/v6/locations";

Request request = new Request.Builder().url(url)
.addHeader("Authorization", "Bearer " + token)
.get()
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
return false;

} else return response.body() != null;
} catch (IOException e) {
throw new EdcException("Error access Ionos Cloud", e);

}
}
public S3AccessKey createAccessKey(String token) {

Request request = new Request.Builder().url(ACCESS_KEYS_ENDPOINT_URL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ public S3ConnectorImpl(String regionId, @NotNull String accessKey, @NotNull Stri
this.maxFiles = maxFiles;

this.regionId = Objects.requireNonNullElse(regionId, REGION_ID_DEFAULT);
var endpoint = getEndpoint( this.regionId , token);

this.minioClient = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
if(S3ApiClient.verifyToken(token)) {
var endpoint = getEndpoint(this.regionId, token);
this.minioClient = MinioClient.builder().endpoint(endpoint).credentials(accessKey, secretKey).build();
} else {
this.minioClient = null;
}
}

@Override
Expand Down