Skip to content

Commit

Permalink
[KeyVault] Addressed feedback on samples (#5447)
Browse files Browse the repository at this point in the history
* addressed feedback

* new way of building samples, plus more fixes

* Fixes the remaining issues in samples
  • Loading branch information
sadasant authored and Jonathan Turner committed Oct 8, 2019
1 parent 41d1963 commit f028c79
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 43 deletions.
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-certificates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:minify": "uglifyjs -c -m --comments --source-map \"content='./dist/index.js.map'\" -o ./dist/index.min.js ./dist/index.js 2>&1",
"build:samples": "tsc samples/backupAndRestore.ts && tsc samples/contacts.ts && tsc samples/deleteAndRecover.ts && tsc samples/helloWorld.ts && tsc samples/issuers.ts && tsc samples/listCertificates.ts && tsc samples/mergeCertificate.ts && tsc samples/operations.ts",
"build:samples": "tsc -p tsconfig.samples.json",
"build:es6": "tsc -p tsconfig.json",
"build:nodebrowser": "rollup -c 2>&1",
"build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ async function main(): Promise<void> {

const backup = await client.backupCertificate("MyCertificate");

await client.deleteCertificate("MyCertificate");

// It might take less time, or more, depending on your location, internet speed and other factors.
await delay(10000);
await delay(30000);

await client.purgeDeletedCertificate("MyCertificate");
await client.purgeDeletedCertificate("MyCertificate23310");
await delay(30000);

await client.restoreCertificate(backup.value!);

Expand Down
10 changes: 0 additions & 10 deletions sdk/keyvault/keyvault-certificates/samples/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ async function main(): Promise<void> {
console.log("Contact List:", getResponse.contactList);

await client.deleteCertificateContacts();

let error;
try {
await client.getCertificateContacts();
throw Error("Expecting an error but not catching one.");
} catch (e) {
error = e;
}

console.log(error.message); // Contacts not found
}

main().catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-certificates/samples/helloWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function main(): Promise<void> {
// To read a certificate from a specific version:
const certificateFromVersion = await client.getCertificate(
certificateName,
certificateWithPolicy.properties.version
certificateWithPolicy.properties.version!
);
// Note: It will not retrieve the certificate's policy.
console.log("Certificate from a specific version:", certificateFromVersion);
Expand Down
12 changes: 2 additions & 10 deletions sdk/keyvault/keyvault-certificates/samples/issuers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,15 @@ async function main(): Promise<void> {
});

// Reading the certificate will give us back the issuer name, but no other information.
const certificate = await client.getCertificate("MyCertificate", "");
const certificate = await client.getCertificateWithPolicy("MyCertificate");
console.log("Certificate: ", certificate);

// We can retrieve the issuer this way:
const getResponse = await client.getCertificateIssuer(issuerName);
console.log("Certificate issuer: ", getResponse);

// We can also delete the issuer.
await client.deleteCertificateIssuer(issuerName);
let error;
try {
await client.getCertificateIssuer(issuerName);
throw Error("Expecting an error but not catching one.");
} catch (e) {
error = e;
}

console.log(error.message); // Issuer not found
}

main().catch((err) => {
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-certificates/samples/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function main(): Promise<void> {
});

// The pending state of the certificate will be visible.
const pendingCertificate = await client.getCertificate(certificateName, "");
const pendingCertificate = await client.getCertificateWithPolicy(certificateName);
console.log({ pendingCertificate });

// Reading the certificate's operation (it will be pending)
Expand Down
24 changes: 24 additions & 0 deletions sdk/keyvault/keyvault-certificates/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"alwaysStrict": true,
"noImplicitAny": true,
"preserveConstEnums": true,
"sourceMap": true,
"newLine": "LF",
"target": "es5",
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"module": "esNext",
"outDir": "./dist-esm",
"declaration": true,
"declarationMap": true,
"importHelpers": true,
"declarationDir": "./types",
"lib": ["dom", "es5", "es6", "es7", "esnext"],
"esModuleInterop": true
},
"compileOnSave": true,
"include": ["./samples/**/*.ts"]
}
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-keys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:minify": "uglifyjs -c -m --comments --source-map \"content='./dist/index.js.map'\" -o ./dist/index.min.js ./dist/index.js 2>&1",
"build:samples": "tsc samples/helloWorld.ts",
"build:samples": "tsc -p tsconfig.samples.json",
"build:es6": "tsc -p tsconfig.json",
"build:nodebrowser": "rollup -c 2>&1",
"build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1",
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-keys/samples/helloWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function main(): Promise<void> {
}

