Skip to content

Commit 496ffd3

Browse files
committed
Rework token generation
1 parent ca36179 commit 496ffd3

File tree

3 files changed

+8
-68
lines changed

3 files changed

+8
-68
lines changed

hugoalh.GitHubActionsToolkit/module/command-file.psm1

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#Requires -PSEdition Core -Version 7.2
2-
Import-Module -Name @(
3-
(Join-Path -Path $PSScriptRoot -ChildPath 'internal\token.psm1')
4-
) -Prefix 'GitHubActions' -Scope 'Local'
52
<#
63
.SYNOPSIS
74
GitHub Actions - Internal - Add File Command
@@ -28,7 +25,7 @@ Function Add-FileCommand {
2825
}
2926
Else {
3027
Do {
31-
[String]$Token = New-GitHubActionsRandomToken
28+
[String]$Token = (New-Guid).Guid.ToLower() -ireplace '-', ''
3229
[String]$TokenRegExEscape = [RegEx]::Escape($Token)
3330
}
3431
While ($Name -imatch $TokenRegExEscape -or $Value -imatch $TokenRegExEscape)

hugoalh.GitHubActionsToolkit/module/command-stdout.psm1

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#Requires -PSEdition Core -Version 7.2
2-
Import-Module -Name @(
3-
(Join-Path -Path $PSScriptRoot -ChildPath 'internal\token.psm1')
4-
) -Prefix 'GitHubActions' -Scope 'Local'
52
[String[]]$StdOutCommandsType = @(
63
'add-mask',
74
'add-matcher',
@@ -19,7 +16,6 @@ Import-Module -Name @(
1916
'stop-commands',
2017
'warning'
2118
)
22-
[String[]]$StdOutCommandTokensUsed = @()
2319
<#
2420
.SYNOPSIS
2521
GitHub Actions - Disable StdOut Command Echo
@@ -51,15 +47,11 @@ Function Disable-StdOutCommandProcess {
5147
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_disablegithubactionsstdoutcommandprocess')]
5248
[OutputType([String])]
5349
Param (
54-
[Parameter(Position = 0)][ValidateScript({ Test-StdOutCommandToken -InputObject $_ }, ErrorMessage = 'Value is not a single line string, more than or equal to 4 characters, and not match any GitHub Actions commands!')][Alias('EndKey', 'EndValue', 'Key', 'Token', 'Value')][String]$EndToken
50+
[Parameter(Position = 0)][ValidateScript({ Test-StdOutCommandEndToken -InputObject $_ }, ErrorMessage = 'Value is not a single line string, more than or equal to 4 characters, and not match any GitHub Actions commands!')][Alias('EndKey', 'EndValue', 'Key', 'Token', 'Value')][String]$EndToken
5551
)
5652
If ($EndToken.Length -eq 0) {
57-
Do {
58-
$EndToken = New-GitHubActionsRandomToken -NoUpperCase
59-
}
60-
While ($EndToken -iin $Script:StdOutCommandTokensUsed)
53+
$EndToken = (New-Guid).Guid.ToLower() -ireplace '-', ''
6154
}
62-
$Script:StdOutCommandTokensUsed += $EndToken
6355
Write-GitHubActionsStdOutCommand -StdOutCommand 'stop-commands' -Value $EndToken
6456
$EndToken |
6557
Write-Output
@@ -100,7 +92,7 @@ Function Enable-StdOutCommandProcess {
10092
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_enablegithubactionsstdoutcommandprocess')]
10193
[OutputType([Void])]
10294
Param (
103-
[Parameter(Mandatory = $True, Position = 0)][ValidateScript({ Test-StdOutCommandToken -InputObject $_ }, ErrorMessage = 'Value is not a single line string, more than or equal to 4 characters, and not match any GitHub Actions commands!')][Alias('EndKey', 'EndValue', 'Key', 'Token', 'Value')][String]$EndToken
95+
[Parameter(Mandatory = $True, Position = 0)][ValidateScript({ Test-StdOutCommandEndToken -InputObject $_ }, ErrorMessage = 'Value is not a single line string, more than or equal to 4 characters, and not match any GitHub Actions commands!')][Alias('EndKey', 'EndValue', 'Key', 'Token', 'Value')][String]$EndToken
10496
)
10597
Write-GitHubActionsStdOutCommand -StdOutCommand $EndToken
10698
}
@@ -145,15 +137,15 @@ Function Format-StdOutCommandParameterValue {
145137
}
146138
<#
147139
.SYNOPSIS
148-
GitHub Actions - Internal - Test StdOut Command Token
140+
GitHub Actions - Internal - Test StdOut Command End Token
149141
.DESCRIPTION
150-
Test the GitHub Actions stdout command token whether is valid.
142+
Test whether is a valid GitHub Actions stdout command end token.
151143
.PARAMETER InputObject
152-
GitHub Actions stdout command token that need to test.
144+
GitHub Actions stdout command end token that need to test.
153145
.OUTPUTS
154146
[Boolean] Test result.
155147
#>
156-
Function Test-StdOutCommandToken {
148+
Function Test-StdOutCommandEndToken {
157149
[OutputType([Boolean])]
158150
Param (
159151
[Parameter(Mandatory = $True, Position = 0)][Alias('EndKey', 'EndValue', 'Input', 'Key', 'Object', 'Token', 'Value')][String]$InputObject

hugoalh.GitHubActionsToolkit/module/internal/token.psm1

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

0 commit comments

Comments
 (0)