Skip to content

Commit

Permalink
Deprecate fields
Browse files Browse the repository at this point in the history
defaultTTL
maxTTL
minTTL
forwardedValues
  • Loading branch information
harjain99 committed Jun 17, 2024
1 parent 9b2477f commit 79ffdee
Showing 1 changed file with 57 additions and 31 deletions.
88 changes: 57 additions & 31 deletions src/main/java/gyro/aws/cloudfront/CloudFrontCacheBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import gyro.aws.Copyable;
import gyro.core.resource.Diffable;
import gyro.core.resource.Updatable;
import gyro.core.validation.ConflictsWith;
import gyro.core.validation.ValidStrings;
import software.amazon.awssdk.services.cloudfront.model.CacheBehavior;
import software.amazon.awssdk.services.cloudfront.model.DefaultCacheBehavior;
Expand Down Expand Up @@ -102,6 +103,8 @@ public void setViewerProtocolPolicy(String viewerProtocolPolicy) {
* The minimum time objects will be cached in this distribution.
*/
@Updatable
@Deprecated
@ConflictsWith("cache-policy")
public Long getMinTtl() {
if (minTtl == null) {
minTtl = 0L;
Expand Down Expand Up @@ -150,6 +153,8 @@ public void setCachedMethods(Set<String> cachedMethods) {
* Headers to include the cache key for an object.
*/
@Updatable
@Deprecated
@ConflictsWith("cache-policy")
public Set<String> getHeaders() {
if (headers == null) {
headers = new HashSet<>();
Expand All @@ -166,6 +171,8 @@ public void setHeaders(Set<String> headers) {
* Whether to forward to cookies to the origin.
*/
@Updatable
@Deprecated
@ConflictsWith("cache-policy")
public String getForwardCookies() {
if (forwardCookies != null) {
return forwardCookies.toLowerCase();
Expand All @@ -182,6 +189,8 @@ public void setForwardCookies(String forwardCookies) {
* Whitelist of cookies to include the cache key for an object.
*/
@Updatable
@Deprecated
@ConflictsWith("cache-policy")
public Set<String> getCookies() {
if (cookies == null) {
cookies = new HashSet<>();
Expand Down Expand Up @@ -214,6 +223,8 @@ public void setSmoothStreaming(Boolean smoothStreaming) {
* The time objects will be cached in this distribution. Only applies when one of ``Cache-Control: max-age``, ``Cache-Control: s-maxage``, or ``Expires`` are not returned by the origin.
*/
@Updatable
@Deprecated
@ConflictsWith("cache-policy")
public Long getDefaultTtl() {
if (defaultTtl == null) {
defaultTtl = 86400L;
Expand All @@ -230,6 +241,8 @@ public void setDefaultTtl(Long defaultTtl) {
* The maximum time objects will be cached in this distribution.
*/
@Updatable
@Deprecated
@ConflictsWith("cache-policy")
public Long getMaxTtl() {
if (maxTtl == null) {
maxTtl = 31536000L;
Expand Down Expand Up @@ -262,6 +275,8 @@ public void setCompress(Boolean compress) {
* Whether to forward query strings to origin. If true, query string parameters become part of the cache key.
*/
@Updatable
@Deprecated
@ConflictsWith("cache-policy")
public Boolean getQueryString() {
if (queryString == null) {
queryString = false;
Expand All @@ -278,6 +293,8 @@ public void setQueryString(Boolean queryString) {
* Query string parameters that should be used in the cache key.
*/
@Updatable
@Deprecated
@ConflictsWith("cache-policy")
public Set<String> getQueryStringCacheKeys() {
if (queryStringCacheKeys == null) {
queryStringCacheKeys = new HashSet<>();
Expand Down Expand Up @@ -437,8 +454,8 @@ public void copyFrom(CacheBehavior cacheBehavior) {
}
}

findById(CachePolicyResource.class, cacheBehavior.cachePolicyId());
findById(OriginRequestPolicyResource.class, cacheBehavior.originRequestPolicyId());
setCachePolicy(findById(CachePolicyResource.class, cacheBehavior.cachePolicyId()));
setOriginRequestPolicy(findById(OriginRequestPolicyResource.class, cacheBehavior.originRequestPolicyId()));
}

@Override
Expand Down Expand Up @@ -467,14 +484,6 @@ static CacheBehavior getCacheBehaviorFromDefault(DefaultCacheBehavior defaultCac
}

DefaultCacheBehavior toDefaultCacheBehavior() {
ForwardedValues forwardedValues = ForwardedValues.builder()
.headers(h -> h.items(getHeaders()).quantity(getHeaders().size()))
.cookies(c -> c.forward(getForwardCookies())
.whitelistedNames(w -> w.items(getCookies()).quantity(getCookies().size())))
.queryString(getQueryString())
.queryStringCacheKeys(q -> q.items(getQueryStringCacheKeys()).quantity(getQueryStringCacheKeys().size()))
.build();

TrustedSigners trustedSigners = TrustedSigners.builder()
.items(getTrustedSigners())
.quantity(getTrustedSigners().size())
Expand All @@ -491,36 +500,41 @@ DefaultCacheBehavior toDefaultCacheBehavior() {
.quantity(getFunctionAssociations().size())
.build();

return DefaultCacheBehavior.builder()
DefaultCacheBehavior.Builder builder = DefaultCacheBehavior.builder()
.allowedMethods(am -> am.itemsWithStrings(getAllowedMethods())
.quantity(getAllowedMethods().size())
.cachedMethods(cm -> cm.itemsWithStrings(getCachedMethods()).quantity(getCachedMethods().size()))
)
.defaultTTL(getDefaultTtl())
.maxTTL(getMaxTtl())
.minTTL(getMinTtl())
.smoothStreaming(getSmoothStreaming())
.targetOriginId(getTargetOriginId())
.forwardedValues(forwardedValues)
.trustedSigners(trustedSigners)
.lambdaFunctionAssociations(lambdaFunctionAssociations)
.functionAssociations(functionAssociations)
.viewerProtocolPolicy(getViewerProtocolPolicy())
.fieldLevelEncryptionId(getFieldLevelEncryptionId())
.compress(getCompress())
.cachePolicyId(getCachePolicy() != null ? getCachePolicy().getId() : null)
.originRequestPolicyId(getOriginRequestPolicy() != null ? getOriginRequestPolicy().getId() : null)
.build();
.originRequestPolicyId(getOriginRequestPolicy() != null ? getOriginRequestPolicy().getId() : null);

if (getCachePolicy() == null) {
ForwardedValues forwardedValues = ForwardedValues.builder()
.headers(h -> h.items(getHeaders()).quantity(getHeaders().size()))
.cookies(c -> c.forward(getForwardCookies())
.whitelistedNames(w -> w.items(getCookies()).quantity(getCookies().size())))
.queryString(getQueryString())
.queryStringCacheKeys(
q -> q.items(getQueryStringCacheKeys()).quantity(getQueryStringCacheKeys().size()))
.build();
builder.forwardedValues(forwardedValues)
.defaultTTL(getDefaultTtl())
.maxTTL(getMaxTtl())
.minTTL(getMinTtl());
}

return builder.build();
}

CacheBehavior toCachBehavior() {
ForwardedValues forwardedValues = ForwardedValues.builder()
.headers(h -> h.items(getHeaders()).quantity(getHeaders().size()))
.cookies(c -> c.forward(getForwardCookies())
.whitelistedNames(w -> w.items(getCookies()).quantity(getCookies().size())))
.queryString(getQueryString())
.queryStringCacheKeys(q -> q.items(getQueryStringCacheKeys()).quantity(getQueryStringCacheKeys().size()))
.build();

TrustedSigners trustedSigners = TrustedSigners.builder()
.items(getTrustedSigners())
Expand All @@ -538,26 +552,38 @@ CacheBehavior toCachBehavior() {
.quantity(getFunctionAssociations().size())
.build();

return CacheBehavior.builder()
CacheBehavior.Builder builder = CacheBehavior.builder()
.allowedMethods(am -> am.itemsWithStrings(getAllowedMethods())
.quantity(getAllowedMethods().size())
.cachedMethods(cm -> cm.itemsWithStrings(getCachedMethods()).quantity(getCachedMethods().size()))
)
.defaultTTL(getDefaultTtl())
.maxTTL(getMaxTtl())
.minTTL(getMinTtl())
.smoothStreaming(getSmoothStreaming())
.targetOriginId(getTargetOriginId())
.pathPattern(getPathPattern())
.forwardedValues(forwardedValues)
.trustedSigners(trustedSigners)
.lambdaFunctionAssociations(lambdaFunctionAssociations)
.functionAssociations(functionAssociations)
.viewerProtocolPolicy(getViewerProtocolPolicy())
.fieldLevelEncryptionId(getFieldLevelEncryptionId())
.compress(getCompress())
.cachePolicyId(getCachePolicy() != null ? getCachePolicy().getId() : null)
.originRequestPolicyId(getOriginRequestPolicy() != null ? getOriginRequestPolicy().getId() : null)
.build();
.originRequestPolicyId(getOriginRequestPolicy() != null ? getOriginRequestPolicy().getId() : null);

if (getCachePolicy() == null) {
ForwardedValues forwardedValues = ForwardedValues.builder()
.headers(h -> h.items(getHeaders()).quantity(getHeaders().size()))
.cookies(c -> c.forward(getForwardCookies())
.whitelistedNames(w -> w.items(getCookies()).quantity(getCookies().size())))
.queryString(getQueryString())
.queryStringCacheKeys(
q -> q.items(getQueryStringCacheKeys()).quantity(getQueryStringCacheKeys().size()))
.build();
builder.forwardedValues(forwardedValues)
.defaultTTL(getDefaultTtl())
.maxTTL(getMaxTtl())
.minTTL(getMinTtl());
}

return builder.build();
}
}

0 comments on commit 79ffdee

Please sign in to comment.