Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Downgrade user-secrets CLI tool to use 1.0.0 runtime #101

Merged
merged 1 commit into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ project.lock.json
.testPublish/
.build/
/.vs/
*.nuget.props
*.nuget.targets
23 changes: 15 additions & 8 deletions UserSecrets.sln
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24709.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{01661652-A100-41E3-AE6E-E6151EB85666}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.Configuration.UserSecrets", "src\Microsoft.Extensions.Configuration.UserSecrets\Microsoft.Extensions.Configuration.UserSecrets.xproj", "{58B6443B-1278-4DF9-B7BB-DDF3BFFCF868}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{9444A5DC-EE0B-4245-B81B-2CEF6F842F3D}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.SecretManager.Tests", "test\Microsoft.Extensions.SecretManager.Tests\Microsoft.Extensions.SecretManager.Tests.xproj", "{113EBBD2-E857-4CAF-9B53-7A8742CBCD4A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CD87E04A-587D-44A6-BB15-A966DB3C18CF}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.SecretManager.Tools", "src\Microsoft.Extensions.SecretManager.Tools\Microsoft.Extensions.SecretManager.Tools.xproj", "{8730E848-CA0F-4E0A-9A2F-BC22AD0B2C4E}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.SecretManager.Tools.Tests", "test\Microsoft.Extensions.SecretManager.Tools.Tests\Microsoft.Extensions.SecretManager.Tools.Tests.xproj", "{7B331122-83B1-4F08-A119-DC846959844C}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.Configuration.UserSecrets.Tests", "test\Microsoft.Extensions.Configuration.UserSecrets.Tests\Microsoft.Extensions.Configuration.UserSecrets.Tests.xproj", "{AC7FAD2A-5763-404D-B0FC-3CCA81A16B0A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,21 +29,26 @@ Global
{58B6443B-1278-4DF9-B7BB-DDF3BFFCF868}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58B6443B-1278-4DF9-B7BB-DDF3BFFCF868}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58B6443B-1278-4DF9-B7BB-DDF3BFFCF868}.Release|Any CPU.Build.0 = Release|Any CPU
{113EBBD2-E857-4CAF-9B53-7A8742CBCD4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{113EBBD2-E857-4CAF-9B53-7A8742CBCD4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{113EBBD2-E857-4CAF-9B53-7A8742CBCD4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{113EBBD2-E857-4CAF-9B53-7A8742CBCD4A}.Release|Any CPU.Build.0 = Release|Any CPU
{8730E848-CA0F-4E0A-9A2F-BC22AD0B2C4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8730E848-CA0F-4E0A-9A2F-BC22AD0B2C4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8730E848-CA0F-4E0A-9A2F-BC22AD0B2C4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8730E848-CA0F-4E0A-9A2F-BC22AD0B2C4E}.Release|Any CPU.Build.0 = Release|Any CPU
{7B331122-83B1-4F08-A119-DC846959844C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B331122-83B1-4F08-A119-DC846959844C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B331122-83B1-4F08-A119-DC846959844C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B331122-83B1-4F08-A119-DC846959844C}.Release|Any CPU.Build.0 = Release|Any CPU
{AC7FAD2A-5763-404D-B0FC-3CCA81A16B0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC7FAD2A-5763-404D-B0FC-3CCA81A16B0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC7FAD2A-5763-404D-B0FC-3CCA81A16B0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC7FAD2A-5763-404D-B0FC-3CCA81A16B0A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{58B6443B-1278-4DF9-B7BB-DDF3BFFCF868} = {01661652-A100-41E3-AE6E-E6151EB85666}
{113EBBD2-E857-4CAF-9B53-7A8742CBCD4A} = {9444A5DC-EE0B-4245-B81B-2CEF6F842F3D}
{8730E848-CA0F-4E0A-9A2F-BC22AD0B2C4E} = {01661652-A100-41E3-AE6E-E6151EB85666}
{7B331122-83B1-4F08-A119-DC846959844C} = {9444A5DC-EE0B-4245-B81B-2CEF6F842F3D}
{AC7FAD2A-5763-404D-B0FC-3CCA81A16B0A} = {9444A5DC-EE0B-4245-B81B-2CEF6F842F3D}
EndGlobalSection
EndGlobal
13 changes: 10 additions & 3 deletions src/Microsoft.Extensions.SecretManager.Tools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,25 @@ private void PrintAll(IDictionary<string, string> secrets)
}
}

private void ProcessSecretFile(string projectPath, Action<IDictionary<string,string>> observer, bool persist = true)
private void ProcessSecretFile(string projectPath, Action<IDictionary<string, string>> observer, bool persist = true)
{
Logger.LogDebug(Resources.Message_Project_File_Path, projectPath);
var secretsFilePath = PathHelper.GetSecretsPath(projectPath);
Logger.LogDebug(Resources.Message_Secret_File_Path, secretsFilePath);

{
// workaround https://github.com/aspnet/Configuration/issues/478
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you file a bug for this and self assign? Easy to miss TODOs in code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Added #102

// TODO remove when tool upgrades to use 1.1.0
Directory.CreateDirectory(Path.GetDirectoryName(secretsFilePath));
}

var secrets = new ConfigurationBuilder()
.AddJsonFile(secretsFilePath, optional: true)
.AddJsonFile(secretsFilePath, optional: true, reloadOnChange: false)
.Build()
.AsEnumerable()
.Where(i => i.Value != null)
.ToDictionary(i => i.Key, i => i.Value, StringComparer.OrdinalIgnoreCase);

observer(secrets);

if (persist)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Microsoft.Extensions.SecretManager.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: NeutralResourcesLanguage("en-us")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

[assembly: AssemblyCompany("Microsoft Corporation.")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Microsoft.Extensions.SecretManager.Tools.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions src/Microsoft.Extensions.SecretManager.Tools/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
"nowarn": [
"CS1591"
],
"xmlDoc": true,
"embed": {
"mappings": {
"Microsoft.Extensions.SecretManager.Resources": "Resources.resx"
}
}
"xmlDoc": true
},
"description": "Command line tool to manage user secrets for Microsoft.Extensions.Configuration.",
"packOptions": {
Expand All @@ -28,18 +23,21 @@
]
},
"dependencies": {
"Microsoft.Extensions.Configuration.UserSecrets": "1.1.0-*",
"Microsoft.Extensions.CommandLineUtils": "1.1.0-*",
"Microsoft.Extensions.Logging": "1.1.0-*",
"Microsoft.Extensions.Configuration.UserSecrets": {
"version": "1.0.0",
"target": "package"
},
"Microsoft.Extensions.CommandLineUtils": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Newtonsoft.Json": "9.0.1",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0-*",
"System.Runtime.Serialization.Primitives": "4.1.1-*"
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
"System.Runtime.Serialization.Primitives": "4.1.1"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-*",
"version": "1.0.0",
"type": "platform"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,42 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.Extensions.SecretManager.Tests;
using Microsoft.Extensions.SecretManager.Tools;
using System.Linq;
using System.IO;
using System.Text;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Microsoft.Extensions.Configuration.UserSecrets.Tests
{
public class ConfigurationExtensionTests
{
private void SetSecret(string id, string key, string value)
{
var secretsFilePath = PathHelper.GetSecretsPathFromSecretsId(id);
var secrets = new ConfigurationBuilder()
.AddJsonFile(secretsFilePath, optional: true)
.Build()
.AsEnumerable()
.Where(i => i.Value != null)
.ToDictionary(i => i.Key, i => i.Value, StringComparer.OrdinalIgnoreCase);

secrets[key] = value;

Directory.CreateDirectory(Path.GetDirectoryName(secretsFilePath));

var contents = new JObject();
if (secrets != null)
{
foreach (var secret in secrets.AsEnumerable())
{
contents[secret.Key] = secret.Value;
}
}

File.WriteAllText(secretsFilePath, contents.ToString(), Encoding.UTF8);
}


[Fact]
public void AddUserSecrets_Does_Not_Fail_On_Non_Existing_File_Explicitly_Passed()
Expand All @@ -36,10 +64,7 @@ public void AddUserSecrets_With_An_Existing_Secret_File()
string userSecretsId;
var projectPath = UserSecretHelper.GetTempSecretProject(out userSecretsId);

var logger = new TestLogger();
var secretManager = new Program() { Logger = logger };

secretManager.Run(new string[] { "set", "Facebook:AppSecret", "value1", "-p", projectPath });
SetSecret(userSecretsId, "Facebook:AppSecret", "value1");

var builder = new ConfigurationBuilder().SetBasePath(projectPath).AddUserSecrets();

Expand All @@ -55,10 +80,7 @@ public void AddUserSecrets_With_SecretsId_Passed_Explicitly()
string userSecretsId;
var projectPath = UserSecretHelper.GetTempSecretProject(out userSecretsId);

var logger = new TestLogger();
var secretManager = new Program() { Logger = logger };

secretManager.Run(new string[] { "set", "Facebook:AppSecret", "value1", "-p", projectPath });
SetSecret(userSecretsId, "Facebook:AppSecret", "value1");

var builder = new ConfigurationBuilder()
.AddUserSecrets(userSecretsId: userSecretsId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>ac7fad2a-5763-404d-b0fc-3cca81a16b0a</ProjectGuid>
<RootNamespace>Microsoft.Extensions.Configuration.UserSecrets.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

using System;
using System.IO;
using Microsoft.Extensions.Configuration.UserSecrets;
using Xunit;

namespace Microsoft.Extensions.SecretManager.Tests
namespace Microsoft.Extensions.Configuration.UserSecrets.Tests
{
public class PathHelperTests
{
Expand All @@ -20,7 +19,7 @@ public void Gives_Correct_Secret_Path()
var root = Environment.GetEnvironmentVariable("APPDATA") ?? // On Windows it goes to %APPDATA%\Microsoft\UserSecrets\
Environment.GetEnvironmentVariable("HOME"); // On Mac/Linux it goes to ~/.microsoft/usersecrets/

var expectedSecretPath = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPDATA"))?
var expectedSecretPath = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPDATA")) ?
Path.Combine(root, "Microsoft", "UserSecrets", userSecretsId, "secrets.json") :
Path.Combine(root, ".microsoft", "usersecrets", userSecretsId, "secrets.json");

Expand Down Expand Up @@ -70,7 +69,7 @@ public void Throws_If_UserSecretId_Contains_Invalid_Characters()
PathHelper.GetSecretsPath(projectPath);
});
}

UserSecretHelper.DeleteTempSecretProject(projectPath);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"buildOptions": {
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk"
"keyFile": "../../tools/Key.snk",
"compile": {
"include": "../Shared/*.cs"
}
},
"dependencies": {
"dotnet-test-xunit": "2.2.0-*",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-*",
"Microsoft.Extensions.Configuration.UserSecrets": "1.1.0-*",
"xunit": "2.2.0-*"
},
"testRunner": "xunit",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="14.0.25420" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.25420</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>113ebbd2-e857-4caf-9b53-7a8742cbcd4a</ProjectGuid>
<ProjectGuid>7b331122-83b1-4f08-a119-dc846959844c</ProjectGuid>
<RootNamespace>Microsoft.Extensions.SecretManager.Tools.Tests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
Expand All @@ -16,5 +17,5 @@
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Text;
using Microsoft.Extensions.Configuration.UserSecrets;
using Microsoft.Extensions.Configuration.UserSecrets.Tests;
using Microsoft.Extensions.SecretManager.Tools;
using Xunit;

Expand Down
29 changes: 29 additions & 0 deletions test/Microsoft.Extensions.SecretManager.Tools.Tests/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"buildOptions": {
"warningsAsErrors": true,
"keyFile": "../../tools/Key.snk",
"compile": {
"include": "../Shared/*.cs"
}
},
"dependencies": {
"dotnet-test-xunit": "2.2.0-*",
"Microsoft.Extensions.Configuration.UserSecrets": {
"version": "1.0.0",
"target": "package"
},
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-*",
"xunit": "2.2.0-*"
},
"testRunner": "xunit",
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
}
}
}
}
}
Loading