Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-certificatemanager) export dns-validated-certificate #1985

Merged
merged 4 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-certificatemanager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ zone `example.com` that provides authoritative records for the domain.

```ts
import { HostedZoneProvider } from '@aws-cdk/aws-route53';
import { DNSValidatedCertificate } from '@aws-cdk/aws-certificatemanager';
import { DnsValidatedCertificate } from '@aws-cdk/aws-certificatemanager';

const hostedZone = new HostedZoneProvider(this, {
domainName: 'example.com',
privateZone: false
}).findAndImport(this, 'ExampleDotCom');

const certificate = new DNSValidatedCertificate(this, 'TestCertificate', {
const certificate = new DnsValidatedCertificate(this, 'TestCertificate', {
domainName: 'test.example.com',
hostedZone: hostedZone
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cdk = require('@aws-cdk/cdk');
import path = require('path');
import { CertificateImportProps, CertificateProps, ICertificate } from './certificate';

export interface DNSValidatedCertificateProps extends CertificateProps {
export interface DnsValidatedCertificateProps extends CertificateProps {
/**
* Route 53 Hosted Zone used to perform DNS validation of the request. The zone
* must be authoritative for the domain name specified in the Certificate Request.
Expand All @@ -18,13 +18,13 @@ export interface DNSValidatedCertificateProps extends CertificateProps {
* A certificate managed by AWS Certificate Manager. Will be automatically
* validated using DNS validation against the specified Route 53 hosted zone.
*/
export class DNSValidatedCertificate extends cdk.Construct implements ICertificate {
export class DnsValidatedCertificate extends cdk.Construct implements ICertificate {
public readonly certificateArn: string;
private normalizedZoneName: string;
private hostedZoneId: string;
private domainName: string;

constructor(scope: cdk.Construct, id: string, props: DNSValidatedCertificateProps) {
constructor(scope: cdk.Construct, id: string, props: DnsValidatedCertificateProps) {
super(scope, id);

this.domainName = props.domainName;
Expand Down Expand Up @@ -80,7 +80,7 @@ export class DNSValidatedCertificate extends cdk.Construct implements ICertifica
};
}

public validate(): string[] {
protected validate(): string[] {
const errors: string[] = [];
// Ensure the zone name is a parent zone of the certificate domain name
if (!this.domainName.endsWith('.' + this.normalizedZoneName)) {
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-certificatemanager/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './certificate';
export * from './dns-validated-certificate';

// AWS::CertificateManager CloudFormation Resources:
export * from './certificatemanager.generated';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, haveResource } from '@aws-cdk/assert';
import { PublicHostedZone } from '@aws-cdk/aws-route53';
import { Stack } from '@aws-cdk/cdk';
import { Test } from 'nodeunit';
import { DNSValidatedCertificate } from '../lib/dns-validated-certificate';
import { DnsValidatedCertificate } from '../lib/dns-validated-certificate';

export = {
'creates CloudFormation Custom Resource'(test: Test) {
Expand All @@ -12,7 +12,7 @@ export = {
zoneName: 'example.com'
});

const cert = new DNSValidatedCertificate(stack, 'Certificate', {
new DnsValidatedCertificate(stack, 'Certificate', {
domainName: 'test.example.com',
hostedZone: exampleDotComZone,
});
Expand Down Expand Up @@ -77,9 +77,6 @@ export = {
}
}));

const errors = cert.validate();
test.equal(errors.length, 0);

test.done();
},

Expand All @@ -90,7 +87,7 @@ export = {
zoneName: 'hello.com'
});

const refProps = new DNSValidatedCertificate(stack, 'Cert', {
const refProps = new DnsValidatedCertificate(stack, 'Cert', {
domainName: 'hello.com',
hostedZone: helloDotComZone,
}).export();
Expand All @@ -106,14 +103,13 @@ export = {
zoneName: 'hello.com'
});

const cert = new DNSValidatedCertificate(stack, 'Cert', {
new DnsValidatedCertificate(stack, 'Cert', {
domainName: 'example.com',
hostedZone: helloDotComZone,
});

const errors = cert.validate();
test.equal(errors.length, 1);

// a bit of a hack: expect(stack) will trigger validation.
test.throws(() => expect(stack), /DNS zone hello.com is not authoritative for certificate domain name example.com/);
test.done();
},
};