Search in sources :

Example 1 with S3Setup

use of com.mercedesbenz.sechub.storage.core.S3Setup in project sechub by mercedes-benz.

the class S3RealLiveStorageTestMain method main.

public static void main(String[] args) throws IOException {
    /* setup */
    SharedVolumeSetup setup = createFakeSharedVolumeNotValid();
    S3Setup s3Setup = createS3SetupByEnvironmentVariables();
    MultiStorageService service = new MultiStorageService(setup, s3Setup);
    UUID jobUUID = UUID.randomUUID();
    JobStorage jobStorage = service.getJobStorage("test-only", jobUUID);
    /* check preconditions */
    boolean existsBefore = jobStorage.isExisting(S3_OBJECT_NAME);
    String testDataAsString = "This is some test data as a simple string\nJust another line...";
    /* store */
    jobStorage.store(S3_OBJECT_NAME, new StringInputStream(testDataAsString));
    boolean existsAfterStore = jobStorage.isExisting(S3_OBJECT_NAME);
    /* fetch */
    InputStream inputStream = jobStorage.fetch(S3_OBJECT_NAME);
    InputStreamReader reader = new InputStreamReader(inputStream);
    BufferedReader br = new BufferedReader(reader);
    String result = br.readLine();
    br.close();
    /* delete all */
    jobStorage.deleteAll();
    /* check delete done */
    boolean existsAfterDelete = jobStorage.isExisting(S3_OBJECT_NAME);
    System.out.println("exists before storage:" + existsBefore);
    System.out.println("exists after storage:" + existsAfterStore);
    System.out.println("fetched string from object store:" + result);
    System.out.println("exists after delete:" + existsAfterDelete);
    if (existsBefore) {
        System.err.println("existed before!");
        System.exit(1);
    }
    if (!existsAfterStore) {
        System.err.println("was not stored!");
        System.exit(1);
    }
    if (!testDataAsString.equals(result)) {
        System.err.println("result was not as expected:" + result);
        System.exit(1);
    }
    if (existsAfterDelete) {
        System.err.println("data was not as expected:" + result);
        System.exit(1);
    }
}
Also used : S3Setup(com.mercedesbenz.sechub.storage.core.S3Setup) MultiStorageService(com.mercedesbenz.sechub.sharedkernel.storage.MultiStorageService) StringInputStream(com.amazonaws.util.StringInputStream) InputStreamReader(java.io.InputStreamReader) SharedVolumeSetup(com.mercedesbenz.sechub.storage.core.SharedVolumeSetup) StringInputStream(com.amazonaws.util.StringInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) UUID(java.util.UUID) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage)

Example 2 with S3Setup

use of com.mercedesbenz.sechub.storage.core.S3Setup in project sechub by mercedes-benz.

the class S3RealLiveStorageTestMain method createS3SetupByEnvironmentVariables.

private static S3Setup createS3SetupByEnvironmentVariables() {
    String bucketURL = System.getenv("S3_ENDPOINT");
    if (bucketURL == null || bucketURL.isEmpty()) {
        throw new IllegalStateException("S3_ENDPOINT missing");
    }
    String bucketAccessKey = System.getenv("S3_ACCESSKEY");
    if (bucketAccessKey == null || bucketAccessKey.isEmpty()) {
        throw new IllegalStateException("S3_ACCESSKEY missing");
    }
    String bucketSecretKey = System.getenv("S3_SECRETKEY");
    if (bucketSecretKey == null || bucketSecretKey.isEmpty()) {
        throw new IllegalStateException("S3_SECRETKEY missing");
    }
    String bucketName = System.getenv("S3_BUCKET_NAME");
    if (bucketName == null || bucketName.isEmpty()) {
        throw new IllegalStateException("S3_BUCKET_NAME missing");
    }
    S3Setup s3Setup = new S3Setup() {

        @Override
        public String getAccessKey() {
            return bucketAccessKey;
        }

        @Override
        public String getSecretkey() {
            return bucketSecretKey;
        }

        @Override
        public String getEndPoint() {
            return bucketURL;
        }

        @Override
        public String getBucketName() {
            return bucketName;
        }

        @Override
        public boolean isAvailable() {
            return true;
        }
    };
    return s3Setup;
}
Also used : S3Setup(com.mercedesbenz.sechub.storage.core.S3Setup)

Example 3 with S3Setup

use of com.mercedesbenz.sechub.storage.core.S3Setup in project sechub by mercedes-benz.

the class S3RealLiveStorageManualTest method createS3SetupByEnvironmentVariables.

