-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
FunctionRouterRuleCredential.cs
78 lines (70 loc) · 2.88 KB
/
FunctionRouterRuleCredential.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
74
75
76
77
78
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Text.Json;
using Azure.Core;
namespace Azure.Communication.JobRouter
{
public partial class FunctionRouterRuleCredential : IUtf8JsonSerializable
{
/// <summary> Initializes a new instance of AzureFunctionRuleCredential. </summary>
/// <param name="functionKey"> Access key scoped to a particular function. </param>
/// <exception cref="ArgumentNullException"> <paramref name="functionKey"/> is null. </exception>
public FunctionRouterRuleCredential(string functionKey)
{
Argument.AssertNotNullOrWhiteSpace(functionKey, nameof(functionKey));
FunctionKey = functionKey;
}
/// <summary> Initializes a new instance of AzureFunctionRuleCredential. </summary>
/// <param name="appKey">
/// Access key scoped to a Azure Function app.
///
/// This key grants access to all functions under the app.
/// </param>
/// <param name="clientId">
/// Client id, when AppKey is provided
///
/// In context of Azure function, this is usually the name of the key.
/// </param>
/// <exception cref="ArgumentNullException"> <paramref name="appKey"/> or <paramref name="clientId"/> is null. </exception>
public FunctionRouterRuleCredential(string appKey, string clientId)
{
Argument.AssertNotNullOrWhiteSpace(appKey, nameof(appKey));
Argument.AssertNotNullOrWhiteSpace(clientId, nameof(clientId));
AppKey = appKey;
ClientId = clientId;
}
/// <summary> Access key scoped to a particular function. </summary>
internal string FunctionKey { get; }
/// <summary>
/// Access key scoped to a Azure Function app.
/// This key grants access to all functions under the app.
/// </summary>
internal string AppKey { get; }
/// <summary>
/// Client id, when AppKey is provided
/// In context of Azure function, this is usually the name of the key
/// </summary>
internal string ClientId { get; }
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
if (Optional.IsDefined(FunctionKey))
{
writer.WritePropertyName("functionKey"u8);
writer.WriteStringValue(FunctionKey);
}
if (Optional.IsDefined(AppKey))
{
writer.WritePropertyName("appKey"u8);
writer.WriteStringValue(AppKey);
}
if (Optional.IsDefined(ClientId))
{
writer.WritePropertyName("clientId"u8);
writer.WriteStringValue(ClientId);
}
writer.WriteEndObject();
}
}
}