Search in sources :

Example 16 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class StoregateShareFeature method toDownloadUrl.

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Void options, final PasswordCallback callback) throws BackgroundException {
    try {
        final Host bookmark = session.getHost();
        final CreateFileShareRequest request = new CreateFileShareRequest().fileId(fileid.getFileId(file, new DisabledListProgressListener()));
        try {
            request.setPassword(callback.prompt(bookmark, LocaleFactory.localizedString("Passphrase", "Cryptomator"), MessageFormat.format(LocaleFactory.localizedString("Create a passphrase required to access {0}", "Credentials"), file.getName()), new LoginOptions().keychain(false).icon(bookmark.getProtocol().disk())).getPassword());
        } catch (LoginCanceledException e) {
        // Ignore no password set
        }
        return new DescriptiveUrl(URI.create(new FileSharesApi(session.getClient()).fileSharesPost(request).getUrl()), DescriptiveUrl.Type.signed);
    } catch (ApiException e) {
        throw new StoregateExceptionMappingService(fileid).map(e);
    }
}
Also used : LoginOptions(ch.cyberduck.core.LoginOptions) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) FileSharesApi(ch.cyberduck.core.storegate.io.swagger.client.api.FileSharesApi) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) Host(ch.cyberduck.core.Host) CreateFileShareRequest(ch.cyberduck.core.storegate.io.swagger.client.model.CreateFileShareRequest) ApiException(ch.cyberduck.core.storegate.io.swagger.client.ApiException)

Example 17 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class StoregateShareFeature method toUploadUrl.

@Override
public DescriptiveUrl toUploadUrl(final Path file, final Void options, final PasswordCallback callback) throws BackgroundException {
    try {
        final Host bookmark = session.getHost();
        final CreateFileShareRequest request = new CreateFileShareRequest().fileId(fileid.getFileId(file, new DisabledListProgressListener())).allowUpload(true);
        try {
            request.setPassword(callback.prompt(bookmark, LocaleFactory.localizedString("Passphrase", "Cryptomator"), MessageFormat.format(LocaleFactory.localizedString("Create a passphrase required to access {0}", "Credentials"), file.getName()), new LoginOptions().keychain(false).icon(bookmark.getProtocol().disk())).getPassword());
        } catch (LoginCanceledException e) {
        // Ignore no password set
        }
        return new DescriptiveUrl(URI.create(new FileSharesApi(session.getClient()).fileSharesPost(request).getUrl()), DescriptiveUrl.Type.signed);
    } catch (ApiException e) {
        throw new StoregateExceptionMappingService(fileid).map(e);
    }
}
Also used : LoginOptions(ch.cyberduck.core.LoginOptions) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) FileSharesApi(ch.cyberduck.core.storegate.io.swagger.client.api.FileSharesApi) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) Host(ch.cyberduck.core.Host) CreateFileShareRequest(ch.cyberduck.core.storegate.io.swagger.client.model.CreateFileShareRequest) ApiException(ch.cyberduck.core.storegate.io.swagger.client.ApiException)

Example 18 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class B2AuthorizedUrlProvider method toDownloadUrl.

@Override
public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException {
    final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file)));
    try {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Create download authorization for %s", file));
        }
        final int seconds = 604800;
        // Determine expiry time for URL
        final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        expiry.add(Calendar.SECOND, seconds);
        final String token = session.getClient().getDownloadAuthorization(fileid.getVersionId(containerService.getContainer(file), new DisabledListProgressListener()), StringUtils.EMPTY, seconds);
        return new DescriptiveUrl(URI.create(String.format("%s?Authorization=%s", download, token)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())));
    } catch (B2ApiException e) {
        throw new B2ExceptionMappingService(fileid).map(e);
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map(e);
    }
}
Also used : DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) Calendar(java.util.Calendar) B2ApiException(synapticloop.b2.exception.B2ApiException) IOException(java.io.IOException) DefaultIOExceptionMappingService(ch.cyberduck.core.DefaultIOExceptionMappingService)

Example 19 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class B2UrlProvider method toUrl.

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    if (file.isVolume()) {
        return DescriptiveUrlBag.empty();
    }
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    if (file.isFile()) {
        final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file)));
        list.add(new DescriptiveUrl(URI.create(download), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), Scheme.https.name().toUpperCase(Locale.ROOT))));
    }
    return list;
}
Also used : DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DescriptiveUrlBag(ch.cyberduck.core.DescriptiveUrlBag)

Example 20 with DescriptiveUrl

use of ch.cyberduck.core.DescriptiveUrl in project cyberduck by iterate-ch.

the class B2AuthorizedUrlProviderTest method testToUrl.

@Test
public void testToUrl() throws Exception {
    final Path bucket = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path test = new Path(bucket, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
    new B2TouchFeature(session, fileid).touch(test, new TransferStatus());
    final B2AuthorizedUrlProvider provider = new B2AuthorizedUrlProvider(session, fileid);
    assertFalse(provider.isSupported(bucket, PromptUrlProvider.Type.download));
    final DescriptiveUrl url = provider.toDownloadUrl(test, null, new DisabledPasswordCallback());
    assertNotEquals(DescriptiveUrl.EMPTY, url);
    assertNotNull(url.getUrl());
    new B2DeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DescriptiveUrl(ch.cyberduck.core.DescriptiveUrl) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

DescriptiveUrl (ch.cyberduck.core.DescriptiveUrl)77 Path (ch.cyberduck.core.Path)42 Test (org.junit.Test)40 IntegrationTest (ch.cyberduck.test.IntegrationTest)30 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)25 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)24 Delete (ch.cyberduck.core.features.Delete)24 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)22 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)22 Host (ch.cyberduck.core.Host)19 DescriptiveUrlBag (ch.cyberduck.core.DescriptiveUrlBag)16 ObjectExpiration (ch.cyberduck.core.sds.io.swagger.client.model.ObjectExpiration)14 LoginOptions (ch.cyberduck.core.LoginOptions)13 CreateDownloadShareRequest (ch.cyberduck.core.sds.io.swagger.client.model.CreateDownloadShareRequest)12 Credentials (ch.cyberduck.core.Credentials)8 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)7 LoginCanceledException (ch.cyberduck.core.exception.LoginCanceledException)7 PathAttributes (ch.cyberduck.core.PathAttributes)6 IOException (java.io.IOException)6 HostUrlProvider (ch.cyberduck.core.HostUrlProvider)5