Skip to main content

Update

Updates the specified CDN resource.

The method implements patch behaviour, i.e. only the fields specified in the request are updated in the resource.

Changes may take up to 15 minutes to apply. Afterwards, it is recommended to purge the resource's cache via a CacheService.Purge request.

import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";

const OriginProtocol = cloudApi.cdn.resource.OriginProtocol;
const PolicyType = cloudApi.cdn.resource.PolicyType;
const Resource = cloudApi.cdn.resource.Resource;
const RewriteFlag = cloudApi.cdn.resource.RewriteFlag;
const SSLCertificateType = cloudApi.cdn.resource.SSLCertificateType;
const SecureKeyURLType = cloudApi.cdn.resource.SecureKeyURLType;
const UpdateResourceRequest =
cloudApi.cdn.resource_service.UpdateResourceRequest;

(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.ResourceServiceClient);

const operation = await client.update(
UpdateResourceRequest.fromPartial({
resourceId: "resourceId",
// originGroupId: {
// value: 0
// },
// secondaryHostnames: {
// values: ["values"]
// },
// options: {
// disableCache: {
// enabled: true,
// value: true
// },
// edgeCacheSettings: {
// enabled: true,
// value: {
// simpleValue: 0,
// customValues: {1: 0}
// },
// defaultValue: 0
// },
// browserCacheSettings: {
// enabled: true,
// value: 0
// },
// cacheHttpHeaders: {
// enabled: true,
// value: ["value"]
// },
// queryParamsOptions: {
// ignoreQueryString: {
// enabled: true,
// value: true
// },
// queryParamsWhitelist: {
// enabled: true,
// value: ["value"]
// },
// queryParamsBlacklist: {
// enabled: true,
// value: ["value"]
// }
// },
// slice: {
// enabled: true,
// value: true
// },
// compressionOptions: {
// fetchCompressed: {
// enabled: true,
// value: true
// },
// gzipOn: {
// enabled: true,
// value: true
// },
// brotliCompression: {
// enabled: true,
// value: ["value"]
// }
// },
// redirectOptions: {
// redirectHttpToHttps: {
// enabled: true,
// value: true
// },
// redirectHttpsToHttp: {
// enabled: true,
// value: true
// }
// },
// hostOptions: {
// host: {
// enabled: true,
// value: "value"
// },
// forwardHostHeader: {
// enabled: true,
// value: true
// }
// },
// staticHeaders: {
// enabled: true,
// value: {"key": "value"}
// },
// cors: {
// enabled: true,
// value: ["value"]
// },
// stale: {
// enabled: true,
// value: ["value"]
// },
// allowedHttpMethods: {
// enabled: true,
// value: ["value"]
// },
// proxyCacheMethodsSet: {
// enabled: true,
// value: true
// },
// disableProxyForceRanges: {
// enabled: true,
// value: true
// },
// staticRequestHeaders: {
// enabled: true,
// value: {"key": "value"}
// },
// customServerName: {
// enabled: true,
// value: "value"
// },
// ignoreCookie: {
// enabled: true,
// value: true
// },
// rewrite: {
// enabled: true,
// body: "body",
// flag: RewriteFlag.LAST
// },
// secureKey: {
// enabled: true,
// key: "key",
// type: SecureKeyURLType.ENABLE_IP_SIGNING
// },
// ipAddressAcl: {
// enabled: true,
// policyType: PolicyType.POLICY_TYPE_ALLOW,
// exceptedValues: ["exceptedValues"]
// }
// },
// originProtocol: OriginProtocol.HTTP,
// active: {
// value: true
// },
// sslCertificate: {
// type: SSLCertificateType.DONT_USE,
// data: {
// cm: {
// id: "id"
// }
// }
// },
// labels: {"key": "labels"}
})
);
const finishedOp = await waitForOperation(operation, session);

if (finishedOp.response) {
const result = decodeMessage<typeof Resource>(finishedOp.response);
console.log(result);
}
})();

UpdateResourceRequest

resourceId : string

ID of updated resource.

originGroupId : google.protobuf.Int64Value

ID of updated origin group.

secondaryHostnames : SecondaryHostnames

List of additional CNAMEs.

options : ResourceOptions

Resource settings and options to tune CDN edge behavior.

originProtocol : OriginProtocol

Specify the protocol schema to be used in communication with origin.

active : google.protobuf.BoolValue

Flag to create Resource either in active or disabled state. In active state Origins payload could be transmitted from CDN CNAME requests. Default value: true

sslCertificate : SSLTargetCertificate

SSL Certificate options.

