Skip to content

Commit 968d346

Browse files
committed
Upgraded extension for VS2019.
1 parent 1175152 commit 968d346

4 files changed

Lines changed: 32 additions & 304 deletions

File tree

SolutionSecrets2019/Commands/PullCommand.cs

Lines changed: 0 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -69,174 +69,6 @@ private async Task PullSecretsAsync()
6969
var solutionFullName = SolutionSecrets2019Package._dte.Solution.FullName;
7070

7171
await _pullCommand.Execute(solutionFullName);
72-
73-
/*
74-
SolutionFile solution = new SolutionFile(solutionFullName);
75-
76-
ICollection<SecretFile> secretFiles = solution.GetProjectsSecretFiles();
77-
if (secretFiles.Count == 0)
78-
{
79-
await UseStatusBarAsync("No secrets found.");
80-
return;
81-
}
82-
83-
var synchronizationSettings = solution.CustomSynchronizationSettings;
84-
85-
// Select the repository for the curront solution
86-
IRepository repository = Context.Current.GetRepository(synchronizationSettings) ?? Context.Current.Repository;
87-
88-
await UseStatusBarAsync($"Pulling secrets from {repository.RepositoryTypeFullName} for the solution: {solution.Name} ...");
89-
90-
if (repository is AzureKeyVaultRepository azureKvRepository)
91-
{
92-
if (!await azureKvRepository.IsReady())
93-
{
94-
try
95-
{
96-
await azureKvRepository.AuthorizeAsync();
97-
}
98-
catch (AuthenticationFailedException)
99-
{
100-
System.Windows.MessageBox.Show($"Azure authentication failed. Check your credential in\nTools -> Options -> Azure Service Authentication.", Vsix.Name, MessageBoxButton.OK, MessageBoxImage.Exclamation);
101-
await UseStatusBarAsync(String.Empty);
102-
return;
103-
}
104-
catch (Exception)
105-
{
106-
await UseStatusBarAsync("Error pulling secrets for the solution.");
107-
return;
108-
}
109-
}
110-
111-
if (!await azureKvRepository.IsReady())
112-
{
113-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
114-
System.Windows.MessageBox.Show($"Access denied to Azure Key Vault {azureKvRepository.RepositoryName}.", Vsix.Name, MessageBoxButton.OK, MessageBoxImage.Exclamation);
115-
commandService.OpenOption<Options.AzureKeyVault.AzureKeyVaultOptionPage>();
116-
await UseStatusBarAsync("Error pulling secrets for the solution.");
117-
return;
118-
}
119-
}
120-
else if (!await Context.Current.Cipher.IsReady() || !await repository.IsReady())
121-
{
122-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
123-
System.Windows.MessageBox.Show("You need to configure the solution secrets synchronization before using the Push command.", Vsix.Name, MessageBoxButton.OK, MessageBoxImage.Exclamation);
124-
commandService.OpenOption<Options.GitHubGists.GitHubGistsOptionPage>();
125-
await UseStatusBarAsync("Error pulling secrets for the solution.");
126-
return;
127-
}
128-
129-
130-
var repositoryFiles = await repository.PullFilesAsync(solution);
131-
if (repositoryFiles.Count == 0)
132-
{
133-
await UseStatusBarAsync("Failed, secrets not found.");
134-
return;
135-
}
136-
137-
// Validate header file
138-
HeaderFile header = null;
139-
foreach (var file in repositoryFiles)
140-
{
141-
if (file.name == "secrets" && file.content != null)
142-
{
143-
try
144-
{
145-
header = JsonConvert.DeserializeObject<HeaderFile>(file.content);
146-
}
147-
catch
148-
{ }
149-
break;
150-
}
151-
}
152-
153-
if (header == null)
154-
{
155-
await UseStatusBarAsync("Error pulling secrets for the solution.");
156-
return;
157-
}
158-
159-
if (!header.IsVersionSupported())
160-
{
161-
await UseStatusBarAsync("Secrets format is not compatible.");
162-
return;
163-
}
164-
165-
bool failed = false;
166-
foreach (var repositoryFile in repositoryFiles)
167-
{
168-
if (repositoryFile.name != "secrets")
169-
{
170-
if (repositoryFile.content == null)
171-
{
172-
continue;
173-
}
174-
175-
Dictionary<string, string> remoteSecretFiles = null;
176-
177-
try
178-
{
179-
remoteSecretFiles = JsonConvert.DeserializeObject<Dictionary<string, string>>(repositoryFile.content);
180-
}
181-
catch
182-
{
183-
await UseStatusBarAsync("Error pulling secrets for the solution.");
184-
}
185-
186-
if (remoteSecretFiles == null)
187-
{
188-
failed = true;
189-
break;
190-
}
191-
192-
foreach (var remoteSecretFile in remoteSecretFiles)
193-
{
194-
string secretFileName = remoteSecretFile.Key;
195-
196-
// This check is for compatibility with version 1.0.x
197-
if (secretFileName == "content")
198-
{
199-
secretFileName = "secrets.json";
200-
}
201-
202-
foreach (var localSecretFile in secretFiles)
203-
{
204-
if (localSecretFile.ContainerName == repositoryFile.name
205-
&& localSecretFile.Name == secretFileName)
206-
{
207-
localSecretFile.Content = remoteSecretFile.Value;
208-
209-
bool isFileOk = true;
210-
if (repository.EncryptOnClient)
211-
{
212-
isFileOk = localSecretFile.Decrypt();
213-
}
214-
215-
if (isFileOk)
216-
{
217-
solution.SaveSecretSettingsFile(localSecretFile);
218-
}
219-
else
220-
{
221-
failed = true;
222-
}
223-
break;
224-
}
225-
}
226-
}
227-
228-
if (failed)
229-
{
230-
break;
231-
}
232-
}
233-
}
234-
235-
if (!failed)
236-
await UseStatusBarAsync($"Secrets pulled successfully from {repository.RepositoryTypeFullName}.");
237-
else
238-
await UseStatusBarAsync("Secrets pull has failed!");
239-
*/
24072
}
24173

