mirror of
https://github.com/bitwarden/server
synced 2025-12-23 03:33:35 +00:00
[PM-5548] Eliminate in-app purchase logic (#3640)
* Eliminate in-app purchase logic * Totally remove obsolete and unused properties / types * Remove unused enum values * Restore token update
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IMetaDataRepository
|
||||
{
|
||||
Task DeleteAsync(string objectName, string id);
|
||||
Task<IDictionary<string, string>> GetAsync(string objectName, string id);
|
||||
Task<string> GetAsync(string objectName, string id, string prop);
|
||||
Task UpsertAsync(string objectName, string id, IDictionary<string, string> dict);
|
||||
Task UpsertAsync(string objectName, string id, KeyValuePair<string, string> keyValuePair);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
namespace Bit.Core.Repositories.Noop;
|
||||
|
||||
public class MetaDataRepository : IMetaDataRepository
|
||||
{
|
||||
public Task DeleteAsync(string objectName, string id)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task<IDictionary<string, string>> GetAsync(string objectName, string id)
|
||||
{
|
||||
return Task.FromResult(null as IDictionary<string, string>);
|
||||
}
|
||||
|
||||
public Task<string> GetAsync(string objectName, string id, string prop)
|
||||
{
|
||||
return Task.FromResult(null as string);
|
||||
}
|
||||
|
||||
public Task UpsertAsync(string objectName, string id, IDictionary<string, string> dict)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task UpsertAsync(string objectName, string id, KeyValuePair<string, string> keyValuePair)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
using System.Net;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Settings;
|
||||
using Microsoft.Azure.Cosmos.Table;
|
||||
|
||||
namespace Bit.Core.Repositories.TableStorage;
|
||||
|
||||
public class MetaDataRepository : IMetaDataRepository
|
||||
{
|
||||
private readonly CloudTable _table;
|
||||
|
||||
public MetaDataRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.Events.ConnectionString)
|
||||
{ }
|
||||
|
||||
public MetaDataRepository(string storageConnectionString)
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
|
||||
var tableClient = storageAccount.CreateCloudTableClient();
|
||||
_table = tableClient.GetTableReference("metadata");
|
||||
}
|
||||
|
||||
public async Task<IDictionary<string, string>> GetAsync(string objectName, string id)
|
||||
{
|
||||
var query = new TableQuery<DictionaryEntity>().Where(
|
||||
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, $"{objectName}_{id}"));
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, null);
|
||||
return queryResults.Results.FirstOrDefault()?.ToDictionary(d => d.Key, d => d.Value.StringValue);
|
||||
}
|
||||
|
||||
public async Task<string> GetAsync(string objectName, string id, string prop)
|
||||
{
|
||||
var dict = await GetAsync(objectName, id);
|
||||
if (dict != null && dict.ContainsKey(prop))
|
||||
{
|
||||
return dict[prop];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task UpsertAsync(string objectName, string id, KeyValuePair<string, string> keyValuePair)
|
||||
{
|
||||
var query = new TableQuery<DictionaryEntity>().Where(
|
||||
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, $"{objectName}_{id}"));
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, null);
|
||||
var entity = queryResults.Results.FirstOrDefault();
|
||||
if (entity == null)
|
||||
{
|
||||
entity = new DictionaryEntity
|
||||
{
|
||||
PartitionKey = $"{objectName}_{id}",
|
||||
RowKey = string.Empty
|
||||
};
|
||||
}
|
||||
if (entity.ContainsKey(keyValuePair.Key))
|
||||
{
|
||||
entity.Remove(keyValuePair.Key);
|
||||
}
|
||||
entity.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
|
||||
public async Task UpsertAsync(string objectName, string id, IDictionary<string, string> dict)
|
||||
{
|
||||
var entity = new DictionaryEntity
|
||||
{
|
||||
PartitionKey = $"{objectName}_{id}",
|
||||
RowKey = string.Empty
|
||||
};
|
||||
foreach (var item in dict)
|
||||
{
|
||||
entity.Add(item.Key, item.Value);
|
||||
}
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string objectName, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _table.ExecuteAsync(TableOperation.Delete(new DictionaryEntity
|
||||
{
|
||||
PartitionKey = $"{objectName}_{id}",
|
||||
RowKey = string.Empty,
|
||||
ETag = "*"
|
||||
}));
|
||||
}
|
||||
catch (StorageException e) when (e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user