Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit 3efd04d

Browse files
stishkinstas
authored andcommitted
bump dependencies to latest (#1782)
remove/implement "cached todo" from some methods, Co-authored-by: stas <statis@microsoft.com>
1 parent c70f8e2 commit 3efd04d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/ApiService/ApiService/onefuzzlib/Storage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ public interface IStorage
2626
public class Storage : IStorage
2727
{
2828
private ICreds _creds;
29+
private ArmClient _armClient;
2930

3031
public Storage(ICreds creds)
3132
{
3233
_creds = creds;
34+
_armClient = new ArmClient(credential: _creds.GetIdentity(), defaultSubscriptionId: _creds.GetSubcription());
3335
}
3436

3537
public static string GetFuncStorage()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Azure.Data.Tables;
2+
using System;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Azure.Core;
6+
using Azure.ResourceManager.Storage;
7+
using Azure.ResourceManager;
8+
using Azure.Identity;
9+
10+
namespace Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
11+
12+
13+
public interface IStorageProvider
14+
{
15+
Task<TableClient> GetTableClient(string table);
16+
//IAsyncEnumerable<T> QueryAsync<T>(string filter) where T : EntityBase;
17+
//Task<bool> Replace<T>(T entity) where T : EntityBase;
18+
19+
}
20+
21+
public class StorageProvider : IStorageProvider
22+
{
23+
private readonly string _accountId;
24+
private readonly EntityConverter _entityConverter;
25+
private readonly ArmClient _armClient;
26+
27+
public StorageProvider(string accountId)
28+
{
29+
_accountId = accountId;
30+
_entityConverter = new EntityConverter();
31+
_armClient = new ArmClient(new DefaultAzureCredential());
32+
}
33+
34+
public async Task<TableClient> GetTableClient(string table)
35+
{
36+
var (name, key) = GetStorageAccountNameAndKey(_accountId);
37+
var identifier = new ResourceIdentifier(_accountId);
38+
var tableClient = new TableServiceClient(new Uri($"https://{identifier.Name}.table.core.windows.net"), new TableSharedKeyCredential(name, key));
39+
await tableClient.CreateTableIfNotExistsAsync(table);
40+
return tableClient.GetTableClient(table);
41+
}
42+
43+
44+
public (string?, string?) GetStorageAccountNameAndKey(string accountId)
45+
{
46+
var resourceId = new ResourceIdentifier(accountId);
47+
var storageAccount = _armClient.GetStorageAccountResource(resourceId);
48+
var key = storageAccount.GetKeys().Value.Keys.FirstOrDefault();
49+
return (resourceId.Name, key?.Value);
50+
}
51+
52+
53+
}

0 commit comments

Comments
 (0)