Skip to content

Commit

Permalink
fix: merge conflict (#8)
Browse files Browse the repository at this point in the history
* Migrating to EDC 0.7.2 (Digital-Ecosystems#77)

* feat: migrating to edc 0.7.3

* feat: migrating to edc 0.7.2

* feat: migrating to edc 0.7.2

* feat: migrating to edc 0.7.2

* feat: migrating to edc 0.7.2

* feat: migrating to edc 0.7.2

* Fixing connector-persistente to EDC 0.7.2 (Digital-Ecosystems#78)

* feat: migrating to edc 0.7.3

* feat: migrating to edc 0.7.2

* feat: migrating to edc 0.7.2

* feat: migrating to edc 0.7.2

* feat: migrating to edc 0.7.2

* feat: migrating to edc 0.7.2

* feat: migrating to edc 0.7.2

* S3 Endpoint Regions Validation (Digital-Ecosystems#79)

* feat: s3 endpoint regions validation

* chore: fixing assets doc

* fix: launchers config

* fix: regions endpoint signature changes (Digital-Ecosystems#81)

Co-authored-by: Glaucio Jannotti <[email protected]>

* fix: initialize Connector without IONOS Account (Digital-Ecosystems#84)

* fix: initialize Connector without IONOS Account

* fix: verify if token is null or empty

* Update README.md

---------

Co-authored-by: Glaucio Jannotti <[email protected]>
Co-authored-by: Glaucio Jannotti <[email protected]>
Co-authored-by: Paulo Cabrita <[email protected]>
  • Loading branch information
4 people authored Jan 6, 2025
1 parent cb4e6b8 commit 08058ef
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Please refer to the official [site](https://github.com/ionos-cloud/edc-ionos-s3)

## Based on the following

- [https://github.com/eclipse-dataspaceconnector/DataSpaceConnector](https://github.com/eclipse-dataspaceconnector/DataSpaceConnector) - v0.4.1;
- [https://github.com/eclipse-dataspaceconnector/DataSpaceConnector](https://github.com/eclipse-dataspaceconnector/DataSpaceConnector) - v0.7.2;
- [International Data Spaces](https://www.internationaldataspaces.org);
- [GAIA-X](https://gaia-x.eu) project;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ public S3Regions retrieveRegions(String token) {
}
}

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 Expand Up @@ -86,7 +89,7 @@ public void uploadObject(String bucketName, String objectName, ByteArrayInputStr
if (!bucketExists(bucketName.toLowerCase())) {
createBucket(bucketName.toLowerCase());
}

try {
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName.toLowerCase())
Expand Down Expand Up @@ -161,10 +164,10 @@ public List<S3Object> listObjects(String bucketName, String objectName) {
.map(item -> new S3Object(item.objectName(), item.size()))
.collect(Collectors.toList());
}

@Override
public S3AccessKey createAccessKey() {
try{
try{
return S3ApiClient.createAccessKey(token);
} catch (Exception e) {
throw new EdcException("Error creating access key", e);
Expand All @@ -179,15 +182,15 @@ public S3AccessKey retrieveAccessKey(String keyID) {
throw new EdcException("Error retrieving access key", e);
}
}
@Override
public void deleteAccessKey(String keyID) {

@Override
public void deleteAccessKey(String keyID) {
try{
S3ApiClient.deleteAccessKey(token, keyID);
} catch (Exception e) {
throw new EdcException("Error deleting access key", e);
}
}
}

private String getEndpoint(String regionId, String token) {
var regions = S3ApiClient.retrieveRegions(token);
Expand All @@ -204,4 +207,4 @@ private String getEndpoint(String regionId, String token) {
public S3Connector clone(String region, String accessKey, String secretKey) {
return new S3ConnectorImpl(region, accessKey, secretKey, this.token, this.maxFiles);
}
}
}
11 changes: 8 additions & 3 deletions launchers/dev/connector-consumer/resources/config.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
edc.participant.id=consumer
edc.dsp.callback.address=http://localhost:9292/protocol
web.http.port=9191
web.http.path=/api
web.http.management.port=9192
Expand All @@ -10,13 +9,19 @@ web.http.control.port=9293
web.http.control.path=/control
web.http.public.port=9393
web.http.public.path=/public
edc.dsp.callback.address=http://localhost:9292/protocol
edc.dataplane.token.validation.endpoint=http://localhost:9293/control/token
edc.dataplane.api.public.baseurl=http://localhost:9393/public

edc.api.auth.key=password
edc.transfer.proxy.token.signer.privatekey.alias=edc.connector.private.key
edc.transfer.proxy.token.verifier.publickey.alias=edc.connector.public.key

edc.vault.hashicorp.url=http://localhost:8200
edc.vault.hashicorp.token=test-token
edc.vault.hashicorp.timeout.seconds=30

edc.ionos.access.key=<YOUR S3 KEY>
edc.ionos.secret.key=<YOUR S3 KEY SECRET>
edc.ionos.endpoint=https://s3-eu-central-1.ionoscloud.com
edc.ionos.token=<IONOS-TOKEN>
edc.ionos.endpoint.region=<IONOS ENDPOINT REGION>
edc.ionos.token=<IONOS API TOKEN>

0 comments on commit 08058ef

Please sign in to comment.