-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add Azure Blob data plane packages * formatting/checkstyle * small test runtime simplification * add test step for dataplane tests * DEPENDENCIES * pr remarks - formatting * pr remarks - constants
- Loading branch information
1 parent
b17cbc0
commit 3ac36f1
Showing
21 changed files
with
1,682 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
edc-tests/edc-dataplane/cloud-transfer-tests/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
|
||
testImplementation(project(":edc-tests:e2e-tests")) | ||
testImplementation(libs.edc.junit) | ||
testImplementation(libs.restAssured) | ||
|
||
// test runtime config | ||
testImplementation(libs.edc.config.filesystem) | ||
testImplementation(libs.edc.dpf.http) | ||
testImplementation(libs.edc.auth.tokenbased) | ||
testImplementation(libs.testcontainers.junit) | ||
testImplementation(testFixtures(libs.edc.azure.test)) | ||
testImplementation(libs.edc.aws.s3.core) | ||
testImplementation(testFixtures(libs.edc.aws.s3.test)) | ||
testImplementation(libs.aws.s3) | ||
testImplementation(libs.aws.s3transfer) | ||
} | ||
|
||
|
||
|
95 changes: 95 additions & 0 deletions
95
...tests/src/test/java/org/eclipse/tractusx/edc/dataplane/transfer/test/AzureBlobHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.dataplane.transfer.test; | ||
|
||
import com.azure.storage.blob.BlobContainerClient; | ||
import com.azure.storage.blob.BlobServiceClient; | ||
import com.azure.storage.blob.models.BlobItem; | ||
import com.azure.storage.blob.sas.BlobContainerSasPermission; | ||
import com.azure.storage.blob.sas.BlobServiceSasSignatureValues; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.time.OffsetDateTime; | ||
import java.util.List; | ||
|
||
import static org.eclipse.edc.azure.testfixtures.TestFunctions.getBlobServiceClient; | ||
|
||
/** | ||
* Helper class that internally uses Azure SDK classes to create containers, upload blobs, generate SAS tokens, etc. | ||
*/ | ||
public class AzureBlobHelper { | ||
private final String accountName; | ||
private final String key; | ||
private final String host; | ||
private final int port; | ||
private BlobServiceClient blobServiceClient; | ||
|
||
public AzureBlobHelper(String accountName, String key, String host, int port) { | ||
this.accountName = accountName; | ||
this.key = key; | ||
this.host = host; | ||
this.port = port; | ||
} | ||
|
||
public BlobContainerClient createContainer(String containerName) { | ||
return blobClient().createBlobContainer(containerName); | ||
} | ||
|
||
private BlobServiceClient blobClient() { | ||
if (blobServiceClient == null) { | ||
var endpoint = "http://%s:%s/%s".formatted(host, port, accountName); | ||
blobServiceClient = getBlobServiceClient(accountName, key, endpoint); | ||
} | ||
return blobServiceClient; | ||
} | ||
|
||
public void uploadBlob(BlobContainerClient client, InputStream inputStream, String targetBlobName) { | ||
client.getBlobClient(targetBlobName).upload(inputStream, true); | ||
} | ||
|
||
public void uploadBlob(BlobContainerClient client, String resourceName) { | ||
try (var is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName)) { | ||
client.getBlobClient(resourceName).upload(is, true); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public List<String> listBlobs(String container) { | ||
if (blobClient().listBlobContainers().stream().noneMatch(bci -> bci.getName().equalsIgnoreCase(container))) { | ||
return List.of(); | ||
} | ||
return blobClient() | ||
.getBlobContainerClient(container) | ||
.listBlobs() | ||
.stream().map(BlobItem::getName) | ||
.toList(); | ||
} | ||
|
||
public String generateAccountSas(String containerName) { | ||
var expiry = OffsetDateTime.MAX.minusDays(1); | ||
var permissions = BlobContainerSasPermission.parse("w"); | ||
var vals = new BlobServiceSasSignatureValues(expiry, permissions); | ||
return blobClient().getBlobContainerClient(containerName).generateSas(vals); | ||
} | ||
} |
Oops, something went wrong.