public string GetPassword(string id, SvcRepositoryType repositoryType, string passphrase) { // TODO: read document async and directly convert to model for a better performance var filter = Builders <BsonDocument> .Filter.Eq("_id", id); var document = base.collection.Find(filter).FirstOrDefault(); if (document == null) { return(null); } var creds = document["RepositoryCredentials"].AsBsonArray; var credentials = new List <CredentialsWithPasswordDto>(creds.Count); credentials.AddRange(creds.Select(item => BsonSerializer.Deserialize <CredentialsWithPasswordDto>(item.AsBsonDocument))); CredentialsWithPasswordDto dto = credentials.FirstOrDefault(c => c.RepositoryType == repositoryType); if (dto == null) { Logging.Log().Debug($"Password for {id} user and {repositoryType} repository type not found."); return(null); } string decrypted = StringCipher.Decrypt(dto.Password, this.webApiConfiguration.SecretPassword); return(decrypted); }
public async Task <string> GetPasswordAsync(string userId, SvcRepositoryType repositoryType) { var uri = new Uri(new Uri(this.workerConfig.ApiUrl), "/user/" + userId + $"/credentials/{repositoryType}/password?passphrase=" + this.workerConfig.SecretPassword); var response = await this.httpClient.GetStringAsync(uri); var dto = JsonConvert.DeserializeObject <Dictionary <string, string> >(response); if (dto.Count == 0) { throw new KeyNotFoundException($"Could not retrieve {repositoryType} repository credentials for user with id {userId}"); } string password = dto["Password"]; return(password); }
public string GetPassword(string userId, SvcRepositoryType repositoryType) { return(this.GetPasswordAsync(userId, repositoryType).Result); }
public string GetPassword(string id, SvcRepositoryType repositoryType, string passphrase) { return(this.query.GetPassword(id, repositoryType, passphrase)); }