mirror of
https://github.com/omegaleo/SecretSecurity.git
synced 2026-11-09 01:53:31 +00:00
added uninstall and update commands
This commit is contained in:
@@ -39,6 +39,22 @@ secretsecurity install
|
|||||||
|
|
||||||
This writes a `pre-commit` hook to `.git/hooks/` that runs `secretsecurity scan` automatically on every commit.
|
This writes a `pre-commit` hook to `.git/hooks/` that runs `secretsecurity scan` automatically on every commit.
|
||||||
|
|
||||||
|
### Uninstall the pre-commit hook
|
||||||
|
|
||||||
|
```bash
|
||||||
|
secretsecurity uninstall
|
||||||
|
```
|
||||||
|
|
||||||
|
Removes the hook if it was installed by SecretSecurity. If the hook was created by something else, it is left untouched.
|
||||||
|
|
||||||
|
### Update
|
||||||
|
|
||||||
|
```bash
|
||||||
|
secretsecurity update
|
||||||
|
```
|
||||||
|
|
||||||
|
Updates the tool to the latest version via `dotnet tool update --global`.
|
||||||
|
|
||||||
### Scan manually
|
### Scan manually
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ class Program
|
|||||||
case "install":
|
case "install":
|
||||||
InstallCommand();
|
InstallCommand();
|
||||||
break;
|
break;
|
||||||
|
case "uninstall":
|
||||||
|
UninstallCommand();
|
||||||
|
break;
|
||||||
|
case "update":
|
||||||
|
UpdateCommand();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
PrintHelp();
|
PrintHelp();
|
||||||
break;
|
break;
|
||||||
@@ -59,7 +65,45 @@ fi
|
|||||||
|
|
||||||
File.WriteAllText(hookPath, script);
|
File.WriteAllText(hookPath, script);
|
||||||
|
|
||||||
Console.WriteLine("✅ SecretSecurity installed successfully");
|
// make the hook executable on Unix
|
||||||
|
if (!OperatingSystem.IsWindows())
|
||||||
|
RunProcess("chmod", $"+x \"{hookPath}\"");
|
||||||
|
|
||||||
|
AnsiConsole.MarkupLine("[green]✅ SecretSecurity hook installed successfully[/]");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UninstallCommand()
|
||||||
|
{
|
||||||
|
var root = RunGit("rev-parse --show-toplevel").Trim();
|
||||||
|
var hookPath = Path.Combine(root, ".git", "hooks", "pre-commit");
|
||||||
|
|
||||||
|
if (!File.Exists(hookPath))
|
||||||
|
{
|
||||||
|
AnsiConsole.MarkupLine("[yellow]No pre-commit hook found — nothing to uninstall.[/]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var content = File.ReadAllText(hookPath);
|
||||||
|
if (!content.Contains("SecretSecurity"))
|
||||||
|
{
|
||||||
|
AnsiConsole.MarkupLine("[yellow]Pre-commit hook exists but was not installed by SecretSecurity — leaving it untouched.[/]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File.Delete(hookPath);
|
||||||
|
AnsiConsole.MarkupLine("[green]✅ SecretSecurity hook removed successfully[/]");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateCommand()
|
||||||
|
{
|
||||||
|
AnsiConsole.MarkupLine("[cyan]Updating SecretSecurity...[/]");
|
||||||
|
|
||||||
|
var exitCode = RunProcess("dotnet", "tool update --global SecretSecurity");
|
||||||
|
|
||||||
|
if (exitCode == 0)
|
||||||
|
AnsiConsole.MarkupLine("[green]✅ SecretSecurity updated successfully[/]");
|
||||||
|
else
|
||||||
|
AnsiConsole.MarkupLine("[red]Update failed. Try running: dotnet tool update --global SecretSecurity[/]");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PrintHelp()
|
static void PrintHelp()
|
||||||
@@ -70,7 +114,8 @@ SecretSecurity CLI
|
|||||||
Commands:
|
Commands:
|
||||||
scan Scan staged git changes
|
scan Scan staged git changes
|
||||||
install Install git pre-commit hook
|
install Install git pre-commit hook
|
||||||
ignore Add ignore-rule
|
uninstall Remove the git pre-commit hook
|
||||||
|
update Update SecretSecurity to the latest version
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +146,7 @@ Commands:
|
|||||||
|
|
||||||
foreach (var f in critical)
|
foreach (var f in critical)
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine($"[red]• {f.Type}[/] in [grey]{f.File}:{f.Line}[/]");
|
AnsiConsole.MarkupLine($"[red]• {f.Type}[/] in [grey]{Markup.Escape(f.File)}:{f.Line}[/]");
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
@@ -134,8 +179,8 @@ Commands:
|
|||||||
|
|
||||||
AnsiConsole.MarkupLine($"""
|
AnsiConsole.MarkupLine($"""
|
||||||
[{color}]{f.Severity}[/]
|
[{color}]{f.Severity}[/]
|
||||||
📄 [bold]{f.File}:{f.Line}[/]
|
📄 [bold]{Markup.Escape(f.File)}:{f.Line}[/]
|
||||||
🔎 {f.ValuePreview}
|
🔎 {Markup.Escape(f.ValuePreview)}
|
||||||
|
|
||||||
────────────────────────────
|
────────────────────────────
|
||||||
""");
|
""");
|
||||||
@@ -225,18 +270,30 @@ Commands:
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string RunGit(string args)
|
public static string RunGit(string args) => RunProcessOutput("git", args);
|
||||||
|
|
||||||
|
static string RunProcessOutput(string fileName, string args)
|
||||||
{
|
{
|
||||||
var process = new Process();
|
var process = new Process();
|
||||||
process.StartInfo.FileName = "git";
|
process.StartInfo.FileName = fileName;
|
||||||
process.StartInfo.Arguments = args;
|
process.StartInfo.Arguments = args;
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
process.StartInfo.UseShellExecute = false;
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.Start();
|
process.Start();
|
||||||
|
|
||||||
return process.StandardOutput.ReadToEnd();
|
return process.StandardOutput.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int RunProcess(string fileName, string args)
|
||||||
|
{
|
||||||
|
var process = new Process();
|
||||||
|
process.StartInfo.FileName = fileName;
|
||||||
|
process.StartInfo.Arguments = args;
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.Start();
|
||||||
|
process.WaitForExit();
|
||||||
|
return process.ExitCode;
|
||||||
|
}
|
||||||
|
|
||||||
static bool IsIgnored(string file)
|
static bool IsIgnored(string file)
|
||||||
{
|
{
|
||||||
return _ignorePatterns.Any(p =>
|
return _ignorePatterns.Any(p =>
|
||||||
|
|||||||
@@ -12,8 +12,20 @@
|
|||||||
<Authors>Omega Leo</Authors>
|
<Authors>Omega Leo</Authors>
|
||||||
<Description>CLI tool for scanning secrets and sensitive data in files.</Description>
|
<Description>CLI tool for scanning secrets and sensitive data in files.</Description>
|
||||||
<RepositoryUrl>https://github.com/omegaleo/SecretSecurity</RepositoryUrl>
|
<RepositoryUrl>https://github.com/omegaleo/SecretSecurity</RepositoryUrl>
|
||||||
|
<Title>SecretSecurity - Git Secret Scanner</Title>
|
||||||
|
<RepositoryType>git</RepositoryType>
|
||||||
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
<PackageTags>security secrets scanner git precommit ci cd devops dotnet cli static-analysis sast code-analysis credentials api-key leak-detection</PackageTags>
|
||||||
|
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\README.md">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath>\</PackagePath>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Spectre.Console" Version="0.57.0" />
|
<PackageReference Include="Spectre.Console" Version="0.57.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user