Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update purview scanning samples #18154

Merged
merged 6 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions sdk/purview/purview-scanning-rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,30 @@ The following section shows you how to initialize and authenticate your client,
### List All Data Sources

```typescript
import PurviewScanning from "@azure-rest/purview-scanning";
import PurviewScanning, { paginate, DataSource } from "@azure-rest/purview-scanning";
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
import { DefaultAzureCredential } from "@azure/identity";

async function main() {
console.log("== List dataSources ==");
const client = PurviewScanning(
"https://<my-account-name>.purview.azure.com",
"https://<my-account-name>.scan.purview.azure.com",
new DefaultAzureCredential()
);

const dataSources = await client.path("/datasources").get();

if (dataSources.status !== "200") {
throw dataSources.body.error;
}
const iter = paginate(client, dataSources)

const items: DataSource[] = [];

for await (const item of <PagedAsyncIterableIterator<DataSource, (DataSource)[], PageSettings>>iter) {
items.push(item);
}

console.log(dataSources.body.value?.map((ds) => ds.name).join("\n"));
console.log(items?.map((ds) => ds.name).join("\n"));
}

main().catch(console.error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* @azsdk-weight 40
*/

import PurviewScanning from "@azure-rest/purview-scanning";
import PurviewScanning, { DataSource, paginate } from "@azure-rest/purview-scanning";
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
import { DefaultAzureCredential } from "@azure/identity";
import dotenv from "dotenv";

Expand All @@ -17,16 +18,23 @@ dotenv.config();
const endpoint = process.env["ENDPOINT"] || "";

async function main() {
console.log("== List dataSources sample ==");
console.log("== List dataSources ==");
const client = PurviewScanning(endpoint, new DefaultAzureCredential());

const dataSources = await client.path("/datasources").get();

if (dataSources.status !== "200") {
throw dataSources.body.error;
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
}
const iter = paginate(client, dataSources);

const items: DataSource[] = [];

console.log(dataSources.body.value?.map((ds) => ds.name).join("\n"));
for await (const item of <PagedAsyncIterableIterator<DataSource, DataSource[], PageSettings>>(
iter
)) {
items.push(item);
}
console.log(items?.map((ds) => ds?.name).join("\n"));
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @summary gets a list of datasources
*/

const PurviewScanning = require("@azure-rest/purview-scanning");
const PurviewScanning, { paginate } = require("@azure-rest/purview-scanning");
const { DefaultAzureCredential } = require("@azure/identity");
const dotenv = require("dotenv");

Expand All @@ -20,12 +20,17 @@ async function main() {
const client = PurviewScanning(endpoint, new DefaultAzureCredential());

const dataSources = await client.path("/datasources").get();

if (dataSources.status !== "200") {
throw dataSources.body.error;
}
const iter = paginate(client, dataSources)

const items = [];

console.log(dataSources.body.value?.map((ds) => ds.name).join("\n"));
for await (const item of iter) {
items.push(item);
}
console.log(items?.map((ds) => ds?.name).join("\n"));
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,32 @@
* @summary gets a list of datasources
*/

import PurviewScanning from "@azure-rest/purview-scanning";
import PurviewScanning, { paginate, DataSource } from "@azure-rest/purview-scanning";
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
import { DefaultAzureCredential } from "@azure/identity";
import dotenv from "dotenv";

dotenv.config();

const endpoint = process.env["ENDPOINT"] || "";

async function main() {
console.log("== List dataSources sample ==");
const client = PurviewScanning(endpoint, new DefaultAzureCredential());
console.log("== List dataSources ==");
const client = PurviewScanning(
"https://<purview-account-name>.scan.purview.azure.com",
new DefaultAzureCredential()
);

const dataSources = await client.path("/datasources").get();

if (dataSources.status !== "200") {
throw dataSources.body.error;
}
const iter = paginate(client, dataSources)

console.log(dataSources.body.value?.map((ds) => ds.name).join("\n"));

const items: DataSource[] = [];

for await (const item of <PagedAsyncIterableIterator<DataSource, DataSource[], PageSettings>>(
iter
)) {
items.push(item);
}
console.log(items?.map((ds) => ds.name).join("\n"));
}

main().catch(console.error);
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { PurviewScanningRestClient, paginate } from "../../src";
import { PurviewScanningRestClient, paginate, DataSource } from "../../src";
import { Recorder } from "@azure-tools/test-recorder";

import { assert } from "chai";
import { createClient, createRecorder } from "./utils/recordedClient";
import { Context } from "mocha";
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";

describe("List data sources", () => {
let recorder: Recorder;
Expand All @@ -24,9 +25,11 @@ describe("List data sources", () => {
const result = await client.path("/datasources").get();
const iter = paginate(client, result);

const items = [];
const items: DataSource[] = [];

for await (const item of iter) {
for await (const item of <PagedAsyncIterableIterator<DataSource, DataSource[], PageSettings>>(
iter
)) {
items.push(item);
}

Expand Down