forked from microsoft/kernel-memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAzureQueuesConfig.cs
73 lines (62 loc) · 2.33 KB
/
AzureQueuesConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json.Serialization;
using Azure;
using Azure.Core;
using Azure.Storage;
using Microsoft.KernelMemory.Configuration;
#pragma warning disable IDE0130 // reduce number of "using" statements
// ReSharper disable once CheckNamespace - reduce number of "using" statements
namespace Microsoft.KernelMemory;
#pragma warning disable CA1024 // properties would need to require serializer cfg to ignore them
public class AzureQueuesConfig
{
private StorageSharedKeyCredential? _storageSharedKeyCredential;
private AzureSasCredential? _azureSasCredential;
private TokenCredential? _tokenCredential;
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum AuthTypes
{
Unknown = -1,
AzureIdentity,
ConnectionString,
AccountKey,
ManualStorageSharedKeyCredential,
ManualAzureSasCredential,
ManualTokenCredential,
}
public AuthTypes Auth { get; set; } = AuthTypes.Unknown;
public string ConnectionString { get; set; } = "";
public string Account { get; set; } = "";
public string AccountKey { get; set; } = "";
public string EndpointSuffix { get; set; } = "core.windows.net";
public void SetCredential(StorageSharedKeyCredential credential)
{
this.Auth = AuthTypes.ManualStorageSharedKeyCredential;
this._storageSharedKeyCredential = credential;
}
public void SetCredential(AzureSasCredential credential)
{
this.Auth = AuthTypes.ManualAzureSasCredential;
this._azureSasCredential = credential;
}
public void SetCredential(TokenCredential credential)
{
this.Auth = AuthTypes.ManualTokenCredential;
this._tokenCredential = credential;
}
public StorageSharedKeyCredential GetStorageSharedKeyCredential()
{
return this._storageSharedKeyCredential
?? throw new ConfigurationException("StorageSharedKeyCredential not defined");
}
public AzureSasCredential GetAzureSasCredential()
{
return this._azureSasCredential
?? throw new ConfigurationException("AzureSasCredential not defined");
}
public TokenCredential GetTokenCredential()
{
return this._tokenCredential
?? throw new ConfigurationException("TokenCredential not defined");
}
}