Search in sources :

Example 51 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfiguration method updateDownloadDistribution.

/**
 * Amazon CloudFront Extension used to enable or disable a distribution configuration and its CNAMESs
 */
protected UpdateDistributionResult updateDownloadDistribution(final Path container, final Distribution distribution) throws BackgroundException {
    final URI origin = this.getOrigin(container, distribution.getMethod());
    if (log.isDebugEnabled()) {
        log.debug(String.format("Update %s distribution with origin %s", distribution, origin));
    }
    final AmazonCloudFront client = this.client(container);
    final GetDistributionConfigResult response = client.getDistributionConfig(new GetDistributionConfigRequest(distribution.getId()));
    final DistributionConfig config = response.getDistributionConfig().withEnabled(distribution.isEnabled()).withDefaultRootObject(distribution.getIndexDocument()).withAliases(new Aliases().withItems(distribution.getCNAMEs()).withQuantity(distribution.getCNAMEs().length));
    if (distribution.isLogging()) {
        // Make bucket name fully qualified
        final String loggingTarget = ServiceUtils.generateS3HostnameForBucket(distribution.getLoggingContainer(), false, new S3Protocol().getDefaultHostname());
        if (log.isDebugEnabled()) {
            log.debug(String.format("Set logging target for %s to %s", distribution, loggingTarget));
        }
        config.setLogging(new LoggingConfig().withEnabled(distribution.isLogging()).withIncludeCookies(true).withBucket(loggingTarget).withPrefix(new HostPreferences(session.getHost()).getProperty("cloudfront.logging.prefix")));
    }
    return client.updateDistribution(new UpdateDistributionRequest(config, distribution.getId(), response.getETag()));
}
Also used : AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront) URI(java.net.URI) S3Protocol(ch.cyberduck.core.s3.S3Protocol) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 52 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfiguration method createDownloadDistribution.

protected com.amazonaws.services.cloudfront.model.Distribution createDownloadDistribution(final Path container, final Distribution distribution) throws BackgroundException {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Create new %s distribution", distribution));
    }
    final AmazonCloudFront client = this.client(container);
    final URI origin = this.getOrigin(container, distribution.getMethod());
    final String originId = String.format("%s-%s", preferences.getProperty("application.name"), new AlphanumericRandomStringService().random());
    final DistributionConfig config = new DistributionConfig(new AlphanumericRandomStringService().random(), distribution.isEnabled()).withComment(originId).withOrigins(new Origins().withQuantity(1).withItems(new Origin().withId(originId).withCustomHeaders(new CustomHeaders().withQuantity(0)).withOriginPath(StringUtils.EMPTY).withDomainName(origin.getHost()).withS3OriginConfig(new S3OriginConfig().withOriginAccessIdentity(StringUtils.EMPTY)))).withPriceClass(PriceClass.PriceClass_All).withDefaultCacheBehavior(new DefaultCacheBehavior().withTargetOriginId(originId).withForwardedValues(new ForwardedValues().withQueryString(true).withCookies(new CookiePreference().withForward(ItemSelection.All))).withViewerProtocolPolicy(ViewerProtocolPolicy.AllowAll).withMinTTL(0L).withTrustedSigners(new TrustedSigners().withEnabled(false).withQuantity(0))).withDefaultRootObject(distribution.getIndexDocument()).withAliases(new Aliases().withItems(distribution.getCNAMEs()).withQuantity(distribution.getCNAMEs().length));
    // Make bucket name fully qualified
    final String loggingTarget = ServiceUtils.generateS3HostnameForBucket(distribution.getLoggingContainer(), false, new S3Protocol().getDefaultHostname());
    if (log.isDebugEnabled()) {
        log.debug(String.format("Set logging target for %s to %s", distribution, loggingTarget));
    }
    config.setLogging(new LoggingConfig().withEnabled(distribution.isLogging()).withIncludeCookies(true).withBucket(loggingTarget).withPrefix(new HostPreferences(session.getHost()).getProperty("cloudfront.logging.prefix")));
    return client.createDistribution(new CreateDistributionRequest(config)).getDistribution();
}
Also used : URI(java.net.URI) S3Protocol(ch.cyberduck.core.s3.S3Protocol) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront)

Example 53 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfiguration method createCustomDistribution.