24274
}

SolutionSecrets2019/Commands/PushCommand.cs

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -69,127 +69,6 @@ private async Task PushSecretsAsync()
6969
var solutionFullName = SolutionSecrets2019Package._dte.Solution.FullName;
7070

7171
await _pushCommand.Execute(solutionFullName);
72-
73-
/*
74-
SolutionFile solution = new SolutionFile(solutionFullName);
75-
76-
var secretFiles = solution.GetProjectsSecretFiles();
77-
if (secretFiles.Count == 0)
78-
{
79-
await UseStatusBarAsync("No secrets found.");
80-
return;
81-
}
82-
83-
var synchronizationSettings = solution.CustomSynchronizationSettings;
84-
85-
// Select the repository for the curront solution
86-
IRepository repository = Context.Current.GetRepository(synchronizationSettings) ?? Context.Current.Repository;
87-
88-
await UseStatusBarAsync($"Pushing secrets to {repository.RepositoryTypeFullName} for the solution: {solution.Name} ...");
89-
90-
if (repository is AzureKeyVaultRepository azureKvRepository)
91-
{
92-
if (!await azureKvRepository.IsReady())
93-
{
94-
try
95-
{
96-
await azureKvRepository.AuthorizeAsync();
97-
}
98-
catch (AuthenticationFailedException ex)
99-
{
100-
System.Windows.MessageBox.Show(ex.Message, Vsix.Name, MessageBoxButton.OK, MessageBoxImage.Exclamation);
101-
await UseStatusBarAsync(String.Empty);
102-
return;
103-
}
104-
catch (Exception)
105-
{
106-
await UseStatusBarAsync("Error pushing secrets for the solution.");
107-
return;
108-
}
109-
}
110-
111-
if (!await azureKvRepository.IsReady())
112-
{
113-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
114-
System.Windows.MessageBox.Show($"Access denied to Azure Key Vault {azureKvRepository.RepositoryName}.", Vsix.Name, MessageBoxButton.OK, MessageBoxImage.Exclamation);
115-
commandService.OpenOption<Options.AzureKeyVault.AzureKeyVaultOptionPage>();
116-
await UseStatusBarAsync("Error pushing secrets for the solution.");
117-
return;
118-
}
119-
}
120-
else if (!await Context.Current.Cipher.IsReady() || !await repository.IsReady())
121-
{
122-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
123-
System.Windows.MessageBox.Show("You need to configure the solution secrets synchronization before using the Push command.", Vsix.Name, MessageBoxButton.OK, MessageBoxImage.Exclamation);
124-
commandService.OpenOption<Options.GitHubGists.GitHubGistsOptionPage>();
125-
await UseStatusBarAsync("Error pushing secrets for the solution.");
126-
return;
127-
}
128-
129-
var headerFile = new HeaderFile
130-
{
131-
visualStudioSolutionSecretsVersion = Versions.VersionString,
132-
lastUpload = DateTime.UtcNow,
133-
solutionFile = solution.Name,
134-
solutionGuid = solution.Uid
135-
};
136-
137-
var files = new List<(string fileName, string content)>
138-
{
139-
("secrets", JsonConvert.SerializeObject(headerFile, Formatting.None))
140-
};
141-
142-
var secrets = new Dictionary<string, Dictionary<string, string>>();
143-
144-
bool isEmpty = true;
145-
bool failed = false;
146-
foreach (var secretFile in secretFiles)
147-
{
148-
if (secretFile.Content != null)
149-
{
150-
isEmpty = false;
151-
bool isFileOk = true;
152-
153-
if (repository.EncryptOnClient)
154-
{
155-
isFileOk = secretFile.Encrypt();
156-
}
157-
158-
if (isFileOk)
159-
{
160-
if (!secrets.ContainsKey(secretFile.ContainerName))
161-
{
162-
secrets.Add(secretFile.ContainerName, new Dictionary<string, string>());
163-
}
164-
secrets[secretFile.ContainerName].Add(secretFile.Name, secretFile.Content);
165-
}
166-
else
167-
{
168-
failed = true;
169-
break;
170-
}
171-
}
172-
}
173-
174-
foreach (var group in secrets)
175-
{
176-
string groupContent = JsonConvert.SerializeObject(group.Value);
177-
files.Add((group.Key, groupContent));
178-
}
179-
180-
if (!isEmpty && !failed)
181-
{
182-
if (await repository.PushFilesAsync(solution, files))
183-
await UseStatusBarAsync($"Secrets pushed successfully to {repository.RepositoryTypeFullName}.");
184-
else
185-
failed = true;
186-
}
187-
188-
if (failed)
189-
{
190-
await UseStatusBarAsync("Secrets push has failed!");
191-
}
192-
*/
19372
}
19473

