Skip to main content

UpdateRoute

Updates the specified route of the specified virtual host.

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

const GrpcStatusResponseAction_Status =
cloudApi.apploadbalancer.virtual_host.GrpcStatusResponseAction_Status;
const RBAC_Action = cloudApi.apploadbalancer.virtual_host.RBAC_Action;
const RedirectAction_RedirectResponseCode =
cloudApi.apploadbalancer.virtual_host.RedirectAction_RedirectResponseCode;
const UpdateRouteRequest =
cloudApi.apploadbalancer.virtual_host_service.UpdateRouteRequest;
const VirtualHost = cloudApi.apploadbalancer.virtual_host.VirtualHost;

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

const operation = await client.updateRoute(
UpdateRouteRequest.fromPartial({
httpRouterId: "httpRouterId",
virtualHostName: "virtualHostName",
routeName: "routeName",
// updateMask: {
// paths: ["paths"]
// },
// http: {
// match: {
// httpMethod: ["httpMethod"],
// path: {
// exactMatch: "exactMatch",
// prefixMatch: "prefixMatch",
// regexMatch: "regexMatch"
// }
// },
// route: {
// backendGroupId: "backendGroupId",
// timeout: {
// seconds: 0,
// nanos: 0
// },
// idleTimeout: {
// seconds: 0,
// nanos: 0
// },
// hostRewrite: "hostRewrite",
// autoHostRewrite: true,
// prefixRewrite: "prefixRewrite",
// upgradeTypes: ["upgradeTypes"],
// rateLimit: {
// allRequests: {
// perSecond: 0,
// perMinute: 0
// },
// requestsPerIp: {
// perSecond: 0,
// perMinute: 0
// }
// }
// },
// redirect: {
// replaceScheme: "replaceScheme",
// replaceHost: "replaceHost",
// replacePort: 0,
// replacePath: "replacePath",
// replacePrefix: "replacePrefix",
// removeQuery: true,
// responseCode: RedirectAction_RedirectResponseCode.FOUND
// },
// directResponse: {
// status: 0,
// body: {
// text: "text"
// }
// }
// },
// grpc: {
// match: {
// fqmn: {
// exactMatch: "exactMatch",
// prefixMatch: "prefixMatch",
// regexMatch: "regexMatch"
// }
// },
// route: {
// backendGroupId: "backendGroupId",
// maxTimeout: {
// seconds: 0,
// nanos: 0
// },
// idleTimeout: {
// seconds: 0,
// nanos: 0
// },
// hostRewrite: "hostRewrite",
// autoHostRewrite: true,
// rateLimit: {
// allRequests: {
// perSecond: 0,
// perMinute: 0
// },
// requestsPerIp: {
// perSecond: 0,
// perMinute: 0
// }
// }
// },
// statusResponse: {
// status: GrpcStatusResponseAction_Status.INVALID_ARGUMENT
// }
// },
// routeOptions: {
// modifyRequestHeaders: [{
// name: "name",
// append: "append",
// replace: "replace",
// remove: true,
// rename: "rename"
// }],
// modifyResponseHeaders: [{
// name: "name",
// append: "append",
// replace: "replace",
// remove: true,
// rename: "rename"
// }],
// rbac: {
// action: RBAC_Action.ALLOW,
// principals: [{
// andPrincipals: [{
// header: {
// name: "name",
// value: {
// exactMatch: "exactMatch",
// prefixMatch: "prefixMatch",
// regexMatch: "regexMatch"
// }
// },
// remoteIp: "remoteIp",
// any: true
// }]
// }]
// },
// securityProfileId: "securityProfileId"
// }
})
);
const finishedOp = await waitForOperation(operation, session);

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

UpdateRouteRequest

httpRouterId : string

ID of the HTTP router to update a route in.

To get the HTTP router ID, make a HttpRouterService.List request.

virtualHostName : string

Name of the virtual host to update a route in.

To get the virtual host name, make a VirtualHostService.List request.

routeName : string

Name of the route to update.

To get the route name, make a VirtualHostService.Get request.

updateMask : google.protobuf.FieldMask

Field mask that specifies which attributes of the route should be updated.

One of route

New settings of the route.

  • http : HttpRoute

    New settings of the HTTP route.

  • grpc : GrpcRoute

    New settings of the gRPC route.

routeOptions : RouteOptions

New route options for the route.

HttpRoute

An HTTP route configuration resource.

match : HttpRouteMatch

Condition (predicate) used to select the route.

One of action

Action performed on the request if the route is selected.

  • route : HttpRouteAction

    Forwards the request to a backend group for processing as configured.

  • redirect : RedirectAction

    Redirects the request as configured.

  • directResponse : DirectResponseAction

    Instructs the load balancer to respond directly as configured.

