Skip to content

Commit 9153271

Browse files
Merge pull request #258452 from taicchoumsft/tachou/mccf-fix-typescript-init-and-scripts
[MCCF][Typescript Quickstart] Fix typescript init and scripts
2 parents 970d284 + 8aa2521 commit 9153271

File tree

1 file changed

+78
-24
lines changed

1 file changed

+78
-24
lines changed

articles/managed-ccf/quickstart-typescript.md

Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,30 @@ This quickstart uses the Azure Identity library, along with Azure CLI or Azure P
3131

3232
[!INCLUDE [Sign in to Azure](../../includes/confidential-ledger-sign-in-azure.md)]
3333

34-
### Install the packages
35-
36-
In a terminal or command prompt, create a suitable project folder, and then create and activate a Python virtual environment as described on [Use Python virtual environments](/azure/developer/python/configure-local-development-environment?tabs=cmd#use-python-virtual-environments).
34+
### Initialize a new npm project
35+
In a terminal or command prompt, create a suitable project folder and initialize an `npm` project. You may skip this step if you have an existing node project.
36+
```terminal
37+
cd <work folder>
38+
npm init -y
39+
```
3740

41+
### Install the packages
3842
Install the Azure Active Directory identity client library.
3943

4044
```terminal
41-
npm install @azure/identity
45+
npm install --save @azure/identity
4246
```
4347

4448
Install the Azure Confidential Ledger management plane client library.
4549

4650
```terminal
47-
npm install @azure/[email protected]
51+
npm install -save @azure/[email protected]
52+
```
53+
54+
Install the TypeScript compiler and tools globally
55+
56+
```terminal
57+
npm install -g typescript
4858
```
4959

5060
### Create a resource group
@@ -63,38 +73,51 @@ npm install @azure/[email protected]
6373

6474
### Use the Management plane client library
6575

66-
The Azure SDK for JavaScript and TypeScript library (azure/arm-confidentialledger) allows operations on Managed CCF resources, such as creation and deletion, listing the resources associated with a subscription, and viewing the details of a specific resource. The following piece of code creates and views the properties of a Managed CCF resource.
76+
The Azure SDK for JavaScript and TypeScript library [azure/arm-confidentialledger](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/confidentialledger/arm-confidentialledger) allows operations on Managed CCF resources, such as creation and deletion, listing the resources associated with a subscription, and viewing the details of a specific resource.
77+
78+
To run the below samples, please save the code snippets into a file with a `.ts` extension into your project folder and compile it as part of your TypeScript project, or compile the script into JavaScript separately by running:
6779

68-
```JavaScript
80+
```terminal
81+
tsc <filename.ts>
82+
```
83+
84+
The compiled JavaScript file will have the same name but a `*.js` extension. Then run the script in nodeJS:
85+
```terminal
86+
node <filename.js>
87+
```
88+
89+
The following sample TypeScript code creates and views the properties of a Managed CCF resource.
90+
91+
```TypeScript
6992
import { ConfidentialLedgerClient, ManagedCCFProperties, ManagedCCF, KnownLanguageRuntime, DeploymentType, MemberIdentityCertificate } from "@azure/arm-confidentialledger";
7093
import { DefaultAzureCredential } from "@azure/identity";
71-
import { Console } from "console";
7294

73-
const subscriptionId = "0000000-0000-0000-0000-000000000001"; // replace
95+
// Please replace these variables with appropriate values for your project
96+
const subscriptionId = "0000000-0000-0000-0000-000000000001";
7497
const rgName = "myResourceGroup";
75-
const ledgerId = "confidentialbillingapp";
98+
const ledgerId = "testApp";
99+
const memberCert0 = "-----BEGIN CERTIFICATE-----\nMIIBvjCCAUSgAwIBAg...0d71ZtULNWo\n-----END CERTIFICATE-----";
100+
const memberCert1 = "-----BEGIN CERTIFICATE-----\nMIIBwDCCAUagAwIBAgI...2FSyKIC+vY=\n-----END CERTIFICATE-----";
76101

77-
let client: ConfidentialLedgerClient;
78-
79-
export async function main() {
102+
async function main() {
80103
console.log("Creating a new instance.")
81-
client = new ConfidentialLedgerClient(new DefaultAzureCredential(), subscriptionId);
104+
const client = new ConfidentialLedgerClient(new DefaultAzureCredential(), subscriptionId);
82105

83-
let properties = <ManagedCCFProperties> {
106+
const properties = <ManagedCCFProperties> {
84107
deploymentType: <DeploymentType> {
85108
appSourceUri: "",
86109
languageRuntime: KnownLanguageRuntime.JS
87110
},
88111
memberIdentityCertificates: [
89112
<MemberIdentityCertificate>{
90-
certificate: "-----BEGIN CERTIFICATE-----\nMIIBvjCCAUSgAwIBAg...0d71ZtULNWo\n-----END CERTIFICATE-----",
113+
certificate: memberCert0,
91114
encryptionkey: "",
92115
tags: {
93116
"owner":"member0"
94117
}
95118
},
96119
<MemberIdentityCertificate>{
97-
certificate: "-----BEGIN CERTIFICATE-----\nMIIBwDCCAUagAwIBAgI...2FSyKIC+vY=\n-----END CERTIFICATE-----",
120+
certificate: memberCert1,
98121
encryptionkey: "",
99122
tags: {
100123
"owner":"member1"
@@ -104,23 +127,23 @@ export async function main() {
104127
nodeCount: 3,
105128
};
106129

107-
let mccf = <ManagedCCF> {
130+
const mccf = <ManagedCCF> {
108131
location: "SouthCentralUS",
109132
properties: properties,
110133
}
111134

112-
let createResponse = await client.managedCCFOperations.beginCreateAndWait(rgName, ledgerId, mccf);
135+
const createResponse = await client.managedCCFOperations.beginCreateAndWait(rgName, ledgerId, mccf);
113136
console.log("Created. Instance id: " + createResponse.id);
114137

115138
// Get details of the instance
116139
console.log("Getting instance details.");
117-
let getResponse = await client.managedCCFOperations.get(rgName, ledgerId);
140+
const getResponse = await client.managedCCFOperations.get(rgName, ledgerId);
118141
console.log(getResponse.properties?.identityServiceUri);
119142
console.log(getResponse.properties?.nodeCount);
120143

121144
// List mccf instances in the RG
122145
console.log("Listing the instances in the resource group.");
123-
let instancePages = await client.managedCCFOperations.listByResourceGroup(rgName).byPage();
146+
const instancePages = await client.managedCCFOperations.listByResourceGroup(rgName).byPage();
124147
for await(const page of instancePages){
125148
for(const instance of page)
126149
{
@@ -133,11 +156,42 @@ export async function main() {
133156
console.log("Deleted.");
134157
}
135158

136-
main().catch((err) => {
137-
console.error(err);
138-
});
159+
(async () => {
160+
try {
161+
await main();
162+
} catch(err) {
163+
console.error(err);
164+
}
165+
})();
139166
```
140167

168+
## Delete the Managed CCF resource
169+
The following piece of code deletes the Managed CCF resource. Other Managed CCF articles can build upon this quickstart. If you plan to continue on to work with subsequent quickstarts and tutorials, you might wish to leave these resources in place.
170+
171+
```TypeScript
172+
import { ConfidentialLedgerClient, ManagedCCFProperties, ManagedCCF, KnownLanguageRuntime, DeploymentType, MemberIdentityCertificate } from "@azure/arm-confidentialledger";
173+
import { DefaultAzureCredential } from "@azure/identity";
174+
175+
const subscriptionId = "0000000-0000-0000-0000-000000000001"; // replace
176+
const rgName = "myResourceGroup";
177+
const ledgerId = "confidentialbillingapp";
178+
179+
async function deleteManagedCcfResource() {
180+
const client = new ConfidentialLedgerClient(new DefaultAzureCredential(), subscriptionId);
181+
182+
console.log("Delete the instance.");
183+
await client.managedCCFOperations.beginDeleteAndWait(rgName, ledgerId);
184+
console.log("Deleted.");
185+
}
186+
187+
(async () => {
188+
try {
189+
await deleteManagedCcfResource();
190+
} catch(err) {
191+
console.error(err);
192+
}
193+
})();
194+
```
141195
## Clean up resources
142196

143197
Other Managed CCF articles can build upon this quickstart. If you plan to continue on to work with subsequent quickstarts and tutorials, you might wish to leave these resources in place.

0 commit comments

Comments
 (0)