Skip to content

Commit

Permalink
Refactor GitHub context functions to remove sensitive token logging a…
Browse files Browse the repository at this point in the history
…nd clean up unused completer scripts
  • Loading branch information
MariusStorhaug committed Dec 9, 2024
1 parent 34b59ca commit ea767ad
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .github/linters/.powershell-psscriptanalyzer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
@{
#CustomRulePath='path\to\CustomRuleModule.psm1'
#RecurseCustomRulePath='path\of\customrules'
Severity = @(
'Error'
'Warning'
)
# Severity = @(
# 'Error'
# 'Warning'
# )
#IncludeDefaultRules=${true}
ExcludeRules = @(
'PSMissingModuleManifestField'
Expand Down
9 changes: 0 additions & 9 deletions src/completers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,3 @@
[System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', $_.Name)
}
}

Register-ArgumentCompleter -CommandName Set-GitHubConfig, Get-GitHubConfig, Remove-GitHubConfig -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter

([GitHubConfig]).GetProperties().Name | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_ )
}
}
File renamed without changes.
2 changes: 0 additions & 2 deletions src/functions/public/Auth/Context/Get-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ function Get-GitHubContext {
$contextObj = $_
Write-Verbose 'Context:'
$contextObj | Select-Object * | Out-String -Stream | ForEach-Object { Write-Verbose $_ }
Write-Verbose 'Token splatt:'
Write-Verbose ($contextObj.Token | ConvertFrom-SecureString -AsPlainText)

Write-Verbose "Converting to: [$($contextObj.Type)GitHubContext]"
switch ($contextObj.Type) {
Expand Down
9 changes: 0 additions & 9 deletions src/functions/public/Auth/Context/Set-GitHubContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ function Set-GitHubContext {
Write-Verbose 'Context:'
$Context | Out-String -Stream | ForEach-Object { Write-Verbose $_ }

Write-Verbose "Token splatt:"
Write-Verbose ($Context.Token | ConvertFrom-SecureString -AsPlainText)

# Run functions to get info on the temporary context.
try {
Write-Verbose "Getting info on the context [$($Context['AuthType'])]."
Expand Down Expand Up @@ -96,16 +93,10 @@ function Set-GitHubContext {
$Context | Out-String -Stream | ForEach-Object { Write-Verbose $_ }

if ($PSCmdlet.ShouldProcess('Context', 'Set')) {
Write-Verbose 'Token splatt:'
Write-Verbose ($Context.Token | ConvertFrom-SecureString -AsPlainText)
Set-Context -ID "$($script:GitHub.Config.ID)/$($Context['Name'])" -Context $Context
Write-Verbose 'Token splatt:'
Write-Verbose ($Context.Token | ConvertFrom-SecureString -AsPlainText)
if ($Default) {
Set-GitHubDefaultContext -Context $Context['Name']
if ($Context['AuthType'] -eq 'IAT' -and $script:GitHub.EnvironmentType -eq 'GHA') {
Write-Verbose "Token splatt:"
$Context.Token | ConvertFrom-SecureString -AsPlainText | ForEach-Object { Write-Verbose "Token: $_" }
Set-GitHubGitConfig -Context $Context['Name']
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
}

process {
Write-Verbose 'Token splatt:'
$Context.Token | ConvertFrom-SecureString -AsPlainText | ForEach-Object { Write-Verbose "Token: $_" }
if ($PSCmdlet.ShouldProcess("$Context", 'Set default context')) {
Set-GitHubConfig -Name 'DefaultContext' -Value $Context.Name
}
Expand Down
8 changes: 8 additions & 0 deletions src/functions/public/Config/completers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Register-ArgumentCompleter -CommandName Set-GitHubConfig, Get-GitHubConfig, Remove-GitHubConfig -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter

([GitHubConfig]).GetProperties().Name | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_ )
}
}
6 changes: 0 additions & 6 deletions src/functions/public/Git/Set-GitHubGitConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,9 @@
throw 'Git is not installed. Please install Git before running this command.'
}

Write-Verbose 'Token splatt:'
$Context.Token | ConvertFrom-SecureString -AsPlainText | ForEach-Object { Write-Verbose "Token: $_" }


$username = $Context.UserName
$id = $Context.DatabaseID
Write-Verbose "Context.Token: [$($Context.Token)]"
$token = $Context.Token | ConvertFrom-SecureString -AsPlainText
Write-Verbose "token: [$($token)]"
$hostName = $Context.HostName

if ($PSCmdlet.ShouldProcess("$Name", 'Set Git configuration')) {
Expand Down

0 comments on commit ea767ad

Please sign in to comment.