-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rds): split DatabaseClusterEngine and DatabaseInstanceEngine into…
… separate types Currently, InstanceEngine extended ClusterEngine, which meant you could pass InstanceEngine when creating a Cluster, which would fail at deploy time. This change splits the two classes into distinct types, without a subtyping relationship between the two.
- Loading branch information
Showing
8 changed files
with
245 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; | ||
import { BaseEngine } from './engine'; | ||
|
||
/** | ||
* A database cluster engine. Provides mapping to the serverless application | ||
* used for secret rotation. | ||
*/ | ||
export class DatabaseClusterEngine extends BaseEngine { | ||
public static readonly AURORA = new DatabaseClusterEngine( | ||
'aurora', | ||
secretsmanager.SecretRotationApplication.MYSQL_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.MYSQL_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '5.6', parameterGroupFamily: 'aurora5.6' }, | ||
], | ||
); | ||
|
||
public static readonly AURORA_MYSQL = new DatabaseClusterEngine( | ||
'aurora-mysql', | ||
secretsmanager.SecretRotationApplication.MYSQL_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.MYSQL_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '5.7', parameterGroupFamily: 'aurora-mysql5.7' }, | ||
], | ||
); | ||
|
||
public static readonly AURORA_POSTGRESQL = new DatabaseClusterEngine( | ||
'aurora-postgresql', | ||
secretsmanager.SecretRotationApplication.POSTGRES_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.POSTGRES_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '9.6', parameterGroupFamily: 'aurora-postgresql9.6' }, | ||
{ engineMajorVersion: '10', parameterGroupFamily: 'aurora-postgresql10' }, | ||
{ engineMajorVersion: '11', parameterGroupFamily: 'aurora-postgresql11' }, | ||
], | ||
); | ||
|
||
/** | ||
* Get the latest parameter group family for this engine. Latest is determined using semver on the engine major version. | ||
* When `engineVersion` is specified, return the parameter group family corresponding to that engine version. | ||
* Return undefined if no parameter group family is defined for this engine or for the requested `engineVersion`. | ||
*/ | ||
public parameterGroupFamily(engineVersion?: string): string | undefined { | ||
return this.calculateParameterGroupForEngineVersion(engineVersion); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; | ||
import { compare } from './private/version'; | ||
import { ParameterGroupFamily } from './props'; | ||
|
||
/** @internal */ | ||
export abstract class BaseEngine { | ||
/** | ||
* The engine. | ||
*/ | ||
public readonly name: string; | ||
|
||
/** | ||
* The single user secret rotation application. | ||
*/ | ||
public readonly singleUserRotationApplication: secretsmanager.SecretRotationApplication; | ||
|
||
/** | ||
* The multi user secret rotation application. | ||
*/ | ||
public readonly multiUserRotationApplication: secretsmanager.SecretRotationApplication; | ||
|
||
private readonly parameterGroupFamilies?: ParameterGroupFamily[]; | ||
|
||
constructor( | ||
name: string, | ||
singleUserRotationApplication: secretsmanager.SecretRotationApplication, | ||
multiUserRotationApplication: secretsmanager.SecretRotationApplication, | ||
parameterGroupFamilies?: ParameterGroupFamily[]) { | ||
|
||
this.name = name; | ||
this.singleUserRotationApplication = singleUserRotationApplication; | ||
this.multiUserRotationApplication = multiUserRotationApplication; | ||
this.parameterGroupFamilies = parameterGroupFamilies; | ||
} | ||
|
||
protected calculateParameterGroupForEngineVersion(engineVersion: string | undefined) { | ||
if (this.parameterGroupFamilies === undefined) { | ||
return undefined; | ||
} | ||
if (engineVersion) { | ||
const family = this.parameterGroupFamilies.find(x => engineVersion.startsWith(x.engineMajorVersion)); | ||
if (family) { | ||
return family.parameterGroupFamily; | ||
} | ||
} else if (this.parameterGroupFamilies.length > 0) { | ||
const sorted = this.parameterGroupFamilies.slice().sort((a, b) => { | ||
return compare(a.engineMajorVersion, b.engineMajorVersion); | ||
}).reverse(); | ||
return sorted[0].parameterGroupFamily; | ||
} | ||
return undefined; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import * as secretsmanager from '@aws-cdk/aws-secretsmanager'; | ||
import { BaseEngine } from './engine'; | ||
|
||
/** | ||
* A database instance engine. Provides mapping to DatabaseEngine used for | ||
* secret rotation. | ||
*/ | ||
export class DatabaseInstanceEngine extends BaseEngine { | ||
public static readonly MARIADB = new DatabaseInstanceEngine( | ||
'mariadb', | ||
secretsmanager.SecretRotationApplication.MARIADB_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.MARIADB_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '10.0', parameterGroupFamily: 'mariadb10.0' }, | ||
{ engineMajorVersion: '10.1', parameterGroupFamily: 'mariadb10.1' }, | ||
{ engineMajorVersion: '10.2', parameterGroupFamily: 'mariadb10.2' }, | ||
{ engineMajorVersion: '10.3', parameterGroupFamily: 'mariadb10.3' }, | ||
], | ||
); | ||
|
||
public static readonly MYSQL = new DatabaseInstanceEngine( | ||
'mysql', | ||
secretsmanager.SecretRotationApplication.MYSQL_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.MYSQL_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '5.6', parameterGroupFamily: 'mysql5.6' }, | ||
{ engineMajorVersion: '5.7', parameterGroupFamily: 'mysql5.7' }, | ||
{ engineMajorVersion: '8.0', parameterGroupFamily: 'mysql8.0' }, | ||
], | ||
); | ||
|
||
public static readonly ORACLE_EE = new DatabaseInstanceEngine( | ||
'oracle-ee', | ||
secretsmanager.SecretRotationApplication.ORACLE_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.ORACLE_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '11.2', parameterGroupFamily: 'oracle-ee-11.2' }, | ||
{ engineMajorVersion: '12.1', parameterGroupFamily: 'oracle-ee-12.1' }, | ||
{ engineMajorVersion: '12.2', parameterGroupFamily: 'oracle-ee-12.2' }, | ||
{ engineMajorVersion: '18', parameterGroupFamily: 'oracle-ee-18' }, | ||
{ engineMajorVersion: '19', parameterGroupFamily: 'oracle-ee-19' }, | ||
], | ||
); | ||
|
||
public static readonly ORACLE_SE2 = new DatabaseInstanceEngine( | ||
'oracle-se2', | ||
secretsmanager.SecretRotationApplication.ORACLE_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.ORACLE_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '12.1', parameterGroupFamily: 'oracle-se2-12.1' }, | ||
{ engineMajorVersion: '12.2', parameterGroupFamily: 'oracle-se2-12.2' }, | ||
{ engineMajorVersion: '18', parameterGroupFamily: 'oracle-se2-18' }, | ||
{ engineMajorVersion: '19', parameterGroupFamily: 'oracle-se2-19' }, | ||
], | ||
); | ||
|
||
public static readonly ORACLE_SE1 = new DatabaseInstanceEngine( | ||
'oracle-se1', | ||
secretsmanager.SecretRotationApplication.ORACLE_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.ORACLE_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '11.2', parameterGroupFamily: 'oracle-se1-11.2' }, | ||
], | ||
); | ||
|
||
public static readonly ORACLE_SE = new DatabaseInstanceEngine( | ||
'oracle-se', | ||
secretsmanager.SecretRotationApplication.ORACLE_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.ORACLE_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '11.2', parameterGroupFamily: 'oracle-se-11.2' }, | ||
], | ||
); | ||
|
||
public static readonly POSTGRES = new DatabaseInstanceEngine( | ||
'postgres', | ||
secretsmanager.SecretRotationApplication.POSTGRES_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.POSTGRES_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '9.3', parameterGroupFamily: 'postgres9.3' }, | ||
{ engineMajorVersion: '9.4', parameterGroupFamily: 'postgres9.4' }, | ||
{ engineMajorVersion: '9.5', parameterGroupFamily: 'postgres9.5' }, | ||
{ engineMajorVersion: '9.6', parameterGroupFamily: 'postgres9.6' }, | ||
{ engineMajorVersion: '10', parameterGroupFamily: 'postgres10' }, | ||
{ engineMajorVersion: '11', parameterGroupFamily: 'postgres11' }, | ||
], | ||
); | ||
|
||
public static readonly SQL_SERVER_EE = new DatabaseInstanceEngine( | ||
'sqlserver-ee', | ||
secretsmanager.SecretRotationApplication.SQLSERVER_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.SQLSERVER_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '11', parameterGroupFamily: 'sqlserver-ee-11.0' }, | ||
{ engineMajorVersion: '12', parameterGroupFamily: 'sqlserver-ee-12.0' }, | ||
{ engineMajorVersion: '13', parameterGroupFamily: 'sqlserver-ee-13.0' }, | ||
{ engineMajorVersion: '14', parameterGroupFamily: 'sqlserver-ee-14.0' }, | ||
], | ||
); | ||
|
||
public static readonly SQL_SERVER_SE = new DatabaseInstanceEngine( | ||
'sqlserver-se', | ||
secretsmanager.SecretRotationApplication.SQLSERVER_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.SQLSERVER_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '11', parameterGroupFamily: 'sqlserver-se-11.0' }, | ||
{ engineMajorVersion: '12', parameterGroupFamily: 'sqlserver-se-12.0' }, | ||
{ engineMajorVersion: '13', parameterGroupFamily: 'sqlserver-se-13.0' }, | ||
{ engineMajorVersion: '14', parameterGroupFamily: 'sqlserver-se-14.0' }, | ||
], | ||
); | ||
|
||
public static readonly SQL_SERVER_EX = new DatabaseInstanceEngine( | ||
'sqlserver-ex', | ||
secretsmanager.SecretRotationApplication.SQLSERVER_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.SQLSERVER_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '11', parameterGroupFamily: 'sqlserver-ex-11.0' }, | ||
{ engineMajorVersion: '12', parameterGroupFamily: 'sqlserver-ex-12.0' }, | ||
{ engineMajorVersion: '13', parameterGroupFamily: 'sqlserver-ex-13.0' }, | ||
{ engineMajorVersion: '14', parameterGroupFamily: 'sqlserver-ex-14.0' }, | ||
], | ||
); | ||
|
||
public static readonly SQL_SERVER_WEB = new DatabaseInstanceEngine( | ||
'sqlserver-web', | ||
secretsmanager.SecretRotationApplication.SQLSERVER_ROTATION_SINGLE_USER, | ||
secretsmanager.SecretRotationApplication.SQLSERVER_ROTATION_MULTI_USER, | ||
[ | ||
{ engineMajorVersion: '11', parameterGroupFamily: 'sqlserver-web-11.0' }, | ||
{ engineMajorVersion: '12', parameterGroupFamily: 'sqlserver-web-12.0' }, | ||
{ engineMajorVersion: '13', parameterGroupFamily: 'sqlserver-web-13.0' }, | ||
{ engineMajorVersion: '14', parameterGroupFamily: 'sqlserver-web-14.0' }, | ||
], | ||
); | ||
|
||
/** To make it a compile-time error to pass a DatabaseClusterEngine where a DatabaseInstanceEngine is expected. */ | ||
public readonly isDatabaseInstanceEngine = true; | ||
} |
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
Oops, something went wrong.