Search in sources :

Example 1 with S3Protocol

use of ch.cyberduck.core.s3.S3Protocol in project cyberduck by iterate-ch.

the class InfoController method toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar.

@Override
public NSToolbarItem toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(final NSToolbar toolbar, final String identifier, final boolean flag) {
    NSToolbarItem item = super.toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(toolbar, identifier, flag);
    switch(InfoToolbarItem.valueOf(identifier)) {
        case distribution:
            if (session.getFeature(DistributionConfiguration.class) != null) {
                // Give icon and label of the given session
                item.setImage(IconCacheFactory.<NSImage>get().iconNamed(session.getHost().getProtocol().icon(), 32));
            } else {
                // CloudFront is the default for custom distributions
                item.setImage(IconCacheFactory.<NSImage>get().iconNamed(new S3Protocol().icon(), 32));
            }
            break;
        case s3:
            // Set icon of cloud service provider
            item.setLabel(session.getHost().getProtocol().getName());
            item.setImage(IconCacheFactory.<NSImage>get().iconNamed(session.getHost().getProtocol().icon(), 32));
            break;
        case metadata:
            item.setImage(IconCacheFactory.<NSImage>get().iconNamed("pencil.tiff", 32));
            break;
        case info:
            item.setImage(IconCacheFactory.<NSImage>get().iconNamed("NSInfo", 32));
            break;
        case permissions:
        case acl:
            item.setImage(IconCacheFactory.<NSImage>get().iconNamed("NSUserGroup", 32));
            break;
    }
    return item;
}
Also used : DistributionConfiguration(ch.cyberduck.core.cdn.DistributionConfiguration) S3Protocol(ch.cyberduck.core.s3.S3Protocol)

Example 2 with S3Protocol

use of ch.cyberduck.core.s3.S3Protocol in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfigurationTest method testGetOrigin.

@Test
public void testGetOrigin() throws Exception {
    final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname()));
    final CloudFrontDistributionConfiguration configuration = new CloudFrontDistributionConfiguration(session, new DisabledX509TrustManager(), new DefaultX509KeyManager());
    assertEquals("bbb.s3.amazonaws.com", configuration.getOrigin(new Path("/bbb", EnumSet.of(Path.Type.directory, Path.Type.volume)), Distribution.DOWNLOAD).getHost());
}
Also used : Path(ch.cyberduck.core.Path) DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) S3Session(ch.cyberduck.core.s3.S3Session) Host(ch.cyberduck.core.Host) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) S3Protocol(ch.cyberduck.core.s3.S3Protocol) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 3 with S3Protocol

use of ch.cyberduck.core.s3.S3Protocol in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfigurationTest method testGetName.

@Test
public void testGetName() {
    final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname()));
    final DistributionConfiguration configuration = new CloudFrontDistributionConfiguration(session, new DisabledX509TrustManager(), new DefaultX509KeyManager());
    assertEquals("Amazon CloudFront", configuration.getName());
}
Also used : DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) S3Session(ch.cyberduck.core.s3.S3Session) DistributionConfiguration(ch.cyberduck.core.cdn.DistributionConfiguration) Host(ch.cyberduck.core.Host) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) S3Protocol(ch.cyberduck.core.s3.S3Protocol) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with S3Protocol

use of ch.cyberduck.core.s3.S3Protocol in project cyberduck by iterate-ch.

the class S3SingleTransferWorkerTest method testTransferredSizeRepeat.

@Test
public void testTransferredSizeRepeat() throws Exception {
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    // Minimum multipart upload size
    final byte[] content = new byte[6 * 1024 * 1024];
    new Random().nextBytes(content);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);
    out.close();
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new S3Protocol())));
    final Profile profile = new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/S3 (HTTPS).cyberduckprofile"));
    final Host host = new Host(profile, profile.getDefaultHostname(), new Credentials(System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")));
    final AtomicBoolean failed = new AtomicBoolean();
    final S3Session session = new S3Session(host, new DefaultX509TrustManager(), new DefaultX509KeyManager()) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type == Upload.class) {
                return (T) new S3MultipartUploadService(this, new S3WriteFeature(this), 5 * 1024L * 1024L, 5) {

                    @Override
                    protected InputStream decorate(final InputStream in, final MessageDigest digest) {
                        if (failed.get()) {
                            // Second attempt successful
                            return in;
                        }
                        return new CountingInputStream(in) {

                            @Override
                            protected void beforeRead(final int n) throws IOException {
                                super.beforeRead(n);
                                if (this.getByteCount() >= 1024L * 1024L) {
                                    failed.set(true);
                                    throw new SocketTimeoutException();
                                }
                            }
                        };
                    }
                };
            }
            return super._getFeature(type);
        }
    };
    session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
    session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
    final Path test = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Transfer t = new UploadTransfer(session.getHost(), test, local);
    final BytecountStreamListener counter = new BytecountStreamListener();
    assertTrue(new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), counter, new DisabledLoginCallback(), new DisabledNotificationService()) {
    }.run(session));
    local.delete();
    assertTrue(t.isComplete());
    assertEquals(content.length, new S3AttributesFinderFeature(session).find(test).getSize());
    assertEquals(content.length, counter.getRecv(), 0L);
    assertEquals(content.length, counter.getSent(), 0L);
    assertTrue(failed.get());
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) S3AttributesFinderFeature(ch.cyberduck.core.s3.S3AttributesFinderFeature) S3MultipartUploadService(ch.cyberduck.core.s3.S3MultipartUploadService) TransferAction(ch.cyberduck.core.transfer.TransferAction) OutputStream(java.io.OutputStream) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) ProfilePlistReader(ch.cyberduck.core.serializer.impl.dd.ProfilePlistReader) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) Random(java.util.Random) MessageDigest(java.security.MessageDigest) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) S3Session(ch.cyberduck.core.s3.S3Session) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) InputStream(java.io.InputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) IOException(java.io.IOException) S3Protocol(ch.cyberduck.core.s3.S3Protocol) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) SocketTimeoutException(java.net.SocketTimeoutException) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) S3WriteFeature(ch.cyberduck.core.s3.S3WriteFeature) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) TransferItem(ch.cyberduck.core.transfer.TransferItem) DefaultX509TrustManager(ch.cyberduck.core.ssl.DefaultX509TrustManager) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) Test(org.junit.Test)

