import { Construct } from 'constructs'; import Secret from './Secret'; import { Password } from '../generated/providers/random'; import { getId } from '../utils'; export default class DatabaseCredentials extends Construct { readonly username: string; readonly password: string; constructor(scope: Construct, id: string) { super(scope, id); // store username and password if not previously setup const dbUsername = new Password(this, 'username', { length: 24, special: false, }); const { value: dbUsernameValue } = new Secret( this, getId('db', 'username'), { secretString: `db${dbUsername.result}`, } ); const dbPassword = new Password(this, 'password', { length: 24, special: false, }); const { value: dbPasswordValue } = new Secret( this, getId('db', 'password'), { secretString: dbPassword.result, } ); this.username = dbUsernameValue; this.password = dbPasswordValue; } }