Skip to content

Commit

Permalink
Allow full control of configuring cdn values of backend bucket resources
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanjan90 committed Oct 20, 2023
1 parent c383bee commit 2f3ecfc
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2023, Brightspot.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gyro.google.compute;

import com.google.cloud.compute.v1.BackendBucketCdnPolicyBypassCacheOnRequestHeader;
import gyro.core.resource.Diffable;
import gyro.core.validation.Required;
import gyro.google.Copyable;

public class BackendBucketCdnBypassCacheOnRequestHeader extends Diffable implements Copyable<BackendBucketCdnPolicyBypassCacheOnRequestHeader> {

private String headerName;

/**
* The header name to match on when bypassing cache.
*/
@Required
public String getHeaderName() {
return headerName;
}

public void setHeaderName(String headerName) {
this.headerName = headerName;
}

@Override
public void copyFrom(BackendBucketCdnPolicyBypassCacheOnRequestHeader model) {
setHeaderName(model.getHeaderName());
}

@Override
public String primaryKey() {
return headerName != null ? getHeaderName() : "";
}

BackendBucketCdnPolicyBypassCacheOnRequestHeader toBackendBucketCdnPolicyBypassCacheOnRequestHeader() {
return BackendBucketCdnPolicyBypassCacheOnRequestHeader.newBuilder()
.setHeaderName(getHeaderName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2023, Brightspot.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gyro.google.compute;

import java.util.ArrayList;
import java.util.List;

import com.google.cloud.compute.v1.BackendBucketCdnPolicyCacheKeyPolicy;
import gyro.core.resource.Diffable;
import gyro.core.resource.Updatable;
import gyro.google.Copyable;

public class BackendBucketCdnCacheKeyPolicy extends Diffable implements Copyable<BackendBucketCdnPolicyCacheKeyPolicy> {

private List<String> includeHttpHeaders;
private List<String> queryStringWhitelist;

/**
* Headers to include in cache keys according to include_http_headers.
*/
@Updatable
public List<String> getIncludeHttpHeaders() {
if (includeHttpHeaders == null) {
includeHttpHeaders = new ArrayList<>();
}

return includeHttpHeaders;
}

public void setIncludeHttpHeaders(List<String> includeHttpHeaders) {
this.includeHttpHeaders = includeHttpHeaders;
}

/**
* Names of query string parameters to include in cache keys.
*/
@Updatable
public List<String> getQueryStringWhitelist() {
if (queryStringWhitelist == null) {
queryStringWhitelist = new ArrayList<>();
}

return queryStringWhitelist;
}

public void setQueryStringWhitelist(List<String> queryStringWhitelist) {
this.queryStringWhitelist = queryStringWhitelist;
}

@Override
public void copyFrom(BackendBucketCdnPolicyCacheKeyPolicy model) {
setIncludeHttpHeaders(model.getIncludeHttpHeadersList());
setQueryStringWhitelist(model.getQueryStringWhitelistList());
}

BackendBucketCdnPolicyCacheKeyPolicy toBackendBucketCdnPolicyCacheKeyPolicy() {
BackendBucketCdnPolicyCacheKeyPolicy.Builder builder = BackendBucketCdnPolicyCacheKeyPolicy.newBuilder();
builder.addAllIncludeHttpHeaders(getIncludeHttpHeaders());
builder.addAllQueryStringWhitelist(getQueryStringWhitelist());
return builder.build();
}

@Override
public String primaryKey() {
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2023, Brightspot.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gyro.google.compute;

import com.google.cloud.compute.v1.BackendBucketCdnPolicyNegativeCachingPolicy;
import gyro.core.resource.Diffable;
import gyro.core.validation.Required;
import gyro.google.Copyable;

public class BackendBucketCdnNegativeCachingPolicy extends Diffable implements Copyable<BackendBucketCdnPolicyNegativeCachingPolicy> {

private Integer code;
private Integer ttl;

/**
* The HTTP status code to define custom set of rules.
*/
@Required
public Integer getCode() {
return code;
}

public void setCode(Integer code) {
this.code = code;
}

/**
* The TTL for the negative response.
*/
@Required
public Integer getTtl() {
return ttl;
}

public void setTtl(Integer ttl) {
this.ttl = ttl;
}

@Override
public void copyFrom(BackendBucketCdnPolicyNegativeCachingPolicy model) {
setCode(model.getCode());
setTtl(model.getTtl());
}

@Override
public String primaryKey() {
return String.format("Code: %s, TTL: %s", getCode() != null ? getCode() : 0, getTtl() != null ? getTtl() : 0);
}

BackendBucketCdnPolicyNegativeCachingPolicy toBackendBucketCdnPolicyNegativeCachingPolicy() {
return BackendBucketCdnPolicyNegativeCachingPolicy.newBuilder()
.setCode(getCode())
.setTtl(getTtl())
.build();
}
}
Loading

0 comments on commit 2f3ecfc

Please sign in to comment.