-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates in hosting, spectre version, minor fixes
- Loading branch information
Showing
13 changed files
with
286 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,48 @@ | ||
ο»Ώusing System.ComponentModel; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Reflection; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
ο»Ώusing System.Diagnostics.CodeAnalysis; | ||
using devops.Internal; | ||
using Microsoft.AspNetCore.DataProtection; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.VisualStudio.Services.Common.CommandLine; | ||
using Spectre.Console; | ||
using Spectre.Console.Cli; | ||
|
||
namespace devops.Commands; | ||
|
||
public class InitCommand : Command<InitCommand.Settings> | ||
public class InitCommand( | ||
IAnsiConsole console, | ||
DevOpsConfigurationStore configStore, | ||
DevOpsConfigurationAccessor configurationAccessor) | ||
: Command<InitCommand.Settings> | ||
{ | ||
private readonly IAnsiConsole _console; | ||
|
||
private readonly DevOpsConfigurationProtector _protector; | ||
|
||
private readonly DevOpsConfigurationAccessor _configurationAccessor; | ||
|
||
public sealed class Settings : CommandSettings | ||
{ | ||
} | ||
|
||
public InitCommand(IAnsiConsole console, DevOpsConfigurationProtector protector, DevOpsConfigurationAccessor configurationAccessor) | ||
{ | ||
_console = console; | ||
_protector = protector; | ||
_configurationAccessor = configurationAccessor; | ||
} | ||
|
||
private void SaveConfiguration(DevOpsConfiguration config) | ||
{ | ||
var saveConfig = new DevOpsConfiguration() | ||
{ | ||
CollectionPAT = config.CollectionPAT, | ||
CollectionUri = config.CollectionUri | ||
}; | ||
|
||
_protector.Encrypt(saveConfig); | ||
|
||
var configAsJson = JsonSerializer.Serialize(config); | ||
var configFile = "{\"DevOps\":" + configAsJson + "\n}"; | ||
|
||
if (!Directory.Exists(Constants.SettingsDirectory)) | ||
{ | ||
Directory.CreateDirectory(Constants.SettingsDirectory); | ||
} | ||
|
||
var path = Constants.SettingsPath; | ||
File.WriteAllText(path, configFile); | ||
|
||
_console.WriteLine($"Updated encrypted devops settings at '${path}'."); | ||
} | ||
|
||
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings) | ||
{ | ||
|
||
|
||
_console.WriteLine("To connect to AzureDevops we'll need the url to your project collection and a PAT authorized to view it"); | ||
_console.WriteLine("Examples:"); | ||
_console.WriteLine("Url - https://mycompany.visualstudio.com/defaultcollection"); | ||
_console.WriteLine("PAT - apatfromazuredevopswhichisalongstringofcharacters"); | ||
_console.WriteLine(""); | ||
console.WriteLine( | ||
"To connect to AzureDevops we'll need the url to your project collection and a PAT authorized to view it"); | ||
console.WriteLine("Examples:"); | ||
console.WriteLine("Url - https://mycompany.visualstudio.com/defaultcollection"); | ||
console.WriteLine("PAT - apatfromazuredevopswhichisalongstringofcharacters"); | ||
console.WriteLine(""); | ||
|
||
var uri = _console.Ask<string>("Enter DevOps [green]Url[/] :"); | ||
var uri = console.Ask<string>("Enter DevOps [green]Url[/] :"); | ||
|
||
var pat = _console.Ask<string>("Enter DevOps [green]PAT[/] :"); | ||
var pat = console.Ask<string>("Enter DevOps [green]PAT[/] :"); | ||
|
||
var update = new DevOpsConfiguration | ||
{ | ||
CollectionUri = uri, | ||
CollectionPAT = pat | ||
}; | ||
|
||
_configurationAccessor.OverrideSettings(update); | ||
// Save it to disk | ||
configStore.SaveConfiguration(update, Constants.SettingsPath); | ||
|
||
|
||
SaveConfiguration(update); | ||
// Update the loaded settings | ||
configurationAccessor.UpdateSettings(update); | ||
|
||
_console.WriteLine(""); | ||
console.WriteLine($"Updated encrypted devops settings at '${Constants.SettingsPath}'."); | ||
console.WriteLine(""); | ||
|
||
return 0; | ||
} | ||
|
||
public sealed class Settings : CommandSettings | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.