Skip to content

Commit

Permalink
Using TestEnvironment.Credential instead
Browse files Browse the repository at this point in the history
  • Loading branch information
kinelski committed Oct 14, 2024
1 parent fc9b573 commit ae4bf9a
Show file tree
Hide file tree
Showing 25 changed files with 58 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica

```C# Snippet:CreateDocumentIntelligenceClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceClient(new Uri(endpoint), credential);
```

## Key concepts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceClient(new Uri(endpoint), credential);
```

## High resolution extraction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceClient(new Uri(endpoint), credential);
```

## Use a prebuilt model to analyze a document from a URI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceAdministrationClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), credential);
```

## Build a custom model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceAdministrationClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), credential);
```

## Build a document classifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceClient(new Uri(endpoint), credential);
```

## Classify a document from a URI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ The source client that contains the custom model to copy.

```C# Snippet:DocumentIntelligenceSampleCreateCopySourceClient
string sourceEndpoint = "<sourceEndpoint>";
var sourceClient = new DocumentIntelligenceAdministrationClient(new Uri(sourceEndpoint), new DefaultAzureCredential());
var sourceResourceCredential = new DefaultAzureCredential();
var sourceClient = new DocumentIntelligenceAdministrationClient(new Uri(sourceEndpoint), sourceResourceCredential);
```

### Target client
Expand All @@ -35,7 +36,8 @@ The target client to copy the custom model to.

```C# Snippet:DocumentIntelligenceSampleCreateCopyTargetClient
string targetEndpoint = "<targetEndpoint>";
var targetClient = new DocumentIntelligenceAdministrationClient(new Uri(targetEndpoint), new DefaultAzureCredential());
var targetResourceCredential = new DefaultAzureCredential();
var targetClient = new DocumentIntelligenceAdministrationClient(new Uri(targetEndpoint), targetResourceCredential);
```

### Authorize the copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceClient(new Uri(endpoint), credential);
```

## Extract the layout of a document from a URI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceClient(new Uri(endpoint), credential);
```

## Extract the layout of a document as Markdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceAdministrationClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), credential);
```

