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()));
}
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();
}
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();
}
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));
}
}
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;
}
Aggregations