labels : string

Resource labels. At some point will be needed for granular detailing.

SecondaryHostnames

List of secondary (alternative) CNAMEs.

values : string

List of secondary hostname values.

ResourceOptions

A major set of various resource options.

BoolOption

Set up bool values.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : bool

Value of the option.

StringOption

A set of the string parameters.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : string

Value of the option.

Int64Option

A set of the numeric parameters.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : int64

Value of the option.

StringsListOption

A set of the string list parameters.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : string

Value of the option.

StringsMapOption

A set of the strings map parameters.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : string

Value of the option.

CachingTimes

A set of the caching response time parameters.

simpleValue : int64

Caching time for a response with codes 200, 206, 301, 302. Responses with codes 4xx, 5xx will not be cached. Use 0s disable to caching. Use custom_values field to specify a custom caching time for a response with specific codes.

customValues : int64

Caching time for a response with specific codes. These settings have a higher priority than the value field. Response code (304, 404 for example). Use any to specify caching time for all response codes. Caching time in seconds (0s, 600s for example). Use 0s to disable caching for a specific response code.

EdgeCacheSettings

A set of the edge cache parameters.

enabled : bool

True - the option is enabled and its values_variant is applied to the resource. False - the option is disabled and its default value is used for the resource.

One of valuesVariant

  • value : CachingTimes

    Value of the option.

  • defaultValue : int64
    Content will be cached according to origin cache settings.

    The value applies for a response with codes 200, 201, 204, 206, 301, 302, 303, 304, 307, 308 if an origin server does not have caching HTTP headers. Responses with other codes will not be cached.

StringVariableMapOption

A set of the string variable map parameters.

OneofString

One of stringOption

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : OneofString

Value of the option.

QueryParamsOptions

A set of the query parameters.

One of queryParamsVariant

  • ignoreQueryString : BoolOption

    Using BoolOption. Selected by default. Files with different query parameters are cached as objects with the same key regardless of the parameter value.

  • queryParamsWhitelist : StringsListOption
    Ignore All Except.

    Files with the specified query parameters are cached as objects with different keys, files with other parameters are cached as objects with the same key.

  • queryParamsBlacklist : StringsListOption
    Ignore only. Files with the specified query parameters are cached as objects with the same key,

    files with other parameters are cached as objects with different keys.

RedirectOptions

A set of the redirect parameters.

One of redirectVariant

  • redirectHttpToHttps : BoolOption

    Using BoolOption. Set up a redirect from HTTPS to HTTP.

  • redirectHttpsToHttp : BoolOption

    Using BoolOption. Set up a redirect from HTTP to HTTPS.

HostOptions

A set of the host parameters.

One of hostVariant

  • host : StringOption

    Custom value for the Host header.

Your server must be able to process requests with the chosen header.

Default value (if StringOption.enabled is false) is Resource.cname.

  • forwardHostHeader : BoolOption
    Using [BoolOption][16]. Choose the Forward Host header option if is important to send in the request to the Origin

    the same Host header as was sent in the request to CDN server.

CompressionOptions

A set of the compression variant parameters.

One of compressionVariant

  • fetchCompressed : BoolOption
    The Fetch compressed option helps you to reduce

    the bandwidth between origin and CDN servers. Also, content delivery speed becomes higher because of reducing the time for compressing files in a CDN.

  • gzipOn : BoolOption

    Using BoolOption. GZip compression at CDN servers reduces file size by 70% and can be as high as 90%.

  • brotliCompression : StringsListOption

    The option allows to compress content with brotli on the CDN's end.

Compression is performed on the Origin Shielding. If a pre-cache server doesn't active for a resource, compression does not occur even if the option is enabled.

Specify the content-type for each type of content you wish to have compressed. CDN servers will request only uncompressed content from the origin.

RewriteOption

An option for changing or redirecting query paths.

enabled : bool

True - the option is enabled and its flag is applied to the resource. False - the option is disabled and its default value of the flag is used for the resource.

body : string

Pattern for rewrite.

The value must have the following format: <source path> <destination path>, where both paths are regular expressions which use at least one group. E.g., /foo/(.*) /bar/$1.

flag : RewriteFlag

Break flag is applied to the option by default. It is not shown in the field.

SecureKeyOption
enabled : bool

True - the option is enabled and its flag is applied to the resource. False - the option is disabled and its default value of the flag is used for the resource.

key : string

The key for the URL signing.

type : SecureKeyURLType

The type of the URL signing. The URL could be available for all IP addresses or for the only one IP.

IPAddressACLOption
enabled : bool