// Update the key
const updatedKey = await client.updateKey(keyName, result.properties.version, { enabled: false });
const updatedKey = await client.updateKey(keyName, result.properties.version!, { enabled: false });
console.log("updated key: ", updatedKey);

await client.deleteKey(keyName);
Expand Down
24 changes: 24 additions & 0 deletions sdk/keyvault/keyvault-keys/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"alwaysStrict": true,
"noImplicitAny": true,
"preserveConstEnums": true,
"sourceMap": true,
"newLine": "LF",
"target": "es5",
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"module": "esNext",
"outDir": "./dist-esm",
"declaration": true,
"declarationMap": true,
"importHelpers": true,
"declarationDir": "./types",
"lib": ["dom", "es5", "es6", "es7", "esnext"],
"esModuleInterop": true
},
"compileOnSave": true,
"include": ["./samples/**/*.ts"]
}
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-secrets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"scripts": {
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:minify": "uglifyjs -c -m --comments --source-map \"content='./dist/index.js.map'\" -o ./dist/index.min.js ./dist/index.js 2>&1",
"build:samples": "tsc samples/helloWorld.ts && tsc samples/listOperations.ts && tsc samples/backupAndRestore.ts && tsc samples/deleteAndRecover.ts",
"build:samples": "tsc -p tsconfig.samples.json",
"build:es6": "tsc -p tsconfig.json",
"build:nodebrowser": "rollup -c 2>&1",
"build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1",
Expand Down
4 changes: 2 additions & 2 deletions sdk/keyvault/keyvault-secrets/samples/backupAndRestore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SecretsClient } from "../src";
import fs = require("fs");
import * as fs from "fs";
import { DefaultAzureCredential } from "@azure/identity";

function writeFile(filename: string, text: Uint8Array): Promise<void> {
Expand Down Expand Up @@ -44,7 +44,7 @@ async function main(): Promise<void> {
const backupResult = await client.backupSecret(secretName);

// Write the backup to a file
await writeFile("secret_backup.dat", backupResult);
await writeFile("secret_backup.dat", backupResult!);

// Delete the secret
console.log("about to delete");
Expand Down
12 changes: 2 additions & 10 deletions sdk/keyvault/keyvault-secrets/samples/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ import { SecretsClient } from "../src";
import { DefaultAzureCredential } from "@azure/identity";

import {
ServiceClientCredentials,
TokenCredential,
isTokenCredential,
RequestPolicyFactory,
deserializationPolicy,
signingPolicy,
bearerTokenAuthenticationPolicy,
RequestOptionsBase,
exponentialRetryPolicy,
redirectPolicy,
systemErrorRetryPolicy,
Expand All @@ -20,13 +14,11 @@ import {
userAgentPolicy
} from "@azure/core-http";

import { RetryConstants, SDK_VERSION } from "../src/core/utils/constants";
import { RetryConstants } from "../src/core/utils/constants";
import {
ChallengeBasedAuthenticationPolicy,
challengeBasedAuthenticationPolicy
} from "../src/core/challengeBasedAuthenticationPolicy";

import { TokenCredentials } from "@azure/core-http";
import { Pipeline } from "../src/core/keyVaultBase";

async function main(): Promise<void> {
Expand Down Expand Up @@ -76,7 +68,7 @@ async function main(): Promise<void> {
console.log("secret: ", secret);

// Update the secret with different attributes
const updatedSecret = await client.updateSecretAttributes(secretName, result.properties.version, {
const updatedSecret = await client.updateSecretProperties(secretName, result.properties.version!, {
enabled: false
});
console.log("updated secret: ", updatedSecret);
Expand Down
2 changes: 1 addition & 1 deletion sdk/keyvault/keyvault-secrets/samples/helloWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function main(): Promise<void> {
console.log("secret: ", secret);

// Update the secret with different attributes
const updatedSecret = await client.updateSecretProperties(secretName, result.properties.version, {
const updatedSecret = await client.updateSecretProperties(secretName, result.properties.version!, {
enabled: false
});
console.log("updated secret: ", updatedSecret);
Expand Down
24 changes: 24 additions & 0 deletions sdk/keyvault/keyvault-secrets/tsconfig.samples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"alwaysStrict": true,
"noImplicitAny": true,
"preserveConstEnums": true,
"sourceMap": true,
"newLine": "LF",
"target": "es5",
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"module": "esNext",
"outDir": "./dist-esm",
"declaration": true,
"declarationMap": true,
"importHelpers": true,
"declarationDir": "./types",
"lib": ["dom", "es5", "es6", "es7", "esnext"],
"esModuleInterop": true
},
"compileOnSave": true,
"include": ["./samples/**/*.ts"]
}

0 comments on commit f028c79

Please sign in to comment.