## Get and List Document Model Operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceAdministrationClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), credential);
```

## Model administration operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ You can set `endpoint` and `apiKey` based on an environment variable, a configur

```C# Snippet:CreateDocumentIntelligenceAdministrationClient
string endpoint = "<endpoint>";
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var credential = new DefaultAzureCredential();
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), credential);
```

## Compose a model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading.Tasks;
using Azure.AI.DocumentIntelligence.Tests;
using Azure.Core.TestFramework;
using Azure.Identity;

namespace Azure.AI.DocumentIntelligence.Samples
{
Expand All @@ -17,7 +16,7 @@ public partial class DocumentIntelligenceSamples
public async Task AnalyzeWithPrebuiltModelWithBase64Async()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceAnalyzeWithPrebuiltModelWithBase64Async
#if SNIPPET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public void CreateDocumentIntelligenceClient()
#region Snippet:CreateDocumentIntelligenceClient
#if SNIPPET
string endpoint = "<endpoint>";
var credential = new DefaultAzureCredential();
#else
string endpoint = TestEnvironment.Endpoint;
var credential = TestEnvironment.Credential;
#endif
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), credential);
#endregion
}

Expand All @@ -46,10 +48,12 @@ public void CreateDocumentIntelligenceAdministrationClient()
#region Snippet:CreateDocumentIntelligenceAdministrationClient
#if SNIPPET
string endpoint = "<endpoint>";
var credential = new DefaultAzureCredential();
#else
string endpoint = TestEnvironment.Endpoint;
var credential = TestEnvironment.Credential;
#endif
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), credential);
#endregion
}

Expand All @@ -59,10 +63,11 @@ public void CreateBothDocumentIntelligenceClients()
#region Snippet:Migration_CreateBothDocumentIntelligenceClients
#if SNIPPET
string endpoint = "<endpoint>";
var credential = new DefaultAzureCredential();
#else
string endpoint = TestEnvironment.Endpoint;
var credential = TestEnvironment.Credential;
#endif
var credential = new DefaultAzureCredential();

var documentIntelligenceClient = new DocumentIntelligenceClient(new Uri(endpoint), credential);
var documentIntelligenceAdministrationClient = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), credential);
Expand All @@ -73,7 +78,7 @@ public void CreateBothDocumentIntelligenceClients()
public async Task BadRequestSnippet()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceBadRequest
var content = new AnalyzeDocumentContent()
Expand All @@ -96,7 +101,7 @@ public async Task BadRequestSnippet()
public async Task GetWordsSnippet()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:Migration_DocumentIntelligenceGetWordsUsage
#if SNIPPET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading.Tasks;
using Azure.AI.DocumentIntelligence.Tests;
using Azure.Core.TestFramework;
using Azure.Identity;

namespace Azure.AI.DocumentIntelligence.Samples
{
Expand All @@ -17,7 +16,7 @@ public partial class DocumentIntelligenceSamples
public async Task AnalyzeWithFormulaExtraction()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceSampleFormulaExtraction
#if SNIPPET
Expand Down Expand Up @@ -65,7 +64,7 @@ public async Task AnalyzeWithFormulaExtraction()
public async Task AnalyzeWithFontStyling()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceSampleFontStyling
#if SNIPPET
Expand Down Expand Up @@ -228,7 +227,7 @@ public async Task AnalyzeWithFontStyling()
public async Task AnalyzeWithBarcodeExtraction()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceSampleBarcodeExtraction
#if SNIPPET
Expand Down Expand Up @@ -278,7 +277,7 @@ public async Task AnalyzeWithBarcodeExtraction()
public async Task AnalyzeWithLanguageDetection()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceSampleLanguageDetection
#if SNIPPET
Expand Down Expand Up @@ -320,7 +319,7 @@ public async Task AnalyzeWithLanguageDetection()
public async Task AnalyzeWithKeyValuePairs()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceSampleKeyValuePairsExtraction
#if SNIPPET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading.Tasks;
using Azure.AI.DocumentIntelligence.Tests;
using Azure.Core.TestFramework;
using Azure.Identity;

namespace Azure.AI.DocumentIntelligence.Samples
{
Expand All @@ -16,7 +15,7 @@ public partial class DocumentIntelligenceSamples
public async Task AnalyzeWithPrebuiltModelFromUriAsync()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceAnalyzeWithPrebuiltModelFromUriAsync
#if SNIPPET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure.Core.TestFramework;
using Azure.Identity;

namespace Azure.AI.DocumentIntelligence.Samples
{
Expand All @@ -15,7 +14,7 @@ public partial class DocumentIntelligenceSamples
public async Task BuildCustomModelAsync()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceSampleBuildModel
// For this sample, you can use the training documents found in the `trainingFiles` folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure.Core.TestFramework;
using Azure.Identity;

namespace Azure.AI.DocumentIntelligence.Samples
{
Expand All @@ -15,7 +14,7 @@ public partial class DocumentIntelligenceSamples
public async Task BuildDocumentClassifierAsync()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceSampleBuildClassifier
// For this sample, you can use the training documents found in the `classifierTrainingFiles` folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Threading.Tasks;
using Azure.AI.DocumentIntelligence.Tests;
using Azure.Core.TestFramework;
using Azure.Identity;

namespace Azure.AI.DocumentIntelligence.Samples
{
Expand All @@ -16,8 +15,8 @@ public partial class DocumentIntelligenceSamples
public async Task ClassifyDocumentFromUriAsync()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var adminClient = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);
var adminClient = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), TestEnvironment.Credential);

string setupClassifierId = Guid.NewGuid().ToString();
Uri blobContainerUri = new Uri(TestEnvironment.ClassifierTrainingSasUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure.Core.TestFramework;
using Azure.Identity;

namespace Azure.AI.DocumentIntelligence.Samples
{
Expand All @@ -15,7 +14,7 @@ public partial class DocumentIntelligenceSamples
public async Task ComposeModelAsync()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceAdministrationClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceSampleBuildVariousModels
// For this sample, you can use the training documents found in the `trainingFiles` folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public async Task CopyModelToAsync()
#region Snippet:DocumentIntelligenceSampleCreateCopySourceClient
#if SNIPPET
string sourceEndpoint = "<sourceEndpoint>";
var sourceResourceCredential = new DefaultAzureCredential();
#else
string sourceEndpoint = TestEnvironment.Endpoint;
var sourceResourceCredential = TestEnvironment.Credential;
#endif
var sourceClient = new DocumentIntelligenceAdministrationClient(new Uri(sourceEndpoint), new DefaultAzureCredential());
var sourceClient = new DocumentIntelligenceAdministrationClient(new Uri(sourceEndpoint), sourceResourceCredential);
#endregion

// For the purpose of this sample, we are going to create a model to copy. Note that
Expand All @@ -37,10 +39,12 @@ public async Task CopyModelToAsync()
#region Snippet:DocumentIntelligenceSampleCreateCopyTargetClient
#if SNIPPET
string targetEndpoint = "<targetEndpoint>";
var targetResourceCredential = new DefaultAzureCredential();
#else
string targetEndpoint = TestEnvironment.Endpoint;
var targetResourceCredential = TestEnvironment.Credential;
#endif
var targetClient = new DocumentIntelligenceAdministrationClient(new Uri(targetEndpoint), new DefaultAzureCredential());
var targetClient = new DocumentIntelligenceAdministrationClient(new Uri(targetEndpoint), targetResourceCredential);
#endregion

#region Snippet:DocumentIntelligenceSampleGetCopyAuthorization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Tasks;
using Azure.AI.DocumentIntelligence.Tests;
using Azure.Core.TestFramework;
using Azure.Identity;

namespace Azure.AI.DocumentIntelligence.Samples
{
Expand All @@ -15,7 +14,7 @@ public partial class DocumentIntelligenceSamples
public async Task ExtractLayoutAsMarkdownAsync()
{
string endpoint = TestEnvironment.Endpoint;
var client = new DocumentIntelligenceClient(new Uri(endpoint), new DefaultAzureCredential());
var client = new DocumentIntelligenceClient(new Uri(endpoint), TestEnvironment.Credential);

#region Snippet:DocumentIntelligenceExtractLayoutAsMarkdownAsync
#if SNIPPET
Expand Down
Loading

0 comments on commit ae4bf9a

Please sign in to comment.