-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
KeyVaultSecret.cs
74 lines (67 loc) · 3.32 KB
/
KeyVaultSecret.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using Azure.ResourceManager.KeyVault;
using Azure.ResourceManager.KeyVault.Models;
namespace Azure.Provisioning.KeyVaults
{
/// <summary>
/// A key vault secret.
/// </summary>
public class KeyVaultSecret : Resource<KeyVaultSecretData>
{
private const string ResourceTypeName = "Microsoft.KeyVault/vaults/secrets";
private static KeyVaultSecretData Empty(string name) => ArmKeyVaultModelFactory.KeyVaultSecretData();
/// <summary>
/// Initializes a new instance of the <see cref="KeyVaultSecret"/>.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="parent">The parent vault.</param>
/// <param name="name">The name.</param>
/// <param name="version">The version.</param>
public KeyVaultSecret(IConstruct scope, KeyVault? parent = null, string name = "kvs", string version = KeyVault.DefaultVersion)
: this(scope, parent, name, version, false, (name) => ArmKeyVaultModelFactory.KeyVaultSecretData(
name: name,
resourceType: ResourceTypeName,
properties: ArmKeyVaultModelFactory.SecretProperties(
value: Guid.Empty.ToString())
))
{
}
private KeyVaultSecret(IConstruct scope, KeyVault? parent, string name, string version = KeyVault.DefaultVersion, bool isExisting = false, Func<string, KeyVaultSecretData>? createProperties = null)
: base(scope, parent, name, ResourceTypeName, version, createProperties ?? Empty, isExisting)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="KeyVaultSecret"/>.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="name">The name.</param>
/// <param name="connectionString">The connection string.</param>
/// <param name="parent">The parent vault.</param>
/// <param name="version">The version.</param>
public KeyVaultSecret(IConstruct scope, string name, ConnectionString connectionString, KeyVault? parent = null, string version = KeyVault.DefaultVersion)
: this(scope, parent, name, version, false, (name) => ArmKeyVaultModelFactory.KeyVaultSecretData(
name: name,
resourceType: ResourceTypeName,
properties: ArmKeyVaultModelFactory.SecretProperties(
value: connectionString.Value)
))
{
}
/// <summary>
/// Creates a new instance of the <see cref="KeyVaultSecret"/> class referencing an existing instance.
/// </summary>
/// <param name="scope">The scope.</param>
/// <param name="name">The resource name.</param>
/// <param name="parent">The parent vault.</param>
/// <returns>The KeyVaultSecret instance.</returns>
public static KeyVaultSecret FromExisting(IConstruct scope, string name, KeyVault parent)
=> new KeyVaultSecret(scope, parent, name, isExisting: true);
/// <inheritdoc/>
protected override Resource? FindParentInScope(IConstruct scope)
{
return scope.GetSingleResource<KeyVault>() ?? new KeyVault(scope);
}
}
}