Skip to content

Commit

Permalink
JavaScript (v3): Task - Fix outdated cert; test improvements. (awsdoc…
Browse files Browse the repository at this point in the history
  • Loading branch information
cpyle0819 authored and max-webster committed Mar 15, 2024
1 parent 0059eaf commit 48b27dd
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 169 deletions.
2 changes: 0 additions & 2 deletions .tools/validation/validator_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ def skip(path):
"chat_sfn_state_machine.json",
"market_2.jpg",
"movies.json",
"sample_cert.pem",
"sample_private_key.pem",
"sample_saml_metadata.xml",
"speech_sample.mp3",
"spheres_2.jpg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import { scenarios } from "../index.js";

describe("workflow", () => {
it("should run without error", async () => {
await scenarios.deploy.run({ confirmAll: true, verbose: true });
await scenarios.demo.run({ confirmAll: true, verbose: true });
await scenarios.destroy.run({ confirmAll: true, verbose: true });
try {
await scenarios.deploy.run({ confirmAll: true, verbose: true });
await scenarios.demo.run({ confirmAll: true, verbose: true });
await scenarios.destroy.run({ confirmAll: true, verbose: true });
} catch (err) {
await scenarios.destroy.run({ confirmAll: true, verbose: true });
throw err;
}
});
});
55 changes: 29 additions & 26 deletions javascriptv3/example_code/iam/actions/upload-server-certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,43 @@ import * as path from "path";

const client = new IAMClient({});

/**
* The certificate body and private key were generated with the
* following command.
*
* ```
* openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
* -keyout example.key -out example.crt -subj "/CN=example.com" \
* -addext "subjectAltName=DNS:example.com,DNS:www.example.net,IP:10.0.0.1"
* ```
*/

const certBody = readFileSync(
path.join(
dirnameFromMetaUrl(import.meta.url),
"../../../../resources/sample_files/sample_cert.pem",
),
);

const privateKey = readFileSync(
path.join(
dirnameFromMetaUrl(import.meta.url),
"../../../../resources/sample_files/sample_private_key.pem",
),
);
const certMessage = `Generate a certificate and key with the following command, or the equivalent for your system.
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes \
-keyout example.key -out example.crt -subj "/CN=example.com" \
-addext "subjectAltName=DNS:example.com,DNS:www.example.net,IP:10.0.0.1"
`;

const getCertAndKey = () => {
try {
const cert = readFileSync(
path.join(dirnameFromMetaUrl(import.meta.url), "./example.crt")
);
const key = readFileSync(
path.join(dirnameFromMetaUrl(import.meta.url), "./example.key")
);
return { cert, key };
} catch (err) {
if (err.code === "ENOENT") {
throw new Error(
`Certificate and/or private key not found. ${certMessage}`
);
}

throw err;
}
};

/**
*
* @param {string} certificateName
*/
export const uploadServerCertificate = (certificateName) => {
const { cert, key } = getCertAndKey();
const command = new UploadServerCertificateCommand({
ServerCertificateName: certificateName,
CertificateBody: certBody.toString(),
PrivateKey: privateKey.toString(),
CertificateBody: cert.toString(),
PrivateKey: key.toString(),
});

return client.send(command);
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions resources/sample_files/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ These files are included as shared sample data files for use in examples in this
* [speech_sample.mp3](.sample_media/speech_sample.mp3) `A sample audio file of speech used for Amazon Transcribe examples.`
* [spheres_2.jpg](.sample_media/spheres_2.jpg) `A sample image of the Amazon Spheres in Seattle.`
* [market_2.jpg](.sample_media/market_2.jpg) `A sample image of the public market in Seattle.`
* [sample_cert.pem](./sample_cert.pem) `A sample certificate PEM file.`
* [sample_private_key.pem](./sample_private_key.pem) `A sample private key PEM file.`
* [sample_saml_metadata.xml](./sample_saml_metadata.xml) `A sample SAML metadata file for creating a SAML provider.`

34 changes: 0 additions & 34 deletions resources/sample_files/sample_cert.pem

This file was deleted.

52 changes: 0 additions & 52 deletions resources/sample_files/sample_private_key.pem

This file was deleted.

0 comments on commit 48b27dd

Please sign in to comment.