Example 5 with S3Protocol

use of ch.cyberduck.core.s3.S3Protocol in project cyberduck by iterate-ch.

the class CommandLinePathParserTest method testParse.

@Test
public void testParse() throws Exception {
    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(new Options(), new String[] {});
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Arrays.asList(new FTPTLSProtocol(), new S3Protocol())));
    factory.register(new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/FTP.cyberduckprofile")));
    factory.register(new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/FTPS.cyberduckprofile")));
    factory.register(new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/S3 (HTTPS).cyberduckprofile")));
    assertEquals(new Path("/", EnumSet.of(Path.Type.directory)), new CommandLinePathParser(input, factory).parse("ftps://u@test.cyberduck.ch/"));
    assertEquals(new Path("/d", EnumSet.of(Path.Type.directory)), new CommandLinePathParser(input, factory).parse("ftps://u@test.cyberduck.ch/d/"));
    assertEquals(new Path("/d", EnumSet.of(Path.Type.file)), new CommandLinePathParser(input, factory).parse("ftps://u@test.cyberduck.ch/d"));
    assertEquals(new Path("/", EnumSet.of(Path.Type.directory)), new CommandLinePathParser(input, factory).parse("ftps://u@test.cyberduck.ch/"));
    assertEquals(new Path("/", EnumSet.of(Path.Type.directory)), new CommandLinePathParser(input, factory).parse("ftps://u@test.cyberduck.ch"));
    assertEquals(new Path("/test.cyberduck.ch", EnumSet.of(Path.Type.directory)), new CommandLinePathParser(input, factory).parse("s3:u@test.cyberduck.ch/"));
    assertEquals(new Path("/test.cyberduck.ch", EnumSet.of(Path.Type.directory)), new CommandLinePathParser(input, factory).parse("s3:u@test.cyberduck.ch/"));
    assertEquals(new Path("/test.cyberduck.ch/d", EnumSet.of(Path.Type.directory)), new CommandLinePathParser(input, factory).parse("s3:u@test.cyberduck.ch/d/"));
    assertEquals(new Path("/test.cyberduck.ch/d", EnumSet.of(Path.Type.directory)), new CommandLinePathParser(input, factory).parse("s3://u@/test.cyberduck.ch/d/"));
    assertEquals(new Path("/test.cyberduck.ch/d", EnumSet.of(Path.Type.file)), new CommandLinePathParser(input, factory).parse("s3://u@/test.cyberduck.ch/d"));
    assertEquals(new Path("/test.cyberduck.ch/d", EnumSet.of(Path.Type.file)), new CommandLinePathParser(input, factory).parse("s3://u@/test.cyberduck.ch/d"));
    // Test bucket
    assertEquals(new Path("/test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)), new CommandLinePathParser(input, factory).parse("s3:/test.cyberduck.ch"));
}
Also used : ProtocolFactory(ch.cyberduck.core.ProtocolFactory) Path(ch.cyberduck.core.Path) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) FTPTLSProtocol(ch.cyberduck.core.ftp.FTPTLSProtocol) PosixParser(org.apache.commons.cli.PosixParser) CommandLineParser(org.apache.commons.cli.CommandLineParser) ProfilePlistReader(ch.cyberduck.core.serializer.impl.dd.ProfilePlistReader) S3Protocol(ch.cyberduck.core.s3.S3Protocol) Test(org.junit.Test)

Aggregations

S3Protocol (ch.cyberduck.core.s3.S3Protocol)29 Test (org.junit.Test)18 S3Session (ch.cyberduck.core.s3.S3Session)13 IntegrationTest (ch.cyberduck.test.IntegrationTest)13 Host (ch.cyberduck.core.Host)12 DefaultX509KeyManager (ch.cyberduck.core.ssl.DefaultX509KeyManager)12 DisabledX509TrustManager (ch.cyberduck.core.ssl.DisabledX509TrustManager)11 AbstractS3Test (ch.cyberduck.core.s3.AbstractS3Test)10 Path (ch.cyberduck.core.Path)9 ProtocolFactory (ch.cyberduck.core.ProtocolFactory)6 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)6 ProfilePlistReader (ch.cyberduck.core.serializer.impl.dd.ProfilePlistReader)6 AmazonCloudFront (com.amazonaws.services.cloudfront.AmazonCloudFront)6 URI (java.net.URI)6 Credentials (ch.cyberduck.core.Credentials)5 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)5 DisabledHostKeyCallback (ch.cyberduck.core.DisabledHostKeyCallback)5 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)5 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)4 DistributionLogging (ch.cyberduck.core.cdn.features.DistributionLogging)4