GrpcRoute

A gRPC route configuration resource.

match : GrpcRouteMatch

Condition (predicate) used to select the route.

  • route : GrpcRouteAction

    Forwards the request to a backend group for processing as configured.

  • statusResponse : GrpcStatusResponseAction

    Instructs the load balancer to respond directly with a specified status.

RouteOptions

modifyRequestHeaders : HeaderModification

Apply the following modifications to the request headers.

modifyResponseHeaders : HeaderModification

Apply the following modifications to the response headers.

rbac : RBAC
securityProfileId : string

Security profile that will take effect to all requests routed via particular virtual host.

HttpRouteMatch

An HTTP route condition (predicate) resource.

httpMethod : string

HTTP method specified in the request.

path : StringMatch

Match settings for the path specified in the request.

If not specified, the route matches all paths.

HttpRouteAction

An HTTP route action resource.

backendGroupId : string

Backend group to forward requests to.

Stream (TCP) backend groups are not supported.

timeout : google.protobuf.Duration

Overall timeout for an HTTP connection between a load balancer node an a backend from the backend group: the maximum time the connection is kept alive for, regardless of whether data is transferred over it.

If a connection times out, the load balancer responds to the client with a 504 Gateway Timeout status code.

Default value: 60.

idleTimeout : google.protobuf.Duration

Idle timeout for an HTTP connection between a load balancer node an a backend from the backend group: the maximum time the connection is allowed to be idle, i.e. without any data transferred over it.

Specifying meaningful values for both timeout and idle_timeout is useful for implementing server-push mechanisms such as long polling, server-sent events (EventSource interface) etc.

If a connection times out, the load balancer responds to the client with a 504 Gateway Timeout status code.

If not specified, no idle timeout is used, and an alive connection may be idle for any duration (see timeout).

One of hostRewriteSpecifier

Value rewrite settings for HTTP/1.1 Host headers and HTTP/2 :authority pseudo-headers.

If not specified, the host is not changed.

  • hostRewrite : string

    Host replacement.

  • autoHostRewrite : bool

    Automatically replaces the host with that of the target.

prefixRewrite : string

Replacement for the path prefix matched by StringMatch.

For instance, if StringMatch.prefix_match value is /foo and prefix_rewrite value is /bar, a request with /foobaz path is forwarded with /barbaz path. For StringMatch.exact_match, the whole path is replaced.

If not specified, the path is not changed.

upgradeTypes : string

Supported values for HTTP Upgrade header. E.g. websocket.

rateLimit : RateLimit

RateLimit is a rate limit configuration applied for route.

RedirectAction

A redirect action resource.

RedirectResponseCode

HTTP status codes supported for use in redirect responses.

  • MOVED_PERMANENTLY

    301 Moved Permanently status code.

  • FOUND

    302 Found status code.

  • SEE_OTHER

    303 See Other status code.

  • TEMPORARY_REDIRECT

    307 Temporary Redirect status code.

  • PERMANENT_REDIRECT

    308 Permanent Redirect status code.

replaceScheme : string

URI scheme replacement.

If http or https scheme is to be replaced and 80 or 443 port is specified in the original URI, the port is also removed.

If not specified, the original scheme and port are used.

replaceHost : string

URI host replacement.

If not specified, the original host is used.

replacePort : int64

URI host replacement.

If not specified, the original host is used.

One of path

URI path replacement.

If not specified, the original path is used.

  • replacePath : string

    Replacement for the whole path.

  • replacePrefix : string

    Replacement for the path prefix matched by StringMatch.

For instance, if StringMatch.prefix_match value is /foo and replace_prefix value is /bar, a request with https://example.com/foobaz URI is redirected to https://example.com/barbaz. For StringMatch.exact_match, the whole path is replaced.

removeQuery : bool

Removes URI query.

responseCode : RedirectResponseCode

HTTP status code to use in redirect responses.

DirectResponseAction

A direct response action resource.

status : int64

HTTP status code to use in responses.

body : Payload

Response body.

GrpcRouteMatch

A gRPC route condition (predicate) resource.

fqmn : StringMatch

Match settings for gRPC service method called in the request.

A match string must be a fully qualified method name, e.g. foo.bar.v1.BazService/Get, or a prefix of such.

If not specified, the route matches all methods.

GrpcRouteAction

A gRPC route action resource.

backendGroupId : string

Backend group to forward requests to.

maxTimeout : google.protobuf.Duration

Overall timeout for an underlying HTTP connection between a load balancer node an a backend from the backend group: the maximum time the connection is kept alive for, regardless of whether data is transferred over it.

