46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using System;
|
|
using System.Data.Common;
|
|
using Swarmops.Basic.Types;
|
|
using Swarmops.Basic.Types.Security;
|
|
|
|
namespace Swarmops.Database
|
|
{
|
|
public partial class SwarmDb
|
|
{
|
|
public BasicExternalCredential GetExternalCredential (string serviceName)
|
|
{
|
|
using (DbConnection connection = GetMySqlDbConnection())
|
|
{
|
|
connection.Open();
|
|
|
|
DbCommand command =
|
|
GetDbCommand (
|
|
"SELECT ExternalCredentialId,ServiceName,Login,Password From ExternalCredentials WHERE ServiceName=@serviceName",
|
|
connection);
|
|
|
|
AddParameterWithName(command, "serviceName", serviceName);
|
|
|
|
using (DbDataReader reader = command.ExecuteReader())
|
|
{
|
|
if (reader.Read())
|
|
{
|
|
return ReadExternalCredentialFromDataReader (reader);
|
|
}
|
|
|
|
throw new ArgumentException ("Unknown Service Name");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private BasicExternalCredential ReadExternalCredentialFromDataReader (DbDataReader reader)
|
|
{
|
|
int externalCredentialId = reader.GetInt32 (0);
|
|
string serviceName = reader.GetString (1);
|
|
string login = reader.GetString (2);
|
|
string password = reader.GetString (3);
|
|
|
|
return new BasicExternalCredential (externalCredentialId, serviceName, login, password);
|
|
}
|
|
}
|
|
} |