diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs index f8de2e9f..6c116865 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs @@ -122,6 +122,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent this.ServiceHost.SetRequestHandler(CreateAgentScheduleRequest.Type, HandleCreateAgentScheduleRequest); this.ServiceHost.SetRequestHandler(UpdateAgentScheduleRequest.Type, HandleUpdateAgentScheduleRequest); this.ServiceHost.SetRequestHandler(DeleteAgentScheduleRequest.Type, HandleDeleteAgentScheduleRequest); + } #region "Jobs Handlers" diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/AgentProxyAccountActions.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/AgentProxyAccountActions.cs index 556fedb7..fd428941 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/AgentProxyAccountActions.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/AgentProxyAccountActions.cs @@ -131,7 +131,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent // Try refresh and check again this.DataContainer.Server.JobServer.ProxyAccounts.Refresh(); if (this.DataContainer.Server.JobServer.ProxyAccounts.Contains(this.proxyAccountName)) - { + { proxyAccount = AgentProxyAccountActions.GetProxyAccount(this.proxyAccountName, this.DataContainer.Server.JobServer); // Set the other properties proxyAccount.CredentialName = proxyInfo.CredentialName; @@ -209,7 +209,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent } #endif } - + public bool Create() { CreateOrUpdateProxyAccount(this.proxyInfo); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Security/Contracts/CredentialInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/Security/Contracts/CredentialInfo.cs index b08bfcf3..b86acc18 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Security/Contracts/CredentialInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Security/Contracts/CredentialInfo.cs @@ -14,11 +14,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Security.Contracts /// public class CredentialInfo { - public int Id { get; } + public int Id { get; set; } public string Identity { get; set; } public string Name { get; set; } - public DateTime DateLastModified { get; } - public DateTime CreateDate { get; } - public string ProviderName { get; set; } + public DateTime DateLastModified { get; set; } + public DateTime CreateDate { get; set; } + public string ProviderName { get; set; } } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Security/Contracts/CredentialRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/Security/Contracts/CredentialRequest.cs index 16808ade..be123dc7 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Security/Contracts/CredentialRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Security/Contracts/CredentialRequest.cs @@ -9,6 +9,32 @@ using Microsoft.SqlTools.Utility; namespace Microsoft.SqlTools.ServiceLayer.Security.Contracts { + /// + /// Get Credential parameters + /// + public class GetCredentialsParams: GeneralRequestDetails + { + public string OwnerUri { get; set; } + } + + public class GetCredentialsResult: ResultStatus + { + public CredentialInfo[] Credentials { get; set; } + } + + /// + /// SQL Agent Credentials request type + /// + public class GetCredentialsRequest + { + /// + /// Request definition + /// + public static readonly + RequestType Type = + RequestType.Create("security/credentials"); + } + /// /// Create Credential parameters /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Security/SecurityService.cs b/src/Microsoft.SqlTools.ServiceLayer/Security/SecurityService.cs index 6bd55631..7f236f5a 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Security/SecurityService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Security/SecurityService.cs @@ -82,6 +82,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Security this.ServiceHost.SetRequestHandler(CreateCredentialRequest.Type, HandleCreateCredentialRequest); this.ServiceHost.SetRequestHandler(UpdateCredentialRequest.Type, HandleUpdateCredentialRequest); this.ServiceHost.SetRequestHandler(DeleteCredentialRequest.Type, HandleDeleteCredentialRequest); + this.ServiceHost.SetRequestHandler(GetCredentialsRequest.Type, HandleGetCredentialsRequest); } /// @@ -137,6 +138,49 @@ namespace Microsoft.SqlTools.ServiceLayer.Security }); } + + /// + /// Handle request to get all credentials + /// + internal async Task HandleGetCredentialsRequest(GetCredentialsParams parameters, RequestContext requestContext) + { + await Task.Run(async () => + { + var result = new GetCredentialsResult(); + try + { + ConnectionInfo connInfo; + ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo); + CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); + + var credentials = dataContainer.Server.Credentials; + int credentialsCount = credentials.Count; + CredentialInfo[] credentialsInfos = new CredentialInfo[credentialsCount]; + for (int i = 0; i < credentialsCount; ++i) + { + credentialsInfos[i] = new CredentialInfo(); + credentialsInfos[i].Name = credentials[i].Name; + credentialsInfos[i].Identity = credentials[i].Identity; + credentialsInfos[i].Id = credentials[i].ID; + credentialsInfos[i].DateLastModified = credentials[i].DateLastModified; + credentialsInfos[i].CreateDate = credentials[i].CreateDate; + credentialsInfos[i].ProviderName = credentials[i].ProviderName; + } + result.Credentials = credentialsInfos; + result.Success = true; + } + catch (Exception ex) + { + result.Success = false; + result.ErrorMessage = ex.ToString(); + } + + await requestContext.SendResult(result); + }); + } + + + /// /// Disposes the service ///