If a client specifies a lower timeout in HTTP grpc-timeout header, the max_timeout value is ignored.

If a connection times out, the load balancer responds to the client with an UNAVAILABLE status code.

Default value: 60.

idleTimeout : google.protobuf.Duration

Idle timeout for an underlying HTTP connection between a load balancer node an a backend from the backend group: the maximum time the connection is allowed to be idle, i.e. without any data transferred over it.

Specifying meaningful values for both max_timeout and idle_timeout is useful for implementing server-push mechanisms such as long polling, server-sent events etc.

If a connection times out, the load balancer responds to the client with an UNAVAILABLE status code.

If not specified, no idle timeout is used, and an alive connection may be idle for any duration (see max_timeout).

  • hostRewrite : string

    Host replacement.

  • autoHostRewrite : bool

    Automatically replaces the host with that of the target.

rateLimit : RateLimit

RateLimit is a rate limit configuration applied for route.

GrpcStatusResponseAction

A gRPC status response action resource.

Status

gRPC status code supported for use in responses.

  • OK

    OK (0) status code.

  • INVALID_ARGUMENT

    INVALID_ARGUMENT (3) status code.

  • NOT_FOUND

    NOT_FOUND (5) status code.

  • PERMISSION_DENIED

    PERMISSION_DENIED (7) status code.

  • UNAUTHENTICATED

    UNAUTHENTICATED (16) status code.

  • UNIMPLEMENTED

    UNIMPLEMENTED (12) status code.

  • INTERNAL

    INTERNAL (13) status code.

  • UNAVAILABLE

    UNAVAILABLE (14) status code.

status : Status

gRPC status code to use in responses.

HeaderModification

A header modification resource.

name : string

Name of the header.

One of operation

Operation to perform on the header.

  • append : string

    Appends the specified string to the header value.

Variables defined for Envoy proxy are supported.

  • replace : string

    Replaces the value of the header with the specified string.

Variables defined for Envoy proxy are supported.

  • remove : bool

    Removes the header.

  • rename : string
    Replaces the name of the header with the specified string.

    This operation is only supported for ALB Virtual Hosts.

RBAC

Role Based Access Control (RBAC) provides router, virtual host, and route access control for the ALB service. Requests are allowed or denied based on the action and whether a matching principal is found. For instance, if the action is ALLOW and a matching principal is found the request should be allowed.

Action
  • ACTION_UNSPECIFIED

  • ALLOW

    Allows the request if and only if there is a principal that matches the request.

  • DENY

    Allows the request if and only if there are no principal that match the request.

action : Action

The action to take if a principal matches. Every action either allows or denies a request.

principals : Principals

Required. A match occurs when at least one matches the request.

StringMatch

A string matcher resource.

One of match

Match string for either exact or prefix match.

  • exactMatch : string

    Exact match string.

  • prefixMatch : string

    Prefix match string.

  • regexMatch : string

    Regular expression match string.

RateLimit

RateLimit is a set of settings for global rate limiting.

Limit

Limit is a rate limit value settings.

One of rate

  • perSecond : int64

    PerSecond is a limit value specified with per second time unit.

  • perMinute : int64

    PerMinute is a limit value specified with per minute time unit.

allRequests : Limit

AllRequests is a rate limit configuration applied to all incoming requests.

requestsPerIp : Limit

RequestsPerIp is a rate limit configuration applied separately for each set of requests grouped by client IP address.

Payload

A health check payload resource.

One of payload

Payload.

  • text : string

    Payload text.

Principals

Principals define a group of identities for a request.

andPrincipals : Principal

Required. A match occurs when all principals match the request.

Limit

Limit is a rate limit value settings.

  • perSecond : int64

    PerSecond is a limit value specified with per second time unit.

  • perMinute : int64

    PerMinute is a limit value specified with per minute time unit.

Principal

Principal defines an identity for a request.

HeaderMatcher
name : string

Specifies the name of the header in the request.

value : StringMatch

Specifies how the header match will be performed to route the request. In the absence of value a request that has specified header name will match, regardless of the header's value.

One of identifier

  • header : HeaderMatcher

    A header (or pseudo-header such as :path or :method) of the incoming HTTP request.

  • remoteIp : string

    A CIDR block or IP that describes the request remote/origin address, e.g. 192.0.0.0/24 or192.0.0.4 .

  • any : bool

    When any is set, it matches any request.

HeaderMatcher

name : string

Specifies the name of the header in the request.

value : StringMatch

Specifies how the header match will be performed to route the request. In the absence of value a request that has specified header name will match, regardless of the header's value.

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.