Exemplo n.º 1
0
        public async Task Delete()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var credentialName     = Recording.GenerateAlphaNumericId("credential");
            var credentialToCreate = new ServicePrincipalCredentialEntity(credentialName, "clientId", "clientSecret", "tenantId");

            string credentialId = null;

            try
            {
                DataSourceCredentialEntity createdCredential = await adminClient.CreateDataSourceCredentialAsync(credentialToCreate);

                credentialId = createdCredential.Id;

                Assert.That(credentialId, Is.Not.Null.And.Not.Empty);
            }
            finally
            {
                if (credentialId != null)
                {
                    await adminClient.DeleteDataSourceCredentialAsync(credentialId);

                    var errorCause = "credentialId is invalid";
                    Assert.That(async() => await adminClient.GetDataSourceCredentialAsync(credentialId), Throws.InstanceOf <RequestFailedException>().With.Message.Contains(errorCause));
                }
            }
        }
Exemplo n.º 2
0
        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}");
            }
        }
Exemplo n.º 3
0
        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}");
        }