forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appmesh): add Route matching on path, query parameters, metadata…
…, and method name (aws#15470) Adding new match properties for `Route`. - For HTTP match, adding `path` and `queryParameters`. Remove `prefixPath`. - For gRPC match, adding `metadata` and `method name` BREAKING CHANGE: `prefixPath` property in `HttpRouteMatch` has been renamed to `path`, and its type changed from `string` to `HttpRoutePathMatch` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
10 changed files
with
893 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
packages/@aws-cdk/aws-appmesh/lib/http-route-path-match.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { CfnRoute } from './appmesh.generated'; | ||
|
||
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main | ||
// eslint-disable-next-line no-duplicate-imports, import/order | ||
import { Construct } from '@aws-cdk/core'; | ||
|
||
/** | ||
* The type returned from the `bind()` method in {@link HttpRoutePathMatch}. | ||
*/ | ||
export interface HttpRoutePathMatchConfig { | ||
/** | ||
* Route configuration for matching on the complete URL path of the request. | ||
* | ||
* @default - no matching will be performed on the complete URL path | ||
*/ | ||
readonly wholePathMatch?: CfnRoute.HttpPathMatchProperty; | ||
|
||
/** | ||
* Route configuration for matching on the prefix of the URL path of the request. | ||
* | ||
* @default - no matching will be performed on the prefix of the URL path | ||
*/ | ||
readonly prefixPathMatch?: string; | ||
} | ||
|
||
/** | ||
* Defines HTTP route matching based on the URL path of the request. | ||
*/ | ||
export abstract class HttpRoutePathMatch { | ||
/** | ||
* The value of the path must match the specified value exactly. | ||
* The provided `path` must start with the '/' character. | ||
* | ||
* @param path the exact path to match on | ||
*/ | ||
public static exactly(path: string): HttpRoutePathMatch { | ||
return new HttpRouteWholePathMatch({ exact: path }); | ||
} | ||
|
||
/** | ||
* The value of the path must match the specified regex. | ||
* | ||
* @param regex the regex used to match the path | ||
*/ | ||
public static regex(regex: string): HttpRoutePathMatch { | ||
return new HttpRouteWholePathMatch({ regex: regex }); | ||
} | ||
|
||
/** | ||
* The value of the path must match the specified prefix. | ||
* | ||
* @param prefix the value to use to match the beginning of the path part of the URL of the request. | ||
* It must start with the '/' character. If provided as "/", matches all requests. | ||
* For example, if your virtual service name is "my-service.local" | ||
* and you want the route to match requests to "my-service.local/metrics", your prefix should be "/metrics". | ||
*/ | ||
public static startsWith(prefix: string): HttpRoutePathMatch { | ||
return new HttpRoutePrefixPathMatch(prefix); | ||
} | ||
|
||
/** | ||
* Returns the route path match configuration. | ||
*/ | ||
public abstract bind(scope: Construct): HttpRoutePathMatchConfig; | ||
} | ||
|
||
class HttpRoutePrefixPathMatch extends HttpRoutePathMatch { | ||
constructor(private readonly prefix: string) { | ||
super(); | ||
|
||
if (this.prefix && this.prefix[0] !== '/') { | ||
throw new Error(`Prefix Path for the match must start with \'/\', got: ${this.prefix}`); | ||
} | ||
} | ||
|
||
bind(_scope: Construct): HttpRoutePathMatchConfig { | ||
return { | ||
prefixPathMatch: this.prefix, | ||
}; | ||
} | ||
} | ||
|
||
class HttpRouteWholePathMatch extends HttpRoutePathMatch { | ||
constructor(private readonly match: CfnRoute.HttpPathMatchProperty) { | ||
super(); | ||
|
||
if (this.match.exact && this.match.exact[0] !== '/') { | ||
throw new Error(`Exact Path for the match must start with \'/\', got: ${this.match.exact}`); | ||
} | ||
} | ||
|
||
bind(_scope: Construct): HttpRoutePathMatchConfig { | ||
return { | ||
wholePathMatch: this.match, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/@aws-cdk/aws-appmesh/lib/query-parameter-match.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { CfnRoute } from './appmesh.generated'; | ||
|
||
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main | ||
// eslint-disable-next-line no-duplicate-imports, import/order | ||
import { Construct } from '@aws-cdk/core'; | ||
|
||
/** | ||
* Configuration for `QueryParameterMatch` | ||
*/ | ||
export interface QueryParameterMatchConfig { | ||
/** | ||
* Route CFN configuration for route query parameter match. | ||
*/ | ||
readonly queryParameterMatch: CfnRoute.QueryParameterProperty; | ||
} | ||
|
||
/** | ||
* Used to generate query parameter matching methods. | ||
*/ | ||
export abstract class QueryParameterMatch { | ||
/** | ||
* The value of the query parameter with the given name in the request must match the | ||
* specified value exactly. | ||
* | ||
* @param queryParameterName the name of the query parameter to match against | ||
* @param queryParameterValue The exact value to test against | ||
*/ | ||
static valueIs(queryParameterName: string, queryParameterValue: string): QueryParameterMatch { | ||
return new QueryParameterMatchImpl(queryParameterName, { exact: queryParameterValue }); | ||
} | ||
|
||
/** | ||
* Returns the query parameter match configuration. | ||
*/ | ||
public abstract bind(scope: Construct): QueryParameterMatchConfig; | ||
} | ||
|
||
class QueryParameterMatchImpl extends QueryParameterMatch { | ||
constructor( | ||
private readonly queryParameterName: string, | ||
private readonly matchProperty: CfnRoute.HttpQueryParameterMatchProperty, | ||
) { | ||
super(); | ||
} | ||
|
||
bind(_scope: Construct): QueryParameterMatchConfig { | ||
return { | ||
queryParameterMatch: { | ||
match: this.matchProperty, | ||
name: this.queryParameterName, | ||
}, | ||
}; | ||
} | ||
} |
Oops, something went wrong.