private static S3Setup createS3SetupByEnvironmentVariables() {
    String bucketURL = System.getenv("S3_ENDPOINT");
    if (bucketURL == null || bucketURL.isEmpty()) {
        throw new IllegalStateException("S3_ENDPOINT missing");
    }
    String bucketAccessKey = System.getenv("S3_ACCESSKEY");
    if (bucketAccessKey == null || bucketAccessKey.isEmpty()) {
        throw new IllegalStateException("S3_ACCESSKEY missing");
    }
    String bucketSecretKey = System.getenv("S3_SECRETKEY");
    if (bucketSecretKey == null || bucketSecretKey.isEmpty()) {
        throw new IllegalStateException("S3_SECRETKEY missing");
    }
    String bucketName = System.getenv("S3_BUCKET_NAME");
    if (bucketName == null || bucketName.isEmpty()) {
        throw new IllegalStateException("S3_BUCKET_NAME missing");
    }
    S3Setup s3Setup = new S3Setup() {

        @Override
        public String getAccessKey() {
            return bucketAccessKey;
        }

        @Override
        public String getSecretkey() {
            return bucketSecretKey;
        }

        @Override
        public String getEndPoint() {
            return bucketURL;
        }

        @Override
        public String getBucketName() {
            return bucketName;
        }

        @Override
        public boolean isAvailable() {
            return true;
        }
    };
    return s3Setup;
}
Also used : S3Setup(com.mercedesbenz.sechub.storage.core.S3Setup)

Example 4 with S3Setup

use of com.mercedesbenz.sechub.storage.core.S3Setup in project sechub by mercedes-benz.

the class S3RealLiveStorageManualTest method manualTestByDeveloper.

@Test
@EnabledIfSystemProperty(named = TestConstants.MANUAL_TEST_BY_DEVELOPER, matches = "true", disabledReason = TestConstants.DESCRIPTION_DISABLED_BECAUSE_A_MANUAL_TEST_FOR_GENERATION)
void manualTestByDeveloper() throws Exception {
    /* setup */
    SharedVolumeSetup setup = createFakeSharedVolumeNotValid();
    S3Setup s3Setup = createS3SetupByEnvironmentVariables();
    MultiStorageService service = new MultiStorageService(setup, s3Setup);
    UUID jobUUID = UUID.randomUUID();
    JobStorage jobStorage = service.getJobStorage("test-only", jobUUID);
    /* check preconditions */
    boolean existsBefore = jobStorage.isExisting(S3_OBJECT_NAME);
    String testDataAsString = "This is some test data as a simple string\nJust another line...";
    /* store */
    jobStorage.store(S3_OBJECT_NAME, new StringInputStream(testDataAsString));
    boolean existsAfterStore = jobStorage.isExisting(S3_OBJECT_NAME);
    /* fetch */
    InputStream inputStream = jobStorage.fetch(S3_OBJECT_NAME);
    InputStreamReader reader = new InputStreamReader(inputStream);
    BufferedReader br = new BufferedReader(reader);
    String result = br.readLine();
    br.close();
    /* delete all */
    jobStorage.deleteAll();
    /* check delete done */
    boolean existsAfterDelete = jobStorage.isExisting(S3_OBJECT_NAME);
    System.out.println("exists before storage:" + existsBefore);
    System.out.println("exists after storage:" + existsAfterStore);
    System.out.println("fetched string from object store:" + result);
    System.out.println("exists after delete:" + existsAfterDelete);
    if (existsBefore) {
        System.err.println("existed before!");
        System.exit(1);
    }
    if (!existsAfterStore) {
        System.err.println("was not stored!");
        System.exit(1);
    }
    if (!testDataAsString.equals(result)) {
        System.err.println("result was not as expected:" + result);
        System.exit(1);
    }
    if (existsAfterDelete) {
        System.err.println("data was not as expected:" + result);
        System.exit(1);
    }
}
Also used : S3Setup(com.mercedesbenz.sechub.storage.core.S3Setup) MultiStorageService(com.mercedesbenz.sechub.sharedkernel.storage.MultiStorageService) StringInputStream(com.amazonaws.util.StringInputStream) InputStreamReader(java.io.InputStreamReader) SharedVolumeSetup(com.mercedesbenz.sechub.storage.core.SharedVolumeSetup) StringInputStream(com.amazonaws.util.StringInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) UUID(java.util.UUID) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) EnabledIfSystemProperty(org.junit.jupiter.api.condition.EnabledIfSystemProperty) Test(org.junit.jupiter.api.Test)

Aggregations

S3Setup (com.mercedesbenz.sechub.storage.core.S3Setup)4 StringInputStream (com.amazonaws.util.StringInputStream)2 MultiStorageService (com.mercedesbenz.sechub.sharedkernel.storage.MultiStorageService)2 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)2 SharedVolumeSetup (com.mercedesbenz.sechub.storage.core.SharedVolumeSetup)2 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)1 EnabledIfSystemProperty (org.junit.jupiter.api.condition.EnabledIfSystemProperty)1