protected com.amazonaws.services.cloudfront.model.Distribution createCustomDistribution(final Path container, final Distribution distribution) throws BackgroundException {
    final AmazonCloudFront client = this.client(container);
    int httpPort = 80;
    int httpsPort = 443;
    final URI origin = this.getOrigin(container, distribution.getMethod());
    if (origin.getPort() != -1) {
        if (origin.getScheme().equals(Scheme.http.name())) {
            httpPort = origin.getPort();
        }
        if (origin.getScheme().equals(Scheme.https.name())) {
            httpsPort = origin.getPort();
        }
    }
    final String originId = String.format("%s-%s", preferences.getProperty("application.name"), new AlphanumericRandomStringService().random());
    final DistributionConfig config = new DistributionConfig(new AlphanumericRandomStringService().random(), distribution.isEnabled()).withComment(originId).withOrigins(new Origins().withQuantity(1).withItems(new Origin().withId(originId).withDomainName(origin.getHost()).withCustomOriginConfig(new CustomOriginConfig().withHTTPPort(httpPort).withHTTPSPort(httpsPort).withOriginSslProtocols(new OriginSslProtocols().withQuantity(2).withItems("TLSv1.1", "TLSv1.2")).withOriginProtocolPolicy(this.getPolicy(distribution.getMethod()))))).withPriceClass(PriceClass.PriceClass_All).withDefaultCacheBehavior(new DefaultCacheBehavior().withTargetOriginId(originId).withForwardedValues(new ForwardedValues().withQueryString(true).withCookies(new CookiePreference().withForward(ItemSelection.All))).withViewerProtocolPolicy(ViewerProtocolPolicy.AllowAll).withMinTTL(0L).withTrustedSigners(new TrustedSigners().withEnabled(false).withQuantity(0))).withDefaultRootObject(distribution.getIndexDocument()).withAliases(new Aliases().withItems(distribution.getCNAMEs()).withQuantity(distribution.getCNAMEs().length));
    if (distribution.isLogging()) {
        // Make bucket name fully qualified
        final String loggingTarget = ServiceUtils.generateS3HostnameForBucket(distribution.getLoggingContainer(), false, new S3Protocol().getDefaultHostname());
        if (log.isDebugEnabled()) {
            log.debug(String.format("Set logging target for %s to %s", distribution, loggingTarget));
        }
        config.setLogging(new LoggingConfig().withEnabled(distribution.isLogging()).withIncludeCookies(true).withBucket(loggingTarget).withPrefix(new HostPreferences(session.getHost()).getProperty("cloudfront.logging.prefix")));
    }
    return client.createDistribution(new CreateDistributionRequest(config)).getDistribution();
}
Also used : URI(java.net.URI) S3Protocol(ch.cyberduck.core.s3.S3Protocol) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront)

Example 54 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class Glacier method restore.

/**
 * Objects in the GLACIER and DEEP_ARCHIVE storage classes are archived. To access an archived object, you must
 * first initiate a restore request. This restores a temporary copy of the archived object. In a restore request,
 * you specify the number of days that you want the restored copy to exist. After the specified period, Amazon S3
 * deletes the temporary copy but the object remains archived in the GLACIER or DEEP_ARCHIVE storage class that
 * object was restored from.
 *
 * @param file   Archived file
 * @param prompt Callback
 */
@Override
public void restore(final Path file, final LoginCallback prompt) throws BackgroundException {
    final Path container = session.getFeature(PathContainerService.class).getContainer(file);
    try {
        try {
            final AmazonS3 client = client(container);
            // Standard - S3 Standard retrievals allow you to access any of your archived objects within several hours.
            // This is the default option for the GLACIER and DEEP_ARCHIVE retrieval requests that do not specify
            // the retrieval option. S3 Standard retrievals typically complete within 3-5 hours from the GLACIER
            // storage class and typically complete within 12 hours from the DEEP_ARCHIVE storage class.
            client.restoreObjectV2(new RestoreObjectRequest(container.getName(), session.getFeature(PathContainerService.class).getKey(file)).withVersionId(file.attributes().getVersionId()).withExpirationInDays(new HostPreferences(session.getHost()).getInteger("s3.glacier.restore.expiration.days")).withGlacierJobParameters(new GlacierJobParameters().withTier(new HostPreferences(session.getHost()).getProperty("s3.glacier.restore.tier"))));
        // 200 Reply if already restored
        } catch (AmazonClientException e) {
            throw new AmazonServiceExceptionMappingService().map("Failure to write attributes of {0}", e, file);
        }
    } catch (ConflictException e) {
        // 409 when restore is in progress
        log.warn(String.format("Restore for %s already in progress %s", file, e));
    }
}
Also used : Path(ch.cyberduck.core.Path) PathContainerService(ch.cyberduck.core.PathContainerService) AmazonS3(com.amazonaws.services.s3.AmazonS3) ConflictException(ch.cyberduck.core.exception.ConflictException) AmazonClientException(com.amazonaws.AmazonClientException) GlacierJobParameters(com.amazonaws.services.s3.model.GlacierJobParameters) RestoreObjectRequest(com.amazonaws.services.s3.model.RestoreObjectRequest) AmazonServiceExceptionMappingService(ch.cyberduck.core.aws.AmazonServiceExceptionMappingService) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 55 with HostPreferences

