Exemplo n.º 1
0
        public static async Task PatchSqlDatasourceCredentials(string WorkspaceId, string importName)
        {
            PowerBIClient pbiClient = GetPowerBiClient();
            var           datasets  = (await pbiClient.Datasets.GetDatasetsInGroupAsync(WorkspaceId)).Value;

            foreach (var dataset in datasets)
            {
                if (importName.Equals(dataset.Name))
                {
                    string datasetId   = dataset.Id;
                    var    datasources = (await pbiClient.Datasets.GetDatasourcesInGroupAsync(WorkspaceId, datasetId)).Value;
                    foreach (var datasource in datasources)
                    {
                        if (datasource.DatasourceType == "SQL")
                        {
                            var datasourceId = datasource.DatasourceId;
                            var gatewayId    = datasource.GatewayId;
                            // create credentials for Azure SQL database log in
                            Creds.BasicCredentials  creds   = new Creds.BasicCredentials("CptStudent", "pass@word1");
                            CredentialDetails       details = new CredentialDetails(creds);
                            UpdateDatasourceRequest req     = new UpdateDatasourceRequest(details);
                            // Update credentials through gateway
                            await pbiClient.Gateways.UpdateDatasourceAsync(gatewayId, datasourceId, details);
                        }
                    }
                }
            }
            return;
        }
        public void Cloud_BasicCredentialsTest()
        {
            CredentialsBase credentials       = new BasicCredentials("user", "pass");
            var             credentialDetails = new CredentialDetails(credentials, PrivacyLevel.None, EncryptedConnection.Encrypted);

            Assert.IsNotNull(credentialDetails);
            Assert.AreEqual("{\"credentialData\":[{\"name\":\"username\",\"value\":\"user\"},{\"name\":\"password\",\"value\":\"pass\"}]}", credentialDetails.Credentials);
            Assert.AreEqual(CredentialType.Basic, credentialDetails.CredentialType);
            Assert.AreEqual(EncryptedConnection.Encrypted, credentialDetails.EncryptedConnection);
            Assert.AreEqual(EncryptionAlgorithm.None, credentialDetails.EncryptionAlgorithm);
            Assert.AreEqual(PrivacyLevel.None, credentialDetails.PrivacyLevel);
            Assert.AreEqual(false, credentialDetails.UseCallerAADIdentity);
        }
        public void OnPrem_BasicCredentialsTest()
        {
            CredentialsBase credentials          = new BasicCredentials("user", "pass");
            var             credentialsEncryptor = new AsymmetricKeyEncryptor(publicKey);

            var credentialDetails = new CredentialDetails(credentials, PrivacyLevel.None, EncryptedConnection.Encrypted, credentialsEncryptor);

            Assert.IsNotNull(credentialDetails);
            Assert.IsNotNull(credentialDetails.Credentials);
            Assert.AreEqual(CredentialType.Basic, credentialDetails.CredentialType);
            Assert.AreEqual(EncryptedConnection.Encrypted, credentialDetails.EncryptedConnection);
            Assert.AreEqual(EncryptionAlgorithm.RSAOAEP, credentialDetails.EncryptionAlgorithm);
            Assert.AreEqual(PrivacyLevel.None, credentialDetails.PrivacyLevel);
            Assert.AreEqual(false, credentialDetails.UseCallerAADIdentity);
        }