Skip to content

Commit 658a3ff

Browse files
committed
Add more instructions, cleanup script for MCCF Typescript
1 parent 591cca1 commit 658a3ff

File tree

1 file changed

+76
-27
lines changed

1 file changed

+76
-27
lines changed

articles/managed-ccf/quickstart-typescript.md

Lines changed: 76 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,33 @@ This quickstart uses the Azure Identity library, along with Azure CLI or Azure P
3030

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

33+
### Initialize a new npm project
34+
Begin by initializing a new `npm` project in a folder. You may skip this step if you have an existing node project.
35+
```terminal
36+
cd <work folder>
37+
npm init -y
38+
```
39+
3340
### Install the packages
3441

3542
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).
3643

3744
Install the Azure Active Directory identity client library.
3845

3946
```terminal
40-
npm install @azure/identity
47+
npm install --save @azure/identity
4148
```
4249

4350
Install the Azure Confidential Ledger management plane client library.
4451

4552
```terminal
46-
npm install @azure/[email protected]
53+
npm install -save @azure/[email protected]
54+
```
55+
56+
Install the TypeScript compiler and tools globally
57+
58+
```terminal
59+
npm install -g typescript
4760
```
4861

4962
### Create a resource group
@@ -62,64 +75,69 @@ npm install @azure/[email protected]
6275

6376
### Use the Management plane client library
6477

65-
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.
78+
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.
79+
80+
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:
81+
82+
```terminal
83+
tsc <filename.ts>
84+
```
85+
86+
The compiled JavaScript file will have the same name but a `*.js` extension. Then run the script in nodeJS:
87+
```terminal
88+
node <filename.js>
89+
```
90+
91+
The following sample TypeScript code creates and views the properties of a Managed CCF resource.
6692

67-
```JavaScript
93+
```TypeScript
6894
import { ConfidentialLedgerClient, ManagedCCFProperties, ManagedCCF, KnownLanguageRuntime, DeploymentType, MemberIdentityCertificate } from "@azure/arm-confidentialledger";
6995
import { DefaultAzureCredential } from "@azure/identity";
70-
import { Console } from "console";
7196

72-
const subscriptionId = "0000000-0000-0000-0000-000000000001"; // replace
97+
// Please replace these variables with appropriate values for your project
98+
const subscriptionId = "0000000-0000-0000-0000-000000000001";
7399
const rgName = "myResourceGroup";
74-
const ledgerId = "confidentialbillingapp";
75-
76-
let client: ConfidentialLedgerClient;
100+
const ledgerId = "testApp";
101+
const memberCert0 = "-----BEGIN CERTIFICATE-----\nMIIBvjCCAUSgAwIBAg...0d71ZtULNWo\n-----END CERTIFICATE-----";
77102

78-
export async function main() {
103+
async function main() {
79104
console.log("Creating a new instance.")
80-
client = new ConfidentialLedgerClient(new DefaultAzureCredential(), subscriptionId);
105+
const client = new ConfidentialLedgerClient(new DefaultAzureCredential(), subscriptionId);
81106

82-
let properties = <ManagedCCFProperties> {
107+
const properties = <ManagedCCFProperties> {
83108
deploymentType: <DeploymentType> {
84109
appSourceUri: "",
85110
languageRuntime: KnownLanguageRuntime.JS
86111
},
87112
memberIdentityCertificates: [
88113
<MemberIdentityCertificate>{
89-
certificate: "-----BEGIN CERTIFICATE-----\nMIIBvjCCAUSgAwIBAg...0d71ZtULNWo\n-----END CERTIFICATE-----",
114+
certificate: memberCert0,
90115
encryptionkey: "",
91116
tags: {
92117
"owner":"member0"
93118
}
94119
},
95-
<MemberIdentityCertificate>{
96-
certificate: "-----BEGIN CERTIFICATE-----\nMIIBwDCCAUagAwIBAgI...2FSyKIC+vY=\n-----END CERTIFICATE-----",
97-
encryptionkey: "",
98-
tags: {
99-
"owner":"member1"
100-
}
101-
},
102120
],
103121
nodeCount: 3,
104122
};
105123

106-
let mccf = <ManagedCCF> {
124+
const mccf = <ManagedCCF> {
107125
location: "SouthCentralUS",
108126
properties: properties,
109127
}
110128

111-
let createResponse = await client.managedCCFOperations.beginCreateAndWait(rgName, ledgerId, mccf);
129+
const createResponse = await client.managedCCFOperations.beginCreateAndWait(rgName, ledgerId, mccf);
112130
console.log("Created. Instance id: " + createResponse.id);
113131

114132
// Get details of the instance
115133
console.log("Getting instance details.");
116-
let getResponse = await client.managedCCFOperations.get(rgName, ledgerId);
134+
const getResponse = await client.managedCCFOperations.get(rgName, ledgerId);
117135
console.log(getResponse.properties?.identityServiceUri);
118136
console.log(getResponse.properties?.nodeCount);
119137

120138
// List mccf instances in the RG
121139
console.log("Listing the instances in the resource group.");
122-
let instancePages = await client.managedCCFOperations.listByResourceGroup(rgName).byPage();
140+
const instancePages = await client.managedCCFOperations.listByResourceGroup(rgName).byPage();
123141
for await(const page of instancePages){
124142
for(const instance of page)
125143
{
@@ -132,11 +150,42 @@ export async function main() {
132150
console.log("Deleted.");
133151
}
134152

135-
main().catch((err) => {
136-
console.error(err);
137-
});
153+
(async () => {
154+
try {
155+
await main();
156+
} catch(err) {
157+
console.error(err);
158+
}
159+
})();
138160
```
139161

162+
## Delete the Managed CCF resource
163+
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.
164+
165+
```TypeScript
166+
import { ConfidentialLedgerClient, ManagedCCFProperties, ManagedCCF, KnownLanguageRuntime, DeploymentType, MemberIdentityCertificate } from "@azure/arm-confidentialledger";
167+
import { DefaultAzureCredential } from "@azure/identity";
168+
169+
const subscriptionId = "0000000-0000-0000-0000-000000000001"; // replace
170+
const rgName = "myResourceGroup";
171+
const ledgerId = "confidentialbillingapp";
172+
173+
async function deleteManagedCcfResource() {
174+
const client = new ConfidentialLedgerClient(new DefaultAzureCredential(), subscriptionId);
175+
176+
console.log("Delete the instance.");
177+
await client.managedCCFOperations.beginDeleteAndWait(rgName, ledgerId);
178+
console.log("Deleted.");
179+
}
180+
181+
(async () => {
182+
try {
183+
await deleteManagedCcfResource();
184+
} catch(err) {
185+
console.error(err);
186+
}
187+
})();
188+
```
140189
## Clean up resources
141190

142191
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)