UpdateRoute
Updates the specified route of the specified virtual host.
- TypeScript
- Python
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);
}
})();
import os
import grpc
import yandexcloud
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import DirectResponseAction
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import GrpcRoute
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import GrpcRouteAction
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import GrpcRouteMatch
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import GrpcStatusResponseAction
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import HeaderModification
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import HttpRoute
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import HttpRouteAction
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import HttpRouteMatch
from yandex.cloud.apploadbalancer.v1.payload_pb2 import Payload
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import Principal
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import Principals
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import RBAC
from yandex.cloud.apploadbalancer.v1.rate_limit_pb2 import RateLimit
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import RedirectAction
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import RouteOptions
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import StringMatch
from yandex.cloud.apploadbalancer.v1.virtual_host_service_pb2 import UpdateRouteMetadata
from yandex.cloud.apploadbalancer.v1.virtual_host_service_pb2 import UpdateRouteRequest
from yandex.cloud.apploadbalancer.v1.virtual_host_pb2 import VirtualHost
from yandex.cloud.apploadbalancer.v1.virtual_host_service_pb2_grpc import VirtualHostServiceStub
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(VirtualHostServiceStub)
operation = service.UpdateRoute(
UpdateRouteRequest(
http_router_id="httpRouterId",
virtual_host_name="virtualHostName",
route_name="routeName",
# update_mask = FieldMask.FromJsonString("field1,field2"),
# http = HttpRoute(
# match = HttpRouteMatch(
# http_method = ["httpMethod"],
# path = StringMatch(
# exact_match = "exactMatch",
# prefix_match = "prefixMatch",
# regex_match = "regexMatch"
# )
# ),
# route = HttpRouteAction(
# backend_group_id = "backendGroupId",
# timeout = Duration(
# seconds = 0,
# nanos = 0
# ),
# idle_timeout = Duration(
# seconds = 0,
# nanos = 0
# ),
# host_rewrite = "hostRewrite",
# auto_host_rewrite = true,
# prefix_rewrite = "prefixRewrite",
# upgrade_types = ["upgradeTypes"],
# rate_limit = RateLimit(
# all_requests = RateLimit.Limit(
# per_second = 0,
# per_minute = 0
# ),
# requests_per_ip = RateLimit.Limit(
# per_second = 0,
# per_minute = 0
# )
# )
# ),
# redirect = RedirectAction(
# replace_scheme = "replaceScheme",
# replace_host = "replaceHost",
# replace_port = 0,
# replace_path = "replacePath",
# replace_prefix = "replacePrefix",
# remove_query = true,
# response_code = RedirectAction.RedirectResponseCode.FOUND
# ),
# direct_response = DirectResponseAction(
# status = 0,
# body = Payload(
# text = "text"
# )
# )
# ),
# grpc = GrpcRoute(
# match = GrpcRouteMatch(
# fqmn = StringMatch(
# exact_match = "exactMatch",
# prefix_match = "prefixMatch",
# regex_match = "regexMatch"
# )
# ),
# route = GrpcRouteAction(
# backend_group_id = "backendGroupId",
# max_timeout = Duration(
# seconds = 0,
# nanos = 0
# ),
# idle_timeout = Duration(
# seconds = 0,
# nanos = 0
# ),
# host_rewrite = "hostRewrite",
# auto_host_rewrite = true,
# rate_limit = RateLimit(
# all_requests = RateLimit.Limit(
# per_second = 0,
# per_minute = 0
# ),
# requests_per_ip = RateLimit.Limit(
# per_second = 0,
# per_minute = 0
# )
# )
# ),
# status_response = GrpcStatusResponseAction(
# status = GrpcStatusResponseAction.Status.INVALID_ARGUMENT
# )
# ),
# route_options = RouteOptions(
# modify_request_headers = [HeaderModification(
# name = "name",
# append = "append",
# replace = "replace",
# remove = true,
# rename = "rename"
# )],
# modify_response_headers = [HeaderModification(
# name = "name",
# append = "append",
# replace = "replace",
# remove = true,
# rename = "rename"
# )],
# rbac = RBAC(
# action = RBAC.Action.ALLOW,
# principals = [Principals(
# and_principals = [Principal(
# header = Principal.HeaderMatcher(
# name = "name",
# value = StringMatch(
# exact_match = "exactMatch",
# prefix_match = "prefixMatch",
# regex_match = "regexMatch"
# )
# ),
# remote_ip = "remoteIp",
# any = true
# )]
# )]
# ),
# security_profile_id = "securityProfileId"
# )
)
)
operation_result = sdk.wait_operation_and_get_result(
operation,
response_type=VirtualHost,
meta_type=UpdateRouteMetadata,
)
print(operation_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.
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
: HttpRouteActionForwards the request to a backend group for processing as configured.
redirect
: RedirectActionRedirects the request as configured.
directResponse
: DirectResponseActionInstructs the load balancer to respond directly as configured.
GrpcRoute
A gRPC route configuration resource.
match
: GrpcRouteMatch
Condition (predicate) used to select the route.
route
: GrpcRouteActionForwards the request to a backend group for processing as configured.
statusResponse
: GrpcStatusResponseActionInstructs 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
: stringHost replacement.
autoHostRewrite
: boolAutomatically 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
: stringReplacement for the whole path.
replacePrefix
: stringReplacement 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
: stringHost replacement.
autoHostRewrite
: boolAutomatically 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
: stringAppends the specified string to the header value.
Variables defined for Envoy proxy are supported.
replace
: stringReplaces the value of the header with the specified string.
Variables defined for Envoy proxy are supported.
remove
: boolRemoves the header.
rename
: stringReplaces 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
: stringExact match string.
prefixMatch
: stringPrefix match string.
regexMatch
: stringRegular 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
: int64PerSecond is a limit value specified with per second time unit.
perMinute
: int64PerMinute 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
: stringPayload 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
: int64PerSecond is a limit value specified with per second time unit.
perMinute
: int64PerMinute 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
: HeaderMatcherA header (or pseudo-header such as :path or :method) of the incoming HTTP request.
remoteIp
: stringA CIDR block or IP that describes the request remote/origin address, e.g.
192.0.0.0/24
or192.0.0.4
.any
: boolWhen 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.StatusThe error result of the operation in case of failure or cancellation.
response
: google.protobuf.AnyThe 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.