-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[MetricsAdvisor] README updates + credential code samples #22549
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2d0f495
Some readme updates
kinelski 2c7f296
Renamed samples
kinelski 6af5824
Update sdk/metricsadvisor/Azure.AI.MetricsAdvisor/README.md
kinelski fe7b346
Update sdk/metricsadvisor/Azure.AI.MetricsAdvisor/README.md
kinelski d5d37e7
Update sdk/metricsadvisor/Azure.AI.MetricsAdvisor/README.md
kinelski 056d5bd
Updated version
kinelski 0a939c1
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-net int…
kinelski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
157 changes: 157 additions & 0 deletions
157
...sadvisor/Azure.AI.MetricsAdvisor/tests/Samples/Sample02_CredentialEntityCrudOperations.cs
This file contains hidden or 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,157 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Azure.AI.MetricsAdvisor.Administration; | ||
| using Azure.AI.MetricsAdvisor.Models; | ||
| using Azure.AI.MetricsAdvisor.Tests; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Azure.AI.MetricsAdvisor.Samples | ||
| { | ||
| public partial class MetricsAdvisorSamples : MetricsAdvisorTestEnvironment | ||
| { | ||
| [Test] | ||
| public async Task CreateAndDeleteDataSourceCredentialAsync() | ||
| { | ||
| string endpoint = MetricsAdvisorUri; | ||
| string subscriptionKey = MetricsAdvisorSubscriptionKey; | ||
| string apiKey = MetricsAdvisorApiKey; | ||
| var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); | ||
|
|
||
| var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); | ||
|
|
||
| #region Snippet:CreateDataSourceCredentialAsync | ||
| #if SNIPPET | ||
| string credentialName = "<credentialName>"; | ||
| #else | ||
| string credentialName = GetUniqueName(); | ||
| #endif | ||
|
|
||
| var credentialEntity = new ServicePrincipalCredentialEntity(credentialName, "<clientId>", "<clientSecret>", "<tenantId>"); | ||
|
|
||
| Response<DataSourceCredentialEntity> response = await adminClient.CreateDataSourceCredentialAsync(credentialEntity); | ||
|
|
||
| DataSourceCredentialEntity createdCredentialEntity = response.Value; | ||
|
|
||
| Console.WriteLine($"Credential entity ID: {createdCredentialEntity.Id}"); | ||
| #endregion | ||
|
|
||
| // Delete the created credential to clean up the Metrics Advisor resource. Do not perform this | ||
| // step if you intend to keep using the credential. | ||
|
|
||
| await adminClient.DeleteDataSourceCredentialAsync(createdCredentialEntity.Id); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task GetDataSourceCredentialAsync() | ||
| { | ||
| string endpoint = MetricsAdvisorUri; | ||
| string subscriptionKey = MetricsAdvisorSubscriptionKey; | ||
| string apiKey = MetricsAdvisorApiKey; | ||
| var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); | ||
|
|
||
| var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); | ||
|
|
||
| string credentialEntityId = CredentialEntityId; | ||
|
|
||
| Response<DataSourceCredentialEntity> response = await adminClient.GetDataSourceCredentialAsync(credentialEntityId); | ||
|
|
||
| DataSourceCredentialEntity credentialEntity = response.Value; | ||
|
|
||
| Console.WriteLine($"Credential name: {credentialEntity.Name}"); | ||
| Console.WriteLine($"Credential description: {credentialEntity.Description}"); | ||
|
|
||
| // You can access specific properties of your credential entity depending on its kind. | ||
|
|
||
| if (credentialEntity.CredentialKind == DataSourceCredentialKind.ServicePrincipal) | ||
| { | ||
| Console.WriteLine("Credential of kind Service Principal:"); | ||
|
|
||
| var servicePrincipalEntity = credentialEntity as ServicePrincipalCredentialEntity; | ||
|
|
||
| Console.WriteLine($" Client ID: {servicePrincipalEntity.ClientId}"); | ||
| Console.WriteLine($" Tenant ID: {servicePrincipalEntity.TenantId}"); | ||
| } | ||
| else if (credentialEntity.CredentialKind == DataSourceCredentialKind.ServicePrincipalInKeyVault) | ||
| { | ||
| Console.WriteLine("Credential of kind Service Principal in Key Vault:"); | ||
|
|
||
| var servicePrincipalEntity = credentialEntity as ServicePrincipalInKeyVaultCredentialEntity; | ||
|
|
||
| Console.WriteLine($"Name of secret for client ID: {servicePrincipalEntity.SecretNameForClientId}"); | ||
| Console.WriteLine($"Name of secret for client secret: {servicePrincipalEntity.SecretNameForClientSecret}"); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task UpdateDataSourceCredentialAsync() | ||
| { | ||
| string endpoint = MetricsAdvisorUri; | ||
| string subscriptionKey = MetricsAdvisorSubscriptionKey; | ||
| string apiKey = MetricsAdvisorApiKey; | ||
| var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); | ||
|
|
||
| var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); | ||
|
|
||
| string credentialEntityId = CredentialEntityId; | ||
|
|
||
| Response<DataSourceCredentialEntity> response = await adminClient.GetDataSourceCredentialAsync(credentialEntityId); | ||
| DataSourceCredentialEntity credentialEntity = response.Value; | ||
|
|
||
| credentialEntity.Description = "This description was generated by a sample."; | ||
|
|
||
| // You can update specific properties of your credential entity depending on its kind. | ||
|
|
||
| if (credentialEntity.CredentialKind == DataSourceCredentialKind.ServicePrincipal) | ||
| { | ||
| var servicePrincipalEntity = credentialEntity as ServicePrincipalCredentialEntity; | ||
|
|
||
| servicePrincipalEntity.ClientId = "<newClientId>"; | ||
|
|
||
| // Secrets can't be read and must be updated through specific methods. | ||
|
|
||
| servicePrincipalEntity.UpdateClientSecret("<newClientSecret>"); | ||
| } | ||
|
|
||
| response = await adminClient.UpdateDataSourceCredentialAsync(credentialEntity); | ||
| DataSourceCredentialEntity updatedCredentialEntity = response.Value; | ||
|
|
||
| Console.WriteLine($"Updated description: {updatedCredentialEntity.Description}"); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task GetDataSourceCredentialsAsync() | ||
| { | ||
| string endpoint = MetricsAdvisorUri; | ||
| string subscriptionKey = MetricsAdvisorSubscriptionKey; | ||
| string apiKey = MetricsAdvisorApiKey; | ||
| var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); | ||
|
|
||
| var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); | ||
|
|
||
| var options = new GetDataSourceCredentialsOptions() | ||
| { | ||
| MaxPageSize = 5 | ||
| }; | ||
|
|
||
| int credentialCount = 0; | ||
|
|
||
| await foreach (DataSourceCredentialEntity credentialEntity in adminClient.GetDataSourceCredentialsAsync(options)) | ||
| { | ||
| Console.WriteLine($"Credential ID: {credentialEntity.Id}"); | ||
| Console.WriteLine($"Name: {credentialEntity.Name}"); | ||
| Console.WriteLine($"Description: {credentialEntity.Description}"); | ||
| Console.WriteLine($"Kind: {credentialEntity.CredentialKind}"); | ||
| Console.WriteLine(); | ||
|
|
||
| // Print at most 5 credentials. | ||
| if (++credentialCount >= 5) | ||
| { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.