Skip to content

Commit 56ee09b

Browse files
committed
Addressed review comments
Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com>
1 parent ebe30bc commit 56ee09b

File tree

6 files changed

+73
-16
lines changed

6 files changed

+73
-16
lines changed

samples/LocalEnvSecretStoreSample/LocalEnvSecretStoreSample.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

9-
<ItemGroup>
10-
<PackageReference Include="Dapr.PluggableComponents.AspNetCore" Version="0.2.0" />
11-
</ItemGroup>
12-
139
<ItemGroup>
1410
<ProjectReference Include="..\..\src\Dapr.PluggableComponents.AspNetCore\Dapr.PluggableComponents.AspNetCore.csproj">
1511
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>

samples/LocalEnvSecretStoreSample/Services/LocalEnvSecretStore.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Dapr.PluggableComponents.Components;
1+
using System;
2+
using Dapr.PluggableComponents.Components;
23
using Dapr.PluggableComponents.Components.SecretStores;
34

45
namespace LocalEnvSecretStoreSample.Services;
@@ -39,14 +40,24 @@ public Task<SecretStoreBulkGetResponse> BulkGetAsync(SecretStoreBulkGetRequest r
3940
this.logger.LogInformation("Get request for all secrets");
4041

4142
SecretStoreBulkGetResponse? response = null;
42-
Dictionary<string, string> resp = new Dictionary<string, string>();
43+
SecretStoreResponse? secretStoreResponse = null;
44+
Dictionary<string, string>? resp = null;
45+
Dictionary<string, SecretStoreResponse> bulkResp = new Dictionary<string, SecretStoreResponse>();
4346
foreach (string key in Environment.GetEnvironmentVariables().Keys)
4447
{
45-
resp.Add(key, Environment.GetEnvironmentVariable(key));
48+
resp = new Dictionary<string, string>
49+
{
50+
{key, Environment.GetEnvironmentVariable(key) }
51+
};
52+
secretStoreResponse = new SecretStoreResponse
53+
{
54+
Data = resp
55+
};
56+
bulkResp.Add(key, secretStoreResponse);
4657
}
4758
response = new SecretStoreBulkGetResponse
4859
{
49-
Data = resp
60+
Data = bulkResp
5061
};
5162
return Task.FromResult(response);
5263
}

src/Dapr.PluggableComponents.Protos/Dapr.PluggableComponents.Protos.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<Protobuf Include="@(Protos-&gt;'$(ProtosComponentsDir)/%(Identity)')" ProtoRoot="$(ProtosRootDir)" GrpcServices="Client,Server" />
26+
<Protobuf Include="@(Protos->'$(ProtosComponentsDir)/%(Identity)')" ProtoRoot="$(ProtosRootDir)" GrpcServices="Client,Server" />
2727
</ItemGroup>
2828

2929
<ItemGroup>

src/Dapr.PluggableComponents/Components/SecretStores/SecretStoreBulkGetResponse.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ namespace Dapr.PluggableComponents.Components.SecretStores;
1919

2020
public sealed record SecretStoreBulkGetResponse
2121
{
22-
public IReadOnlyDictionary<string, string> Data = new Dictionary<string, string>();
22+
public IReadOnlyDictionary<string, SecretStoreResponse> Data { get; init; } = new Dictionary<string, SecretStoreResponse>();
2323

24-
internal static BulkGetSecretResponse ToBulkGetResponse(SecretStoreBulkGetResponse? response)
24+
internal static BulkGetSecretResponse ToBulkGetResponse(SecretStoreBulkGetResponse response)
2525
{
2626
var grpcResponse = new BulkGetSecretResponse();
2727
if (response != null)
2828
{
2929
foreach (var item in response.Data)
3030
{
31-
var secretItem = new SecretResponse();
32-
secretItem.Secrets.Add(item.Key, item.Value);
33-
grpcResponse.Data.Add(item.Key, secretItem);
31+
var secretResp = new SecretResponse();
32+
foreach (var sec in item.Value.Data)
33+
{
34+
secretResp.Secrets.Add(sec.Key, sec.Value);
35+
grpcResponse.Data.Add(sec.Key, secretResp);
36+
}
3437
}
3538
}
3639
return grpcResponse;

src/Dapr.PluggableComponents/Components/SecretStores/SecretStoreGetResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public sealed record SecretStoreGetResponse
2828
/// <remarks>
2929
/// If omitted, defaults to an empty array.
3030
/// </remarks>
31-
public IReadOnlyDictionary<string, string> Data = new Dictionary<string, string>();
31+
public IReadOnlyDictionary<string, string> Data { get; init; } = new Dictionary<string, string>();
3232

3333

34-
internal static GetSecretResponse ToGetResponse(SecretStoreGetResponse? response)
34+
internal static GetSecretResponse ToGetResponse(SecretStoreGetResponse response)
3535
{
3636
var grpcResponse = new GetSecretResponse();
3737

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ------------------------------------------------------------------------
2+
// Copyright 2023 The Dapr Authors
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
// ------------------------------------------------------------------------
13+
14+
using Dapr.PluggableComponents.Utilities;
15+
using Dapr.Proto.Components.V1;
16+
using Google.Protobuf;
17+
namespace Dapr.PluggableComponents.Components.SecretStores;
18+
19+
/// <summary>
20+
/// Represents properties associated with a response to retrieving bulk secret from a secret store.
21+
/// </summary>
22+
public sealed record SecretStoreResponse
23+
{
24+
/// <summary>
25+
/// Gets or sets the key's value.
26+
/// </summary>
27+
/// <remarks>
28+
/// If omitted, defaults to an empty array.
29+
/// </remarks>
30+
public IReadOnlyDictionary<string, string> Data { get; init; } = new Dictionary<string, string>();
31+
32+
33+
internal static SecretResponse ToGetResponse(SecretStoreResponse response)
34+
{
35+
var grpcResponse = new SecretResponse();
36+
37+
// NOTE: in case of not found, you should not return any error.
38+
39+
if (response != null)
40+
{
41+
grpcResponse.Secrets.Add(response.Data);
42+
}
43+
44+
return grpcResponse;
45+
}
46+
}
47+

0 commit comments

Comments
 (0)