Skip to content

Commit e011282

Browse files
author
Harri Klingsten
committed
Updated documentation.
1 parent 6c27eda commit e011282

File tree

5 files changed

+76
-143
lines changed

5 files changed

+76
-143
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ Read more about Power Commands: https://github.com/PowerCommands/PowerCommands20
5858

5959
Read more about SBOM: https://www.cisa.gov/sbom
6060

61-
## CycloneDX Generator
62-
<img src="cdxgen.png" alt="cdxgen" width="128">
61+
<img src="dt_cdxgen_logos.png" alt="Dependency Track logo" width="256">
6362

63+
## CycloneDX Generator
6464
[CycloneDX Generator](https://github.com/CycloneDX/cdxgen) on github.
6565

6666
## Dependency Track
67-
<img src="dt-logo.svg" alt="Dependency Track logo" width="256">
6867

6968
[Dependency Track](https://github.com/CycloneDX/cdxgen) on github.

cdxgen.png

-8.91 KB
Binary file not shown.

dt-logo.svg

Lines changed: 0 additions & 62 deletions
This file was deleted.

dt_cdxgen_logos.png

13.4 KB
Loading
Lines changed: 74 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,93 @@
11
using PainKiller.PowerCommands.Security.Services;
22

3-
namespace PainKiller.PowerCommands.Core.Commands
3+
namespace PainKiller.PowerCommands.Core.Commands;
4+
5+
[PowerCommandDesign(description: "Get, creates, removes or view secrets, first you need to configure your encryption key with initialize argument",
6+
options: "create|initialize|configuration|remove|salt",
7+
disableProxyOutput: true,
8+
example: "//View all declared secrets|secret|secret --create \"mycommand-pass\"|secret --remove \"mycommand-pass\"|//Initialize your machine with a new encryption key (stops if this is already done)|secret --initialize")]
9+
public class SecretCommand : CommandBase<CommandsConfiguration>
410
{
5-
[PowerCommandDesign(description: "Get, creates, removes or view secrets, first you need to configure your encryption key with initialize argument",
6-
options: "create|initialize|configuration|remove|salt",
7-
disableProxyOutput: true,
8-
example: "//View all declared secrets|secret|secret --create \"mycommand-pass\"|secret --remove \"mycommand-pass\"|//Initialize your machine with a new encryption key (stops if this is already done)|secret --initialize")]
9-
public class SecretCommand : CommandBase<CommandsConfiguration>
11+
public SecretCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
12+
public override RunResult Run()
1013
{
11-
public SecretCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
12-
public override RunResult Run()
13-
{
14-
if (Input.HasOption("initialize")) return Init();
15-
if (Input.HasOption("")) return CheckEncryptConfiguration();
16-
if (Input.HasOption("salt")) return Salt();
17-
if (Input.HasOption("create")) return Create();
18-
if (Input.HasOption("remove")) return Remove();
19-
if ((Input.Arguments.Length + Input.Quotes.Length < 2) && Input.Arguments.Length > 0) throw new MissingFieldException("Two parameters must be provided");
20-
if (Input.Arguments.Length == 0 || Input.Arguments[0] == "view") return List();
14+
if (Input.HasOption("initialize")) return Init();
15+
if (Input.HasOption("")) return CheckEncryptConfiguration();
16+
if (Input.HasOption("salt")) return Salt();
17+
if (Input.HasOption("create")) return Create();
18+
if (Input.HasOption("remove")) return Remove();
19+
if ((Input.Arguments.Length + Input.Quotes.Length < 2) && Input.Arguments.Length > 0) throw new MissingFieldException("Two parameters must be provided");
20+
if (Input.Arguments.Length == 0 || Input.Arguments[0] == "view") return List();
2121

22-
return BadParameterError("No matching parameter");
23-
}
24-
private RunResult CheckEncryptConfiguration()
22+
return BadParameterError("No matching parameter");
23+
}
24+
private RunResult CheckEncryptConfiguration()
25+
{
26+
try
2527
{
26-
try
27-
{
28-
var encryptedString = EncryptionService.Service.EncryptString("Encryption is setup properly");
29-
var decryptedString = EncryptionService.Service.DecryptString(encryptedString);
30-
WriteLine(encryptedString);
31-
WriteLine(decryptedString);
32-
}
33-
catch
34-
{
35-
Console.WriteLine("");
36-
WriteError("Encryption is not configured properly");
37-
}
38-
return Ok();
28+
var encryptedString = EncryptionService.Service.EncryptString("Encryption is setup properly");
29+
var decryptedString = EncryptionService.Service.DecryptString(encryptedString);
30+
WriteLine(encryptedString);
31+
WriteLine(decryptedString);
3932
}
40-
private RunResult Salt()
33+
catch
4134
{
42-
Console.WriteLine(IEncryptionService.GetRandomSalt());
43-
return Ok();
35+
Console.WriteLine("");
36+
WriteError("Encryption is not configured properly");
4437
}
38+
return Ok();
39+
}
40+
private RunResult Salt()
41+
{
42+
Console.WriteLine(IEncryptionService.GetRandomSalt());
43+
return Ok();
44+
}
4545

46-
private RunResult Init()
47-
{
48-
var firstHalf = IEncryptionService.GetRandomSalt(); ;
49-
var secondHalf = IEncryptionService.GetRandomSalt(); ;
50-
Environment.SetEnvironmentVariable("_encryptionManager", firstHalf, EnvironmentVariableTarget.User);
51-
var securityConfig = new SecurityConfiguration { Encryption = new EncryptionConfiguration { SharedSecretEnvironmentKey = "_encryptionManager", SharedSecretSalt = secondHalf } };
52-
var fileName = Path.Combine(ConfigurationGlobals.ApplicationDataFolder, ConfigurationGlobals.SecurityFileName);
53-
ConfigurationService.Service.Create(securityConfig, fileName);
54-
WriteSuccessLine($"File {fileName} saved OK, you will need to restart the application before the changes take effect.");
55-
return Ok();
56-
}
46+
private RunResult Init()
47+
{
48+
var firstHalf = IEncryptionService.GetRandomSalt();
49+
var secondHalf = IEncryptionService.GetRandomSalt();
50+
Environment.SetEnvironmentVariable("_encryptionManager", firstHalf, EnvironmentVariableTarget.User);
51+
var securityConfig = new SecurityConfiguration { Encryption = new EncryptionConfiguration { SharedSecretEnvironmentKey = "_encryptionManager", SharedSecretSalt = secondHalf } };
52+
var fileName = Path.Combine(ConfigurationGlobals.ApplicationDataFolder, ConfigurationGlobals.SecurityFileName);
53+
ConfigurationService.Service.Create(securityConfig, fileName);
54+
WriteSuccessLine($"File {fileName} saved OK, you will need to restart the application before the changes take effect.");
55+
return Ok();
56+
}
5757

58-
private RunResult List()
59-
{
60-
if (Configuration.Secret.Secrets == null) return Ok();
61-
foreach (var secret in Configuration.Secret.Secrets) ConsoleService.Service.WriteObjectDescription($"{GetType().Name}", secret.Name, $"{string.Join(',', secret.Options.Keys)}");
62-
return Ok();
63-
}
64-
private RunResult Create()
65-
{
66-
var name = Input.SingleQuote;
67-
var password = DialogService.SecretPromptDialog("Enter secret:");
68-
if (string.IsNullOrEmpty(password)) return BadParameterError("Passwords do not match");
58+
private RunResult List()
59+
{
60+
foreach (var secret in Configuration.Secret.Secrets) ConsoleService.Service.WriteObjectDescription($"{GetType().Name}", secret.Name, $"{string.Join(',', secret.Options.Keys)}");
61+
return Ok();
62+
}
63+
private RunResult Create()
64+
{
65+
var name = Input.SingleQuote;
66+
var password = DialogService.SecretPromptDialog("Enter secret:");
67+
if (string.IsNullOrEmpty(password)) return BadParameterError("Passwords do not match");
6968

70-
var secret = new SecretItemConfiguration { Name = name };
71-
var val = SecretService.Service.SetSecret(name, password, secret.Options, EncryptionService.Service.EncryptString);
69+
var secret = new SecretItemConfiguration { Name = name };
70+
var val = SecretService.Service.SetSecret(name, password, secret.Options, EncryptionService.Service.EncryptString);
7271

73-
Configuration.Secret ??= new();
74-
Configuration.Secret.Secrets ??= new();
75-
Configuration.Secret.Secrets.Add(secret);
76-
ConfigurationService.Service.SaveChanges(Configuration);
77-
Console.WriteLine();
78-
WriteHeadLine("New secret created and stored in configuration file");
79-
ConsoleService.Service.WriteObjectDescription($"{GetType().Name}", name, val);
72+
Configuration.Secret.Secrets.Add(secret);
73+
ConfigurationService.Service.SaveChanges(Configuration);
74+
Console.WriteLine();
75+
WriteHeadLine("New secret created and stored in configuration file");
76+
ConsoleService.Service.WriteObjectDescription($"{GetType().Name}", name, val);
8077

81-
return Ok();
82-
}
83-
private RunResult Remove()
84-
{
85-
var name = Input.SingleQuote;
78+
return Ok();
79+
}
80+
private RunResult Remove()
81+
{
82+
var name = Input.SingleQuote;
8683

87-
var secret = Configuration.Secret.Secrets.FirstOrDefault(s => s.Name.ToLower() == name.ToLower());
88-
if (secret == null) return BadParameterError($"No secret with name \"{name}\" found.");
84+
var secret = Configuration.Secret.Secrets.FirstOrDefault(s => s.Name.ToLower() == name.ToLower());
85+
if (secret == null) return BadParameterError($"No secret with name \"{name}\" found.");
8986

90-
Configuration.Secret.Secrets.Remove(secret);
91-
ConfigurationService.Service.SaveChanges(Configuration);
87+
Configuration.Secret.Secrets.Remove(secret);
88+
ConfigurationService.Service.SaveChanges(Configuration);
9289

93-
WriteHeadLine("Secret removed from configuration file\nManually remove the secret key from environment variables or vault depending on how they are stored.");
94-
return Ok();
95-
}
90+
WriteHeadLine("Secret removed from configuration file\nManually remove the secret key from environment variables or vault depending on how they are stored.");
91+
return Ok();
9692
}
9793
}

0 commit comments

Comments
 (0)