True - the option is enabled and its flag is applied to the resource. False - the option is disabled and its default value of the flag is used for the resource.

policyType : PolicyType

The policy type. One of allow or deny value.

exceptedValues : string

The list of IP addresses to be allowed or denied.

disableCache : BoolOption

Set up a cache status.

edgeCacheSettings : EdgeCacheSettings

Set up EdgeCacheSettings.

browserCacheSettings : Int64Option

Using Int64Option. Set up a cache period for the end-users browser. Content will be cached due to origin settings. If there are no cache settings on your origin, the content will not be cached. The list of HTTP response codes that can be cached in browsers: 200, 201, 204, 206, 301, 302, 303, 304, 307, 308. Other response codes will not be cached. The default value is 4 days.

cacheHttpHeaders : StringsListOption

List HTTP headers that must be included in responses to clients.

queryParamsOptions : QueryParamsOptions

Set up QueryParamsOptions.

slice : BoolOption

Files larger than 10 MB will be requested and cached in parts (no larger than 10 MB each part). It reduces time to first byte.

The origin must support HTTP Range requests.

By default the option is disabled.

compressionOptions : CompressionOptions

Set up compression variant.

redirectOptions : RedirectOptions

Set up redirects.

hostOptions : HostOptions

Set up host parameters.

staticHeaders : StringsMapOption

Set up static headers that CDN servers send in responses to clients.

cors : StringsListOption

Parameter that lets browsers get access to selected resources from a domain different to a domain from which the request is received. Read more.

stale : StringsListOption

List of errors which instruct CDN servers to serve stale content to clients.

Possible values: error, http_403, http_404, http_429, http_500, http_502, http_503, http_504, invalid_header, timeout, updating.

allowedHttpMethods : StringsListOption

HTTP methods for your CDN content. By default the following methods are allowed: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS. In case some methods are not allowed to the user, they will get the 405 (Method Not Allowed) response. If the method is not supported, the user gets the 501 (Not Implemented) response.

proxyCacheMethodsSet : BoolOption

Allows caching for GET, HEAD and POST requests.

disableProxyForceRanges : BoolOption

Disabling proxy force ranges.

staticRequestHeaders : StringsMapOption

Set up custom headers that CDN servers send in requests to origins. The Header name field can contain letters (A-Z, a-z), numbers (0-9), dashes (-) and underscores (). The Value field can contain letters (A-Z, a-z), numbers (0-9), dashes (-), underscores (), slashes (/), colons (:), equal (=), dots (.), and spaces.

customServerName : StringOption

Wildcard additional CNAME. If a resource has a wildcard additional CNAME, you can use your own certificate for content delivery via HTTPS. Read-only.

ignoreCookie : BoolOption

Using BoolOption for ignoring cookie.

rewrite : RewriteOption

Changing or redirecting query paths.

secureKey : SecureKeyOption

Secure token to protect contect and limit access by IP addresses and time limits.

ipAddressAcl : IPAddressACLOption

Manage the state of the IP access policy option. The option controls access to content from the specified IP addresses.

SSLTargetCertificate

A set of the personal SSL certificate parameters.

type : SSLCertificateType

Type of the certificate.

data : SSLCertificateData

Certificate data.

CachingTimes

A set of the caching response time parameters.

simpleValue : int64

Caching time for a response with codes 200, 206, 301, 302. Responses with codes 4xx, 5xx will not be cached. Use 0s disable to caching. Use custom_values field to specify a custom caching time for a response with specific codes.

customValues : int64

Caching time for a response with specific codes. These settings have a higher priority than the value field. Response code (304, 404 for example). Use any to specify caching time for all response codes. Caching time in seconds (0s, 600s for example). Use 0s to disable caching for a specific response code.

StringOption

A set of the string parameters.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : string

Value of the option.

StringsListOption

A set of the string list parameters.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : string

Value of the option.

OneofString

BoolOption

Set up bool values.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : bool

Value of the option.

EdgeCacheSettings

A set of the edge cache parameters.

enabled : bool

True - the option is enabled and its values_variant is applied to the resource. False - the option is disabled and its default value is used for the resource.

  • value : CachingTimes

    Value of the option.

  • defaultValue : int64
    Content will be cached according to origin cache settings.

    The value applies for a response with codes 200, 201, 204, 206, 301, 302, 303, 304, 307, 308 if an origin server does not have caching HTTP headers. Responses with other codes will not be cached.

Int64Option

A set of the numeric parameters.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : int64

Value of the option.

QueryParamsOptions

