Skip to content

Commit

Permalink
AT-11105: add sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
rddimon committed Feb 6, 2024
1 parent 4f805e3 commit 12ff22b
Show file tree
Hide file tree
Showing 7 changed files with 681 additions and 678 deletions.
128 changes: 64 additions & 64 deletions src/aws/acm-wrapper.ts
Expand Up @@ -18,81 +18,81 @@ const certStatuses = [
];

class ACMWrapper {
public acm: ACMClient;
public acm: ACMClient;

constructor (credentials: any, endpointType: string) {
const isEdge = endpointType === Globals.endpointTypes.edge;
this.acm = new ACMClient({
credentials,
region: isEdge ? Globals.defaultRegion : Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler()
});
}
constructor (credentials: any, endpointType: string) {
const isEdge = endpointType === Globals.endpointTypes.edge;
this.acm = new ACMClient({
credentials,
region: isEdge ? Globals.defaultRegion : Globals.getRegion(),
retryStrategy: Globals.getRetryStrategy(),
requestHandler: Globals.getRequestHandler()
});
}

public async getCertArn (domain: DomainConfig): Promise<string> {
let certificateArn; // The arn of the selected certificate
let certificateName = domain.certificateName; // The certificate name
public async getCertArn (domain: DomainConfig): Promise<string> {
let certificateArn; // The arn of the selected certificate
let certificateName = domain.certificateName; // The certificate name

try {
const certificates = await getAWSPagedResults<CertificateSummary, ListCertificatesCommandInput, ListCertificatesCommandOutput>(
this.acm,
"CertificateSummaryList",
"NextToken",
"NextToken",
new ListCertificatesCommand({ CertificateStatuses: certStatuses })
);
// enhancement idea: weight the choice of cert so longer expires
// and RenewalEligibility = ELIGIBLE is more preferable
if (certificateName) {
certificateArn = this.getCertArnByCertName(certificates, certificateName);
} else {
certificateName = domain.givenDomainName;
certificateArn = ACMWrapper.getCertArnByDomainName(certificates, certificateName);
}
Logging.logInfo(`Found a certificate ARN: '${certificateArn}'`);
} catch (err) {
throw Error(`Could not search certificates in Certificate Manager.\n${err.message}`);
}
if (certificateArn == null) {
throw Error(`Could not find an in-date certificate for '${certificateName}'.`);
try {
const certificates = await getAWSPagedResults<CertificateSummary, ListCertificatesCommandInput, ListCertificatesCommandOutput>(
this.acm,
"CertificateSummaryList",
"NextToken",
"NextToken",
new ListCertificatesCommand({ CertificateStatuses: certStatuses })
);
// enhancement idea: weight the choice of cert so longer expires
// and RenewalEligibility = ELIGIBLE is more preferable
if (certificateName) {
certificateArn = this.getCertArnByCertName(certificates, certificateName);
} else {
certificateName = domain.givenDomainName;
certificateArn = ACMWrapper.getCertArnByDomainName(certificates, certificateName);
}
return certificateArn;
Logging.logInfo(`Found a certificate ARN: '${certificateArn}'`);
} catch (err) {
throw Error(`Could not search certificates in Certificate Manager.\n${err.message}`);
}
if (certificateArn == null) {
throw Error(`Could not find an in-date certificate for '${certificateName}'.`);
}
return certificateArn;
}

private getCertArnByCertName (certificates, certName): string {
const found = certificates.find((c) => c.DomainName === certName);
if (found) {
return found.CertificateArn;
}
return null;
private getCertArnByCertName (certificates, certName): string {
const found = certificates.find((c) => c.DomainName === certName);
if (found) {
return found.CertificateArn;
}
return null;
}

private static getCertArnByDomainName (certificates, domainName): string {
// The more specific name will be the longest
let nameLength = 0;
let certificateArn;
for (const currCert of certificates) {
const allDomainsForCert = [
currCert.DomainName,
...(currCert.SubjectAlternativeNameSummaries || [])
];
for (const currCertDomain of allDomainsForCert) {
let certificateListName = currCertDomain;
// Looks for wild card and take it out when checking
if (certificateListName[0] === "*") {
certificateListName = certificateListName.substring(1);
}
// Looks to see if the name in the list is within the given domain
// Also checks if the name is more specific than previous ones
if (domainName.includes(certificateListName) && certificateListName.length > nameLength) {
nameLength = certificateListName.length;
certificateArn = currCert.CertificateArn;
}
private static getCertArnByDomainName (certificates, domainName): string {
// The more specific name will be the longest
let nameLength = 0;
let certificateArn;
for (const currCert of certificates) {
const allDomainsForCert = [
currCert.DomainName,
...(currCert.SubjectAlternativeNameSummaries || [])
];
for (const currCertDomain of allDomainsForCert) {
let certificateListName = currCertDomain;
// Looks for wild card and take it out when checking
if (certificateListName[0] === "*") {
certificateListName = certificateListName.substring(1);
}
// Looks to see if the name in the list is within the given domain
// Also checks if the name is more specific than previous ones
if (domainName.includes(certificateListName) && certificateListName.length > nameLength) {
nameLength = certificateListName.length;
certificateArn = currCert.CertificateArn;
}
}
return certificateArn;
}
return certificateArn;
}
}

export = ACMWrapper;

0 comments on commit 12ff22b

Please sign in to comment.