-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tables] Create clients from connectionString (#10292)
* Initial changes to support SharedKey auth * Add test for utility helpers * re-enable pipeline validation on PR * Add javascript samples * update sample require * Address PR comments * Add url to externalNodeBuiltins * Support SharedKeyCredential * Rename ShareKeyCredential to TablesSharedKeyCredential * Address PR comments * Fix file name TablesShredKeyCredential
- Loading branch information
Showing
29 changed files
with
1,110 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "azure-tables-samples-js", | ||
"private": true, | ||
"version": "0.1.0", | ||
"description": "Azure Tables client library samples for Javascript", | ||
"engine": { | ||
"node": ">=8.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Azure/azure-sdk-for-js.git" | ||
}, | ||
"keywords": [ | ||
"Azure", | ||
"Storage", | ||
"Tables", | ||
"Node.js" | ||
], | ||
"author": "Microsoft Corporation", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Azure/azure-sdk-for-js/issues" | ||
}, | ||
"homepage": "https://github.com/Azure/azure-sdk-for-js#readme", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@azure/tables": "../..", | ||
"dotenv": "^8.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^8.0.0" | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
sdk/tables/azure-tables/samples/javascript/src/connectionString.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
const { TableServiceClient, TableClient } = require("@azure/tables"); | ||
|
||
// Load the .env file if it exists | ||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
|
||
const connectionString = process.env["ACCOUNT_CONNECTION_STRING"] || ""; | ||
// const connectionString = process.env["SAS_CONNECTION_STRING"] || ""; | ||
|
||
async function listTables() { | ||
const client = TableServiceClient.fromConnectionString(connectionString); | ||
|
||
const tables = await client.listTables(); | ||
|
||
console.log(tables.value); | ||
} | ||
|
||
async function listEntities() { | ||
const client = TableClient.fromConnectionString(connectionString, "test1"); | ||
|
||
const entities = await client.listEntities(); | ||
|
||
console.log(entities.value); | ||
} | ||
|
||
async function main() { | ||
await listTables(); | ||
await listEntities(); | ||
} | ||
|
||
main().catch(console.error); |
37 changes: 37 additions & 0 deletions
37
sdk/tables/azure-tables/samples/javascript/src/sasToken.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
const { TableServiceClient, TableClient } = require("@azure/tables"); | ||
|
||
// Load the .env file if it exists | ||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
|
||
const accountSas = process.env["ACCOUNT_SAS"] || ""; | ||
const accountName = process.env["ACCOUNT_NAME"] || ""; | ||
|
||
async function listTables() { | ||
const accountUrl = `https://${accountName}.table.core.windows.net${accountSas}`; | ||
const client = new TableServiceClient(accountUrl); | ||
|
||
const tables = await client.listTables(); | ||
|
||
console.log(tables.value); | ||
} | ||
|
||
async function listEntities() { | ||
const accountUrl = `https://${accountName}.table.core.windows.net${accountSas}`; | ||
const tableName = "test1"; | ||
const client = new TableClient(accountUrl, tableName); | ||
|
||
const entities = await client.listEntities(); | ||
|
||
console.log(entities.value); | ||
} | ||
|
||
async function main() { | ||
await listTables(); | ||
await listEntities(); | ||
} | ||
|
||
main().catch(console.error); |
38 changes: 38 additions & 0 deletions
38
sdk/tables/azure-tables/samples/javascript/src/sharedKey.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
const { TableServiceClient, TableClient, TablesSharedKeyCredential } = require("@azure/tables"); | ||
|
||
// Load the .env file if it exists | ||
const dotenv = require("dotenv"); | ||
dotenv.config(); | ||
|
||
const accountName = process.env["ACCOUNT_NAME"] || ""; | ||
const accountKey = process.env["ACCOUNT_KEY"] || ""; | ||
const accountUrl = process.env["ACCOUNT_URL"] || ""; | ||
|
||
async function listTables() { | ||
const credential = new TablesSharedKeyCredential(accountName, accountKey); | ||
const client = new TableServiceClient(accountUrl, credential); | ||
|
||
const tables = await client.listTables(); | ||
|
||
console.log(tables.value); | ||
} | ||
|
||
async function listEntities() { | ||
const tableName = "test1"; | ||
const credential = new TablesSharedKeyCredential(accountName, accountKey); | ||
const client = new TableClient(accountUrl, tableName, credential); | ||
|
||
const entities = await client.listEntities(); | ||
|
||
console.log(entities.value); | ||
} | ||
|
||
async function main() { | ||
await listTables(); | ||
await listEntities(); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ACCOUNT_CONNECTION_STRING= | ||
SAS_CONNECTION_STRING= | ||
ACCOUNT_NAME= | ||
ACCOUNT_KEY= | ||
ACCOUNT_URL= | ||
ACCOUNT_SAS= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "azure-tables-samples-ts", | ||
"private": true, | ||
"version": "0.1.0", | ||
"description": "Azure Tables client library samples for TypeScript", | ||
"engine": { | ||
"node": ">=8.0.0" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"prebuild": "rimraf dist/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Azure/azure-sdk-for-js.git" | ||
}, | ||
"keywords": [ | ||
"Azure", | ||
"Storage", | ||
"Tables", | ||
"Node.js", | ||
"TypeScript" | ||
], | ||
"author": "Microsoft Corporation", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Azure/azure-sdk-for-js/issues" | ||
}, | ||
"homepage": "https://github.com/Azure/azure-sdk-for-js#readme", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@azure/tables": "../..", | ||
"dotenv": "^8.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"typescript": "~3.6.4" | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
sdk/tables/azure-tables/samples/typescript/src/connectionString.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { TableServiceClient, TableClient } from "@azure/tables"; | ||
|
||
// Load the .env file if it exists | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const connectionString = process.env["ACCOUNT_CONNECTION_STRING"] || ""; | ||
// const connectionString = process.env["SAS_CONNECTION_STRING"] || ""; | ||
async function listTables() { | ||
const client = TableServiceClient.fromConnectionString(connectionString); | ||
|
||
const tables = await client.listTables(); | ||
|
||
console.log(tables.value); | ||
} | ||
|
||
async function listEntities() { | ||
const client = TableClient.fromConnectionString(connectionString, "test1"); | ||
|
||
const entities = await client.listEntities(); | ||
|
||
console.log(entities.value); | ||
} | ||
|
||
async function main() { | ||
await listTables(); | ||
await listEntities(); | ||
} | ||
|
||
main().catch(console.error); |
37 changes: 37 additions & 0 deletions
37
sdk/tables/azure-tables/samples/typescript/src/sasToken.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
import { TableServiceClient, TableClient } from "@azure/tables"; | ||
|
||
// Load the .env file if it exists | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
const accountSas = process.env["ACCOUNT_SAS"] || ""; | ||
const accountName = process.env["ACCOUNT_NAME"] || ""; | ||
|
||
async function listTables() { | ||
const accountUrl = `https://${accountName}.table.core.windows.net${accountSas}`; | ||
const client = new TableServiceClient(accountUrl); | ||
|
||
const tables = await client.listTables(); | ||
|
||
console.log(tables.value); | ||
} | ||
|
||
async function listEntities() { | ||
const accountUrl = `https://${accountName}.table.core.windows.net${accountSas}`; | ||
const tableName = "test1"; | ||
const client = new TableClient(accountUrl, tableName); | ||
|
||
const entities = await client.listEntities(); | ||
|
||
console.log(entities.value); | ||
} | ||
|
||
async function main() { | ||
await listTables(); | ||
await listEntities(); | ||
} | ||
|
||
main().catch(console.error); |
Oops, something went wrong.