A set of the query parameters.

  • ignoreQueryString : BoolOption

    Using BoolOption. Selected by default. Files with different query parameters are cached as objects with the same key regardless of the parameter value.

  • queryParamsWhitelist : StringsListOption
    Ignore All Except.

    Files with the specified query parameters are cached as objects with different keys, files with other parameters are cached as objects with the same key.

  • queryParamsBlacklist : StringsListOption
    Ignore only. Files with the specified query parameters are cached as objects with the same key,

    files with other parameters are cached as objects with different keys.

CompressionOptions

A set of the compression variant parameters.

  • fetchCompressed : BoolOption
    The Fetch compressed option helps you to reduce

    the bandwidth between origin and CDN servers. Also, content delivery speed becomes higher because of reducing the time for compressing files in a CDN.

  • gzipOn : BoolOption

    Using BoolOption. GZip compression at CDN servers reduces file size by 70% and can be as high as 90%.

  • brotliCompression : StringsListOption

    The option allows to compress content with brotli on the CDN's end.

Compression is performed on the Origin Shielding. If a pre-cache server doesn't active for a resource, compression does not occur even if the option is enabled.

Specify the content-type for each type of content you wish to have compressed. CDN servers will request only uncompressed content from the origin.

RedirectOptions

A set of the redirect parameters.

  • redirectHttpToHttps : BoolOption

    Using BoolOption. Set up a redirect from HTTPS to HTTP.

  • redirectHttpsToHttp : BoolOption

    Using BoolOption. Set up a redirect from HTTP to HTTPS.

HostOptions

A set of the host parameters.

  • host : StringOption

    Custom value for the Host header.

Your server must be able to process requests with the chosen header.

Default value (if StringOption.enabled is false) is Resource.cname.

  • forwardHostHeader : BoolOption
    Using [BoolOption][41]. Choose the Forward Host header option if is important to send in the request to the Origin

    the same Host header as was sent in the request to CDN server.

StringsMapOption

A set of the strings map parameters.

enabled : bool

True - the option is enabled and its value is applied to the resource. False - the option is disabled and its default value is used for the resource.

value : string

Value of the option.

RewriteOption

An option for changing or redirecting query paths.

enabled : bool

True - the option is enabled and its flag is applied to the resource. False - the option is disabled and its default value of the flag is used for the resource.

body : string

Pattern for rewrite.

The value must have the following format: <source path> <destination path>, where both paths are regular expressions which use at least one group. E.g., /foo/(.*) /bar/$1.

flag : RewriteFlag

Break flag is applied to the option by default. It is not shown in the field.

SecureKeyOption

enabled : bool

True - the option is enabled and its flag is applied to the resource. False - the option is disabled and its default value of the flag is used for the resource.

key : string

The key for the URL signing.

type : SecureKeyURLType

The type of the URL signing. The URL could be available for all IP addresses or for the only one IP.

IPAddressACLOption

enabled : bool

True - the option is enabled and its flag is applied to the resource. False - the option is disabled and its default value of the flag is used for the resource.

policyType : PolicyType

The policy type. One of allow or deny value.

exceptedValues : string

The list of IP addresses to be allowed or denied.

SSLCertificateData

A certificate data parameters.

One of sslCertificateDataVariant

  • cm : SSLCertificateCMData
    Custom (add your SSL certificate by uploading the certificate

    in PEM format and your private key).

SSLCertificateCMData

A certificate data custom parameters.

id : string

ID of the custom certificate.

Operation

An Operation resource. For more information, see Operation.

id : string

ID of the operation.

description : string

Description of the operation. 0-256 characters long.

createdAt : google.protobuf.Timestamp

Creation timestamp.

createdBy : string

ID of the user or service account who initiated the operation.

modifiedAt : google.protobuf.Timestamp

The time when the Operation resource was last modified.

done : bool

If the value is false, it means the operation is still in progress. If true, the operation is completed, and either error or response is available.

metadata : google.protobuf.Any

Service-specific metadata associated with the operation. It typically contains the ID of the target resource that the operation is performed on. Any method that returns a long-running operation should document the metadata type, if any.

One of result

The operation result. If done == false and there was no failure detected, neither error nor response is set. If done == false and there was a failure detected, error is set. If done == true, exactly one of error or response is set.

  • error : google.rpc.Status

    The error result of the operation in case of failure or cancellation.

  • response : google.protobuf.Any
    The normal response of the operation in case of success.

    If the original method returns no data on success, such as Delete, the response is google.protobuf.Empty. If the original method is the standard Create/Update, the response should be the target resource of the operation. Any method that returns a long-running operation should document the response type, if any.