use of ch.cyberduck.core.preferences.HostPreferences in project cyberduck by iterate-ch.

the class OpenSSHCredentialsConfigurator method configure.

@Override
public Credentials configure(final Host host) {
    final Credentials credentials = new Credentials(host.getCredentials());
    if (StringUtils.isNotBlank(host.getHostname())) {
        configuration.refresh();
        // Update this host credentials from the OpenSSH configuration file in ~/.ssh/config
        final OpenSshConfig.Host entry = configuration.lookup(host.getHostname());
        if (StringUtils.isNotBlank(entry.getUser())) {
            if (!credentials.validate(host.getProtocol(), new LoginOptions(host.getProtocol()).password(false))) {
                if (log.isInfoEnabled()) {
                    log.info(String.format("Using username %s from %s", entry, configuration));
                }
                credentials.setUsername(entry.getUser());
            }
        }
        if (!credentials.isPublicKeyAuthentication()) {
            if (null != entry.getIdentityFile()) {
                if (log.isInfoEnabled()) {
                    log.info(String.format("Using identity %s from %s", entry, configuration));
                }
                credentials.setIdentity(entry.getIdentityFile());
            } else {
                // No custom public key authentication configuration
                if (new HostPreferences(host).getBoolean("ssh.authentication.publickey.default.enable")) {
                    final Local rsa = LocalFactory.get(new HostPreferences(host).getProperty("ssh.authentication.publickey.default.rsa"));
                    if (rsa.exists()) {
                        if (log.isInfoEnabled()) {
                            log.info(String.format("Using RSA default host key %s from %s", rsa, configuration));
                        }
                        credentials.setIdentity(rsa);
                    } else {
                        final Local dsa = LocalFactory.get(new HostPreferences(host).getProperty("ssh.authentication.publickey.default.dsa"));
                        if (dsa.exists()) {
                            if (log.isInfoEnabled()) {
                                log.info(String.format("Using DSA default host key %s from %s", dsa, configuration));
                            }
                            credentials.setIdentity(dsa);
                        }
                    }
                }
            }
        }
    }
    return credentials;
}
Also used : LoginOptions(ch.cyberduck.core.LoginOptions) OpenSshConfig(ch.cyberduck.core.sftp.openssh.config.transport.OpenSshConfig) Local(ch.cyberduck.core.Local) Credentials(ch.cyberduck.core.Credentials) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Aggregations

HostPreferences (ch.cyberduck.core.preferences.HostPreferences)81 IOException (java.io.IOException)33 Path (ch.cyberduck.core.Path)29 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)18 BackgroundException (ch.cyberduck.core.exception.BackgroundException)12 DefaultIOExceptionMappingService (ch.cyberduck.core.DefaultIOExceptionMappingService)11 PathAttributes (ch.cyberduck.core.PathAttributes)11 NotfoundException (ch.cyberduck.core.exception.NotfoundException)11 File (com.google.api.services.drive.model.File)10 AttributedList (ch.cyberduck.core.AttributedList)8 URI (java.net.URI)8 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)7 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)6 SimplePathPredicate (ch.cyberduck.core.SimplePathPredicate)6 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)6 MemorySegementingOutputStream (ch.cyberduck.core.io.MemorySegementingOutputStream)6 NodesApi (ch.cyberduck.core.sds.io.swagger.client.api.NodesApi)5 Credentials (ch.cyberduck.core.Credentials)4 Partition (ch.cyberduck.core.collections.Partition)4 S3Protocol (ch.cyberduck.core.s3.S3Protocol)4