19574
}

SolutionSecrets2019/ConfigDialog.xaml.cs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,23 @@ private async void btnOk_Click(object sender, RoutedEventArgs e)
136136
if (cboxRepositoryType.SelectedIndex == AZURE_KV)
137137
{
138138
var repository = (AzureKeyVaultRepository)CoreContext.Current.GetService<IRepository>(nameof(RepositoryType.AzureKV));
139-
repository.RepositoryName = txtAKVUrl.Text;
140-
if (repository.RepositoryName == null)
139+
if (String.IsNullOrWhiteSpace(txtAKVUrl.Text))
141140
{
142-
System.Windows.MessageBox.Show("The key vault URL is not correct.", Constants.MESSAGE_BOX_TITLE, MessageBoxButton.OK);
143-
return;
141+
repository.RepositoryName = null;
144142
}
145-
else if (txtAKVUrl.Text != repository.RepositoryName)
143+
else
146144
{
147-
await _package.JoinableTaskFactory.SwitchToMainThreadAsync();
148-
txtAKVUrl.Text = repository.RepositoryName;
145+
repository.RepositoryName = txtAKVUrl.Text;
146+
if (repository.RepositoryName == null)
147+
{
148+
System.Windows.MessageBox.Show("The key vault URL is not correct.", Constants.MESSAGE_BOX_TITLE, MessageBoxButton.OK);
149+
return;
150+
}
151+
else if (txtAKVUrl.Text != repository.RepositoryName)
152+
{
153+
await _package.JoinableTaskFactory.SwitchToMainThreadAsync();
154+
txtAKVUrl.Text = repository.RepositoryName;
155+
}
149156
}
150157
}
151158

@@ -206,14 +213,24 @@ private async Task<bool> ConfigureSolutionAsync()
206213
return true;
207214
}
208215

209-
SyncConfiguration.SetCustomSynchronizationSettings(_solution.Uid, new SolutionSynchronizationSettings
216+
SolutionSynchronizationSettings solutionSettings = null;
217+
if (!String.IsNullOrWhiteSpace(txtAKVUrl.Text))
210218
{
211-
Repository = RepositoryType.AzureKV,
212-
AzureKeyVaultName = txtAKVUrl.Text
213-
});
219+
solutionSettings = new SolutionSynchronizationSettings
220+
{
221+
Repository = RepositoryType.AzureKV,
222+
AzureKeyVaultName = txtAKVUrl.Text
223+
};
224+
}
225+
226+
SyncConfiguration.SetCustomSynchronizationSettings(_solution.Uid, solutionSettings);
214227
SyncConfiguration.Save();
215228

216-
await UseStatusBarAsync($"Configured Azure Key Vault as the repository for the solution secrets.");
229+
if (solutionSettings != null)
230+
await UseStatusBarAsync($"Configured Azure Key Vault as the repository for the solution secrets.");
231+
else
232+
await UseStatusBarAsync($"Reverted solution to default settings for solution secrets.");
233+
217234
return true;
218235
}
219236
return false;

SolutionSecrets2019/source.extension.vsixmanifest

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="SolutionSecrets2019.4ee3c3b7-0e84-447d-9860-a2a08bb0f43a" Version="2.0.0" Language="en-US" Publisher="Ernesto Cianciotta" />
4+
<Identity Id="SolutionSecrets2019.4ee3c3b7-0e84-447d-9860-a2a08bb0f43a" Version="2.1.0" Language="en-US" Publisher="Ernesto Cianciotta" />
55
<DisplayName>Solution Secrets 2019</DisplayName>
66
<Description xml:space="preserve">This extension allows you to synchronize Visual Studio solution secrets across different development workstations.</Description>
77
<License>LICENSE</License>
@@ -14,11 +14,11 @@
1414
</Installation>
1515
<Dependencies>
1616
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
17-
</Dependencies>
17+
</Dependencies>
1818
<Prerequisites>
1919
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[16.0,17.0)" DisplayName="Visual Studio core editor" />
2020
</Prerequisites>
2121
<Assets>
2222
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
23-
</Assets>
23+
</Assets>
2424
</PackageManifest>

0 commit comments

Comments
 (0)