S3StorageDriver implements BackupStorageDriver { String getBucketName(BackupRestoreContext ctx) throws URISyntaxException { URI uri = new URI(ctx.getExternalLocation()); LOGGER.info("URI: " + uri); if (uri.getScheme().equals(AmazonS3Client.S3_SERVICE_NAME)) { return uri.getHost(); } else { return uri.getPath().split("/")[1]; } }  @Override void upload(BackupRestoreContext ctx); @Override void uploadSchema(BackupRestoreContext ctx, String schema); @Override void download(BackupRestoreContext ctx); @Override String downloadSchema(BackupRestoreContext ctx);  }
@Test public void testGetBucketNameS3Protocol() throws URISyntaxException { String bucketName = "cassandraBackup"; BackupRestoreContext backupRestoreContext = BackupRestoreContext.create( "node-id", "name", "s3: "local-location", "account-id", "secret-key", false, "existing"); Assert.assertEquals(bucketName, s3StorageDriver.getBucketName(backupRestoreContext)); }
@Test public void testGetBucketNameHTTPSProtocol() throws URISyntaxException { String bucketName = "cassandraBackup"; BackupRestoreContext backupRestoreContext = BackupRestoreContext.create( "node-id", "name", "https: "local-location", "account-id", "secret-key", false, "existing"); Assert.assertEquals(bucketName, s3StorageDriver.getBucketName(backupRestoreContext)); }
@Test public void testGetBucketNameHTTPProtocolIPPort() throws URISyntaxException { String bucketName = "cassandraBackup"; BackupRestoreContext backupRestoreContext = BackupRestoreContext.create( "node-id", "name", "https: "local-location", "account-id", "secret-key", false, "existing"); Assert.assertEquals(bucketName, s3StorageDriver.getBucketName(backupRestoreContext)); }