diff --git a/.github/workflows/Nightly-Run.yml b/.github/workflows/Nightly-Run.yml index c25d80630..4469a9064 100644 --- a/.github/workflows/Nightly-Run.yml +++ b/.github/workflows/Nightly-Run.yml @@ -10,6 +10,12 @@ permissions: pull-requests: write statuses: write +env: + TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }} + TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }} + TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }} + TEST_PAT: ${{ secrets.TEST_PAT }} + jobs: Process-PSModule: uses: PSModule/Process-PSModule/.github/workflows/CI.yml@v3 diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml index f6ed58e7d..9110efba6 100644 --- a/.github/workflows/Process-PSModule.yml +++ b/.github/workflows/Process-PSModule.yml @@ -24,6 +24,12 @@ permissions: pages: write id-token: write +env: + TEST_APP_CLIENT_ID: ${{ secrets.TEST_APP_CLIENT_ID }} + TEST_APP_PRIVATE_KEY: ${{ secrets.TEST_APP_PRIVATE_KEY }} + TEST_FG_PAT: ${{ secrets.TEST_FG_PAT }} + TEST_PAT: ${{ secrets.TEST_PAT }} + jobs: Process-PSModule: uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@v3 diff --git a/src/classes/public/GitHubContext.ps1 b/src/classes/public/GitHubContext.ps1 new file mode 100644 index 000000000..550923125 --- /dev/null +++ b/src/classes/public/GitHubContext.ps1 @@ -0,0 +1,86 @@ +class GitHubContext { + # The API base URI. + # https://api.github.com + [string] $ApiBaseUri + + # The GitHub API version. + # 2022-11-28 + [string] $ApiVersion + + # The authentication client ID. + # Client ID for UAT + [string] $AuthClientID + + # The authentication type. + # UAT / PAT / App / IAT + [string] $AuthType + + # Client ID for GitHub Apps + [string] $ClientID + + # The device flow type. + # GitHubApp / OAuthApp + [string] $DeviceFlowType + + # The API hostname. + # github.com / msx.ghe.com / github.local + [string] $HostName + + # User ID / App ID as GraphQL Node ID + [string] $NodeID + + # The Database ID of the context. + [string] $DatabaseID + + # The context ID. + # HostName/Username or HostName/AppSlug + # Context:PSModule.Github/github.com/Octocat + [string] $ID + + # The user name. + [string] $UserName + + # The default value for the Owner parameter. + [string] $Owner + + # The default value for the Repo parameter. + [string] $Repo + + # The scope when authenticating with OAuth. + # 'gist read:org repo workflow' + [string] $Scope + + # The token type. + # ghu / gho / ghp / github_pat / PEM / ghs / + [string] $TokenType + + # The access token. + [securestring] $Token + + # The token expiration date. + # 2024-01-01-00:00:00 + [datetime] $TokenExpirationDate + + # The refresh token. + [securestring] $RefreshToken + + # The refresh token expiration date. + # 2024-01-01-00:00:00 + [datetime] $RefreshTokenExpirationDate + + GitHubContext([string]$ID) { + $this.ID = $ID + } + + GitHubContext([hashtable]$Properties) { + foreach ($Property in $Properties.Keys) { + $this.$Property = $Properties.$Property + } + } + + GitHubContext([PSCustomObject]$Object) { + $Object.PSObject.Properties | ForEach-Object { + $this.($_.Name) = $_.Value + } + } +} diff --git a/src/formats/GitHubContext.Format.ps1xml b/src/formats/GitHubContext.Format.ps1xml new file mode 100644 index 000000000..14fef32a3 --- /dev/null +++ b/src/formats/GitHubContext.Format.ps1xml @@ -0,0 +1,131 @@ + + + + + + GitHubContextTableView + + GitHubContext + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + UserName + + + HostName + + + AuthType + + + TokenType + + + TokenExpirationDate + + + Owner + + + Repo + + + + + + + + + + GitHubContextListView + + GitHubContext + + + + + + + HostName + + + UserName + + + AuthType + + + TokenType + + + TokenExpirationDate + + + Repo + + + Scope + + + ApiBaseUri + + + ApiVersion + + + AuthClientID + + + ClientID + + + DeviceFlowType + + + NodeID + + + DatabaseID + + + ID + + + Owner + + + RefreshTokenExpirationDate + + + + + + + + diff --git a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 index 850bacdd1..671a1a8ff 100644 --- a/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 +++ b/src/functions/private/Auth/DeviceFlow/Test-GitHubAccessTokenRefreshRequired.ps1 @@ -13,15 +13,13 @@ #> [OutputType([bool])] [CmdletBinding()] - param() + param( + [Parameter()] + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') + ) - $tokenType = Get-GitHubConfig -Name 'SecretType' -ErrorAction SilentlyContinue - if ($tokenType -ne 'ghu_*') { - Write-Verbose 'The access token is not a user token. No need to refresh.' - return $false - } - - $tokenExpirationDate = Get-GitHubConfig -Name 'SecretExpirationDate' -ErrorAction SilentlyContinue + $contextObj = Get-GitHubContext -Context $Context + $tokenExpirationDate = $contextObj.TokenExpirationDate $currentDateTime = Get-Date $remainingDuration = [datetime]$tokenExpirationDate - $currentDateTime diff --git a/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 b/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 index b3db1c4c2..73a2912ed 100644 --- a/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 +++ b/src/functions/private/License/Get-GitHubRepositoryLicense.ps1 @@ -22,25 +22,23 @@ filter Get-GitHubRepositoryLicense { param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) - process { - $inputObject = @{ - APIEndpoint = "/repos/$Owner/$Repo/license" - Accept = 'application/vnd.github+json' - Method = 'GET' - } - - Invoke-GitHubAPI @inputObject | ForEach-Object { - $Response = $_.Response - $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) - $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force - $Response - } + $inputObject = @{ + APIEndpoint = "/repos/$Owner/$Repo/license" + Accept = 'application/vnd.github+json' + Method = 'GET' + } + + Invoke-GitHubAPI @inputObject | ForEach-Object { + $Response = $_.Response + $rawContent = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Response.content)) + $Response | Add-Member -NotePropertyName 'raw_content' -NotePropertyValue $rawContent -Force + $Response } } diff --git a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 index 1ec06269f..e7387d5f8 100644 --- a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 +++ b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByID.ps1 @@ -22,11 +22,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the asset. [Parameter(Mandatory)] diff --git a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 index cb3ac0b0d..ea8dd0bdf 100644 --- a/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 +++ b/src/functions/private/Releases/Assets/Get-GitHubReleaseAssetByReleaseID.ps1 @@ -19,11 +19,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter( diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 index 7ebd6982c..2ed5b0145 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseAll.ps1 @@ -21,11 +21,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter(ParameterSetName = 'AllUsers')] diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 index 34cf612a4..ae2cab2e6 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseByID.ps1 @@ -20,11 +20,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter( diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 index 4ed7ccf35..db6b659f0 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseByTagName.ps1 @@ -19,11 +19,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the tag to get a release from. [Parameter( diff --git a/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 b/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 index 8cc417614..013a812ca 100644 --- a/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 +++ b/src/functions/private/Releases/Releases/Get-GitHubReleaseLatest.ps1 @@ -21,11 +21,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) diff --git a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 index b77396a33..cdff8e230 100644 --- a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 +++ b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkById.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the autolink. [Parameter(Mandatory)] diff --git a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 index c3a49359e..3edebc52c 100644 --- a/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 +++ b/src/functions/private/Repositories/Autolinks/Get-GitHubRepositoryAutolinkList.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 index a37e81f12..b7f6c6422 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryByName.ps1 @@ -24,11 +24,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) diff --git a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 index d6666f478..9e2f108a2 100644 --- a/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 +++ b/src/functions/private/Repositories/Repositories/Get-GitHubRepositoryListByOrg.ps1 @@ -33,7 +33,7 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # Specifies the types of repositories you want returned. [Parameter()] diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 index b7b240a0c..e5a59dbcb 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryFromTemplate.ps1 @@ -52,7 +52,7 @@ # To create a new repository in an organization, the authenticated user must be a member of the specified organization. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the new repository. [Parameter(Mandatory)] diff --git a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 index fef14ccf1..1f8c969c2 100644 --- a/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 +++ b/src/functions/private/Repositories/Repositories/New-GitHubRepositoryOrg.ps1 @@ -64,7 +64,7 @@ filter New-GitHubRepositoryOrg { # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository. [Parameter(Mandatory)] diff --git a/src/functions/public/API/Invoke-GitHubAPI.ps1 b/src/functions/public/API/Invoke-GitHubAPI.ps1 index fe7801ac4..7597193f5 100644 --- a/src/functions/public/API/Invoke-GitHubAPI.ps1 +++ b/src/functions/public/API/Invoke-GitHubAPI.ps1 @@ -32,7 +32,7 @@ [Parameter( ParameterSetName = 'ApiEndpoint' )] - [string] $ApiBaseUri = (Get-GitHubConfig -Name ApiBaseUri), + [string] $ApiBaseUri, # The specific endpoint for the API call, e.g., '/repos/user/repo/pulls'. [Parameter( @@ -74,7 +74,7 @@ # The secure token used for authentication in the GitHub API. It should be stored as a SecureString to ensure it's kept safe in memory. [Parameter()] - [SecureString] $Token = (Get-GitHubConfig -Name Secret), + [SecureString] $Token, # The 'Content-Type' header for the API request. The default is 'application/vnd.github+json'. [Parameter()] @@ -82,18 +82,61 @@ # The GitHub API version to be used. By default, it pulls from a configuration script variable. [Parameter()] - [string] $Version = (Get-GitHubConfig -Name ApiVersion) + [string] $ApiVersion, + + # The context to use for the API call. This is used to retrieve the necessary configuration settings. + [Parameter()] + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) - $secretType = (Get-GitHubConfig -Name SecretType) - switch ($secretType) { + + Write-Verbose 'Invoking GitHub API...' + $PSBoundParameters.GetEnumerator() | ForEach-Object { + Write-Verbose " - $($_.Key): $($_.Value)" + } + + $contextObj = Get-GitHubContext -Name $Context + Write-Verbose "Using GitHub context: $Context" + if (-not $contextObj) { + throw 'Log in using Connect-GitHub before running this command.' + } + + if ([string]::IsNullOrEmpty($ApiBaseUri)) { + Write-Verbose 'Using default API base URI from context.' + Write-Verbose $($contextObj.ApiBaseUri) + $ApiBaseUri = $contextObj.ApiBaseUri + } + Write-Verbose "ApiBaseUri: $ApiBaseUri" + + if ([string]::IsNullOrEmpty($ApiVersion)) { + Write-Verbose 'Using default API version from context.' + Write-Verbose $($contextObj.ApiVersion) + $ApiVersion = $contextObj.ApiVersion + } + Write-Verbose "ApiVersion: $ApiVersion" + + if ([string]::IsNullOrEmpty($TokenType)) { + Write-Verbose 'Using default token type from context.' + Write-Verbose $($contextObj.TokenType) + $TokenType = $contextObj.TokenType + } + Write-Verbose "TokenType: $TokenType" + + if ([string]::IsNullOrEmpty($Token)) { + Write-Verbose 'Using default token from context.' + Write-Verbose $($contextObj.Token) + $Token = $contextObj.Token + } + Write-Verbose "Token: $Token" + + switch ($tokenType) { 'ghu' { if (Test-GitHubAccessTokenRefreshRequired) { Connect-GitHubAccount -Silent - $Token = (Get-GitHubConfig -Name Secret) + $Token = (Get-GitHubContextSetting -Name 'Token' -Context $Context) } } 'PEM' { - $ClientID = Get-GithubConfig -Name ClientID + $ClientID = (Get-GitHubContextSetting -Name 'ClientID' -Context $Context) $JWT = Get-GitHubAppJSONWebToken -ClientId $ClientID -PrivateKey $Token $Token = $JWT.Token } @@ -102,7 +145,7 @@ $headers = @{ Accept = $Accept - 'X-GitHub-Api-Version' = $Version + 'X-GitHub-Api-Version' = $ApiVersion } Remove-HashtableEntry -Hashtable $headers -NullOrEmptyValues @@ -146,7 +189,7 @@ } try { - Write-Verbose "Calling GitHub API with the following parameters:" + Write-Verbose 'Calling GitHub API with the following parameters:' Write-Verbose ($APICall | ConvertFrom-HashTable | Format-List | Out-String) Invoke-RestMethod @APICall | ForEach-Object { $statusCode = $APICallStatusCode | ConvertTo-Json -Depth 100 | ConvertFrom-Json diff --git a/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 b/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 index 9fe267110..ded382b88 100644 --- a/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Disable-GitHubWorkflow.ps1 @@ -6,10 +6,10 @@ [CmdletBinding()] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Parameter( Mandatory, diff --git a/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 b/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 index 9a577fe53..a18258708 100644 --- a/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Enable-GitHubWorkflow.ps1 @@ -6,10 +6,10 @@ [CmdletBinding()] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Parameter( Mandatory, diff --git a/src/functions/public/Actions/Get-GitHubWorkflow.ps1 b/src/functions/public/Actions/Get-GitHubWorkflow.ps1 index 9d7579a07..657690ec8 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Get-GitHubWorkflow.ps1 @@ -24,10 +24,10 @@ [CmdletBinding(DefaultParameterSetName = 'ByName')] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 index e822d26bc..60af3bb19 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Get-GitHubWorkflowRun.ps1 @@ -8,10 +8,10 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidLongLines', '', Justification = 'Contains a long link.')] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Parameter(ParameterSetName = 'ByName')] [string] $Name, diff --git a/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 b/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 index 6f569924f..1bcdec709 100644 --- a/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 +++ b/src/functions/public/Actions/Get-GitHubWorkflowUsage.ps1 @@ -26,10 +26,10 @@ )] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Parameter( Mandatory, diff --git a/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 index b76928c96..723e8d809 100644 --- a/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Remove-GitHubWorkflowRun.ps1 @@ -20,11 +20,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the workflow run. [Parameter( diff --git a/src/functions/public/Actions/Start-GitHubWorkflow.ps1 b/src/functions/public/Actions/Start-GitHubWorkflow.ps1 index ccef74f94..1a50ddb7c 100644 --- a/src/functions/public/Actions/Start-GitHubWorkflow.ps1 +++ b/src/functions/public/Actions/Start-GitHubWorkflow.ps1 @@ -21,11 +21,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The ID of the workflow. [Alias('workflow_id')] diff --git a/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 b/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 index f9e95b180..f4dc66dc3 100644 --- a/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 +++ b/src/functions/public/Actions/Start-GitHubWorkflowReRun.ps1 @@ -16,11 +16,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the workflow run. [Alias('workflow_id')] diff --git a/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 b/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 index 0d42b6a83..181293df4 100644 --- a/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 +++ b/src/functions/public/Actions/Stop-GitHubWorkflowRun.ps1 @@ -18,10 +18,10 @@ [alias('Cancel-GitHubWorkflowRun')] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), [Alias('workflow_id')] [Parameter( diff --git a/src/functions/public/Apps/Get-GitHubApp.ps1 b/src/functions/public/Apps/Get-GitHubApp.ps1 index 24d97b633..ae61fe13c 100644 --- a/src/functions/public/Apps/Get-GitHubApp.ps1 +++ b/src/functions/public/Apps/Get-GitHubApp.ps1 @@ -22,9 +22,13 @@ #> [OutputType([pscustomobject])] [CmdletBinding()] - param() + param( + # The context to run the command in. + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') + ) $inputObject = @{ + Context = $Context APIEndpoint = '/app' Method = 'GET' } diff --git a/src/functions/public/Auth/Connect-GitHubAccount.ps1 b/src/functions/public/Auth/Connect-GitHubAccount.ps1 index 7694381d5..040919f85 100644 --- a/src/functions/public/Auth/Connect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Connect-GitHubAccount.ps1 @@ -32,7 +32,7 @@ Connect-GitHubAccount -UseAccessToken ! Enter your personal access token: ************* - User gets prompted for the access token and stores it in the secret store. + User gets prompted for the access token and stores it in the context. The token is used when connecting to GitHub. .EXAMPLE @@ -132,6 +132,10 @@ [Alias('s')] [switch] $Silent ) + + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + try { if ($Token -is [System.Security.SecureString]) { $Token = ConvertFrom-SecureString $Token -AsPlainText @@ -143,7 +147,7 @@ $tokenPrefixPattern = '(?<=^(ghu|gho|ghs|github_pat|ghp)).*' # If running on GitHub Actions and no access token is provided, use the GitHub token. - if ($env:GITHUB_ACTIONS -eq 'true') { + if (($env:GITHUB_ACTIONS -eq 'true') -and $PSCmdlet.ParameterSetName -ne 'App') { $tokenNotProvided = [string]::IsNullOrEmpty($Token) $gitHubToken = $env:GH_TOKEN ?? $env:GITHUB_TOKEN $gitHubTokenPresent = -not [string]::IsNullOrEmpty($gitHubToken) @@ -156,7 +160,6 @@ } $context = @{ - Name = 'tmp' ApiBaseUri = $ApiBaseUri ApiVersion = $ApiVersion HostName = $HostName @@ -183,7 +186,7 @@ Write-Verbose "Using $Mode authentication..." $tokenResponse = Invoke-GitHubDeviceFlowLogin -ClientID $authClientID -Scope $Scope -HostName $HostName } else { - $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'SecretExpirationDate') - (Get-Date) + $accessTokenValidity = [datetime](Get-GitHubConfig -Name 'TokenExpirationDate') - (Get-Date) $accessTokenIsValid = $accessTokenValidity.Seconds -gt 0 $hours = $accessTokenValidity.Hours.ToString().PadLeft(2, '0') $minutes = $accessTokenValidity.Minutes.ToString().PadLeft(2, '0') @@ -221,9 +224,9 @@ switch ($Mode) { 'GitHubApp' { $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token - SecretExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) - SecretType = $tokenResponse.access_token -replace $tokenPrefixPattern + Token = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token + TokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) + TokenType = $tokenResponse.access_token -replace $tokenPrefixPattern AuthClientID = $authClientID DeviceFlowType = $Mode RefreshToken = ConvertTo-SecureString -AsPlainText $tokenResponse.refresh_token @@ -233,8 +236,8 @@ } 'OAuthApp' { $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token - SecretType = $tokenResponse.access_token -replace $tokenPrefixPattern + Token = ConvertTo-SecureString -AsPlainText $tokenResponse.access_token + TokenType = $tokenResponse.access_token -replace $tokenPrefixPattern AuthClientID = $authClientID DeviceFlowType = $Mode Scope = $tokenResponse.scope @@ -250,9 +253,9 @@ 'App' { Write-Verbose 'Logging in as a GitHub App...' $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $PrivateKey - SecretType = 'PEM' - ClientID = $ClientID + Token = ConvertTo-SecureString -AsPlainText $PrivateKey + TokenType = 'PEM' + ClientID = $ClientID } } 'PAT' { @@ -262,76 +265,54 @@ Start-Process "https://$HostName/settings/tokens" $accessTokenValue = Read-Host -Prompt 'Enter your personal access token' -AsSecureString $Token = ConvertFrom-SecureString $accessTokenValue -AsPlainText - $secretType = $Token -replace $tokenPrefixPattern + $tokenType = $Token -replace $tokenPrefixPattern $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $Token - SecretType = $secretType + Token = ConvertTo-SecureString -AsPlainText $Token + TokenType = $tokenType } } 'Token' { - $secretType = $Token -replace $tokenPrefixPattern - switch -Regex ($secretType) { + $tokenType = $Token -replace $tokenPrefixPattern + switch -Regex ($tokenType) { 'ghp|github_pat' { $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $Token - SecretType = $secretType + Token = ConvertTo-SecureString -AsPlainText $Token + TokenType = $tokenType } $context['AuthType'] = 'PAT' } 'ghs' { Write-Verbose 'Logging in using an installation access token...' $context += @{ - Secret = ConvertTo-SecureString -AsPlainText $Token - SecretType = $secretType + Token = ConvertTo-SecureString -AsPlainText $Token + TokenType = $tokenType } $context['AuthType'] = 'IAT' } default { Write-Host '⚠ ' -ForegroundColor Yellow -NoNewline - Write-Host "Unexpected token type: $secretType" - throw "Unexpected token type: $secretType" + Write-Host "Unexpected token type: $tokenType" + throw "Unexpected token type: $tokenType" } } } } - Set-GitHubContext @context # Needed so we can use the next authenticated functions (API calls). - try { - switch -Regex ($context['AuthType']) { - 'PAT|UAT|IAT' { - $viewer = Get-GitHubViewer - $context['Name'] = $viewer.login - $context['NodeID'] = $viewer.id - $context['DatabaseID'] = $viewer.databaseId - } - 'App' { - $app = Get-GitHubApp - $context['Name'] = $app.slug - $context['NodeID'] = $app.node_id - $context['DatabaseID'] = $app.id - } - default { - $context['Name'] = 'unknown' - $context['ID'] = 'unknown' - } - } - Set-GitHubContext @context - } catch { - Write-Verbose ($_ | Out-String) - Write-Verbose 'Failed to set the user name' - } - - Write-Verbose ($context | Format-Table | Out-String) - + Set-GitHubContext @context -Default + $context = Get-GitHubContext + Write-Verbose ($context | Format-List | Out-String) if (-not $Silent) { - $name = $(Get-GitHubConfig -Name Name) + $name = $context.Username Write-Host '✓ ' -ForegroundColor Green -NoNewline Write-Host "Logged in as $name!" } } catch { - throw $_ + Write-Error $_ + Write-Error (Get-PSCallStack | Format-Table | Out-String) + throw 'Failed to connect to GitHub.' } finally { Remove-Variable -Name tokenResponse -ErrorAction SilentlyContinue Remove-Variable -Name context -ErrorAction SilentlyContinue [System.GC]::Collect() } + Write-Verbose "[$commandName] - End" } diff --git a/src/functions/public/Auth/Context/Get-GitHubContext.ps1 b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 new file mode 100644 index 000000000..8feed3405 --- /dev/null +++ b/src/functions/public/Auth/Context/Get-GitHubContext.ps1 @@ -0,0 +1,73 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } + +function Get-GitHubContext { + <# + .SYNOPSIS + Get the current GitHub context. + + .DESCRIPTION + Get the current GitHub context. + + .EXAMPLE + Get-GitHubContext + + Gets the current GitHub context. + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingConvertToSecureStringWithPlainText', '', + Justification = 'Encapsulated in a function. Never leaves as a plain text.' + )] + [OutputType([GitHubContext])] + [CmdletBinding(DefaultParameterSetName = 'CurrentContext')] + param( + # The name of the context. + [Parameter( + Mandatory, + ParameterSetName = 'NamedContext' + )] + [Alias('Name')] + [string] $Context, + + # List all available contexts. + [Parameter( + Mandatory, + ParameterSetName = 'ListAvailableContexts' + )] + [switch] $ListAvailable + ) + + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + + if ($ListAvailable) { + $ID = "$($script:Config.Name)/*" + Write-Verbose "Getting available contexts for [$ID]" + } elseif ($Context) { + $ID = "$($script:Config.Name)/$Context" + Write-Verbose "Getting available contexts for [$ID]" + } else { + $config = Get-GitHubConfig + $defaultContext = $config.DefaultContext + $ID = "$($script:Config.Name)/$defaultContext" + if ([string]::IsNullOrEmpty($ID)) { + throw "No default GitHub context found. Please run 'Set-GitHubDefaultContext' or 'Connect-GitHub' to configure a GitHub context." + } + Write-Verbose "Getting the default context: [$ID]" + } + + Get-Context -ID $ID | ForEach-Object { + [GitHubContext]$_ + } + + Write-Verbose "[$commandName] - End" +} + +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) + } +} diff --git a/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 new file mode 100644 index 000000000..ac4b0381e --- /dev/null +++ b/src/functions/public/Auth/Context/Remove-GitHubContext.ps1 @@ -0,0 +1,53 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } + +filter Remove-GitHubContext { + <# + .SYNOPSIS + Removes a context from the context vault. + + .DESCRIPTION + This function removes a context from the vault. It supports removing a single context by name, + multiple contexts using wildcard patterns, and can also accept input from the pipeline. + If the specified context(s) exist, they will be removed from the vault. + + .EXAMPLE + Remove-Context + + Removes all contexts from the vault. + + .EXAMPLE + Remove-Context -ID 'MySecret' + + Removes the context called 'MySecret' from the vault. + #> + [OutputType([void])] + [CmdletBinding(SupportsShouldProcess)] + param( + # The name of the context. + [Parameter(Mandatory)] + [Alias('Name')] + [string] $Context + ) + + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + + $ID = "$($script:Config.Name)/$Context" + + if ($PSCmdlet.ShouldProcess('Remove-Secret', $context.Name)) { + Remove-Context -ID $ID + } + + Write-Verbose "[$commandName] - End" +} + +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) + } +} + diff --git a/src/functions/public/Auth/Context/Set-GitHubContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 new file mode 100644 index 000000000..d002eca31 --- /dev/null +++ b/src/functions/public/Auth/Context/Set-GitHubContext.ps1 @@ -0,0 +1,168 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } + +function Set-GitHubContext { + <# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .EXAMPLE + An example + + .NOTES + General notes + #> + [CmdletBinding(SupportsShouldProcess)] + param ( + # The Node ID of the context. + [Parameter()] + [string] $NodeID, + + # The Database ID of the context. + [Parameter()] + [string] $DatabaseID, + + # Set the access token type. + [Parameter(Mandatory)] + [string] $TokenType, + + # Set the client ID. + [Parameter()] + [string] $ClientID, + + # Set the access token. + [Parameter(Mandatory)] + [securestring] $Token, + + # Set the expiration date of the contexts token. + [Parameter()] + [datetime] $TokenExpirationDate, + + # Set the API Base URI. + [Parameter(Mandatory)] + [string] $ApiBaseUri, + + # Set the GitHub API Version. + [Parameter(Mandatory)] + [string] $ApiVersion, + + # Set the authentication client ID. + [Parameter()] + [string] $AuthClientID, + + # Set the authentication type. + [Parameter(Mandatory)] + [string] $AuthType, + + # Set the device flow type. + [Parameter()] + [string] $DeviceFlowType, + + # Set the API hostname. + [Parameter(Mandatory)] + [string] $HostName, + + # Set the default for the Owner parameter. + [Parameter()] + [string] $Owner, + + # Set the refresh token. + [Parameter()] + [securestring] $RefreshToken, + + # Set the refresh token expiration date. + [Parameter()] + [datetime] $RefreshTokenExpirationDate, + + # Set the default for the Repo parameter. + [Parameter()] + [string] $Repo, + + # Set the scope. + [Parameter()] + [string] $Scope, + + # Set as the default context. + [Parameter()] + [switch] $Default + ) + + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + } + + process { + $tempContextName = "$HostName/tempContext" + $tempContextID = "$($script:Config.Name)/$tempContextName" + + # Set a temporary context. + $context = @{ + ApiBaseUri = $ApiBaseUri # https://api.github.com + ApiVersion = $ApiVersion # 2022-11-28 + AuthClientID = $AuthClientID # Client ID for UAT + AuthType = $AuthType # UAT / PAT / App / IAT + ClientID = $ClientID # Client ID for GitHub Apps + DeviceFlowType = $DeviceFlowType # GitHubApp / OAuthApp + HostName = $HostName # github.com / msx.ghe.com / github.local + NodeID = $NodeID # User ID / app ID (GraphQL Node ID) + DatabaseID = $DatabaseID # Database ID + UserName = $UserName # User name + Owner = $Owner # Owner name + Repo = $Repo # Repo name + Scope = $Scope # 'gist read:org repo workflow' + #----------------------------------------------------------------------------------------- + TokenType = $TokenType # ghu / gho / ghp / github_pat / PEM / ghs / + Token = $Token # Access token + TokenExpirationDate = $TokenExpirationDate # 2024-01-01-00:00:00 + RefreshToken = $RefreshToken # Refresh token + RefreshTokenExpirationDate = $RefreshTokenExpirationDate # 2024-01-01-00:00:00 + } + + $context | Remove-HashtableEntry -NullOrEmptyValues + + Set-Context -ID $tempContextID -Context $context + + # Run functions to get info on the temporary context. + try { + Write-Verbose 'Getting info on the context.' + switch -Regex ($context['AuthType']) { + 'PAT|UAT|IAT' { + $viewer = Get-GitHubViewer -Context $tempContextName + $contextName = "$HostName/$($viewer.login)" + $context['Username'] = $viewer.login + $context['NodeID'] = $viewer.id + $context['DatabaseID'] = ($viewer.databaseId).ToString() + } + 'App' { + $app = Get-GitHubApp -Context $tempContextName + $contextName = "$HostName/$($app.slug)" + $context['Username'] = $app.slug + $context['NodeID'] = $app.node_id + $context['DatabaseID'] = $app.id + } + default { + throw 'Failed to get info on the context. Unknown logon type.' + } + } + Write-Verbose "Found user with username: [$($context['Username'])]" + + if ($PSCmdlet.ShouldProcess('Context', 'Set')) { + Set-Context -ID "$($script:Config.Name)/$contextName" -Context $context + if ($Default) { + Set-GitHubDefaultContext -Context $contextName + } + } + } catch { + throw ($_ -join ';') + } finally { + Remove-Context -ID $tempContextID + } + } + + end { + Write-Verbose "[$commandName] - End" + } +} diff --git a/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 new file mode 100644 index 000000000..00f5a98d7 --- /dev/null +++ b/src/functions/public/Auth/Context/Set-GitHubDefaultContext.ps1 @@ -0,0 +1,40 @@ +function Set-GitHubDefaultContext { + <# + .SYNOPSIS + Set the default context. + + .DESCRIPTION + Set the default context for the GitHub module. + + .EXAMPLE + Set-GitHubDefaultContext -Context 'github.com/Octocat' + #> + [CmdletBinding(SupportsShouldProcess)] + param ( + # The context to set as the default. + [Parameter(Mandatory)] + [Alias('Name')] + [string] $Context + ) + + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + + if ($PSCmdlet.ShouldProcess("$Context", 'Set default context')) { + Set-GitHubConfig -Name 'DefaultContext' -Value $Context + } + + Write-Verbose "[$commandName] - End" +} + +Register-ArgumentCompleter -CommandName Set-GitHubDefaultContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + $defaultContext = Get-GitHubConfig -Name 'DefaultContext' + + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" -and $_.ID -ne $defaultContext } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) + } +} diff --git a/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 new file mode 100644 index 000000000..d6ef02820 --- /dev/null +++ b/src/functions/public/Auth/ContextSetting/Get-GitHubContextSetting.ps1 @@ -0,0 +1,50 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } + +function Get-GitHubContextSetting { + <# + .SYNOPSIS + Get a module configuration value. + + .DESCRIPTION + Get a named configuration value from the GitHub config. + + .EXAMPLE + Get-GitHubContextSetting -Name DefaultUser + + Get the current GitHub configuration for the DefaultUser. + #> + [OutputType([object])] + [CmdletBinding()] + param( + # Choose a configuration name to get. + [Parameter()] + [string] $Name, + + # The name of the context. + [Parameter()] + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') + ) + + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + + $ID = "$($script:Config.Name)/$Context" + + if (-not $Name) { + Get-Context -ID $ID + } + + Get-ContextSetting -Name $Name -ID $ID + + Write-Verbose "[$commandName] - End" +} + +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) + } +} diff --git a/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 new file mode 100644 index 000000000..d29c689ea --- /dev/null +++ b/src/functions/public/Auth/ContextSetting/Set-GitHubContextSetting.ps1 @@ -0,0 +1,121 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } + +function Set-GitHubContextSetting { + <# + .SYNOPSIS + Set the GitHub configuration. + + .DESCRIPTION + Set the GitHub configuration. Specific scopes can be set by using the parameters. + + .EXAMPLE + Set-GitHubContextSetting -APIBaseURI 'https://api.github.com" -APIVersion '2022-11-28' + + Sets the App.API scope of the GitHub configuration. + + .EXAMPLE + Set-GitHubContextSetting -Name "MyFavouriteRepo" -Value 'https://github.com/PSModule/GitHub' + + Sets a item called 'MyFavouriteRepo' in the GitHub configuration. + #> + [Alias('Set-GHConfig')] + [CmdletBinding(SupportsShouldProcess)] + param ( + # Set the access token type. + [Parameter()] + [string] $TokenType, + + # The Node ID of the context. + [Parameter()] + [string] $NodeID, + + # The Database ID of the context. + [Parameter()] + [string] $DatabaseID, + + # Set the access token. + [Parameter()] + [securestring] $Token, + + # Set the access token expiration date. + [Parameter()] + [datetime] $TokenExpirationDate, + + # Set the API Base URI. + [Parameter()] + [string] $ApiBaseUri, + + # Set the GitHub API Version. + [Parameter()] + [string] $ApiVersion, + + # Set the authentication client ID. + [Parameter()] + [string] $AuthClientID, + + # Set the authentication type. + [Parameter()] + [string] $AuthType, + + # Set the client ID. + [Parameter()] + [string] $ClientID, + + # Set the device flow type. + [Parameter()] + [string] $DeviceFlowType, + + # Set the default for the Owner parameter. + [Parameter()] + [string] $Owner, + + # Set the refresh token. + [Parameter()] + [securestring] $RefreshToken, + + # Set the refresh token expiration date. + [Parameter()] + [datetime] $RefreshTokenExpirationDate, + + # Set the default for the Repo parameter. + [Parameter()] + [string] $Repo, + + # Set the scope. + [Parameter()] + [string] $Scope, + + # The context name to set the configuration for. + [Parameter()] + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') + ) + + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + + $contextID = "$($Script:Config.Name)/$Context" + + if ($PSCmdlet.ShouldProcess('Config', 'Set')) { + + $PSBoundParameters.GetEnumerator() | ForEach-Object { + $key = $_.Key + $value = $_.Value + if ($PSCmdlet.ShouldProcess("Setting [$key]", "to [$value]")) { + Write-Verbose "Setting [$key] to [$value]" + Set-ContextSetting -Name $key -Value $value -ID $contextID + } + } + } + + Write-Verbose "[$commandName] - End" +} + +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) + } +} diff --git a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 index 27a599f00..e6d5cd254 100644 --- a/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 +++ b/src/functions/public/Auth/Disconnect-GitHubAccount.ps1 @@ -1,34 +1,63 @@ function Disconnect-GitHubAccount { <# .SYNOPSIS - Disconnects from GitHub and removes the current GitHub configuration. + Disconnects from GitHub and removes the GitHub context. .DESCRIPTION - Disconnects from GitHub and removes the current GitHub configuration. + Disconnects from GitHub and removes the GitHub context. .EXAMPLE Disconnect-GitHubAccount - Disconnects from GitHub and removes the current GitHub configuration. + Disconnects from GitHub and removes the default GitHub context. + + .EXAMPLE + Disconnect-GithubAccount -Context 'github.com/Octocat' + + Disconnects from GitHub and removes the context 'github.com/Octocat'. #> - [Alias('Disconnect-GHAccount')] - [Alias('Disconnect-GitHub')] - [Alias('Disconnect-GH')] - [Alias('Logout-GitHubAccount')] - [Alias('Logout-GHAccount')] - [Alias('Logout-GitHub')] - [Alias('Logout-GH')] - [Alias('Logoff-GitHubAccount')] - [Alias('Logoff-GHAccount')] - [Alias('Logoff-GitHub')] - [Alias('Logoff-GH')] + [Alias( + 'Disconnect-GHAccount', + 'Disconnect-GitHub', + 'Disconnect-GH', + 'Logout-GitHubAccount', + 'Logout-GHAccount', + 'Logout-GitHub', + 'Logout-GH', + 'Logoff-GitHubAccount', + 'Logoff-GHAccount', + 'Logoff-GitHub', + 'Logoff-GH' + )] [OutputType([void])] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification = 'Is the CLI part of the module.')] [CmdletBinding()] - param () + param( + # The context to log out of. + [Parameter()] + [Alias('Name')] + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') + ) + + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" - Remove-Store -Name $script:Config.Name + $Context = Get-GitHubConfig -Name 'DefaultContext' + Remove-GitHubContext -Context $Context + Remove-GitHubConfig -Name 'DefaultContext' Write-Host '✓ ' -ForegroundColor Green -NoNewline - Write-Host 'Logged out of GitHub!' + Write-Host "Logged out of GitHub! [$Context]" + + Write-Verbose "[$commandName] - End" +} + +Register-ArgumentCompleter -CommandName Get-GitHubContext -ParameterName Context -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter + + Get-GitHubContext -ListAvailable | Where-Object { $_.ID -like "$wordToComplete*" } -Verbose:$false | + ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_.ID, $_.ID, 'ParameterValue', $_.ID) + } } diff --git a/src/functions/public/Auth/Get-GitHubViewer.ps1 b/src/functions/public/Auth/Get-GitHubViewer.ps1 index d29d8a863..1b3292ac3 100644 --- a/src/functions/public/Auth/Get-GitHubViewer.ps1 +++ b/src/functions/public/Auth/Get-GitHubViewer.ps1 @@ -16,16 +16,32 @@ #> [CmdletBinding()] param( - [string[]] $Fields = @('login', 'id', 'databaseId') + # The fields to return. + [string[]] $Fields = @('login', 'id', 'databaseId'), + + # Context to run the command in. + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) - $query = @" + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + } + + process { + $query = @" query { viewer { $($Fields -join "`n") } } "@ - $results = Invoke-GitHubGraphQLQuery -Query $query - return $results.data.viewer + $results = Invoke-GitHubGraphQLQuery -Query $query -Context $Context + + return $results.data.viewer + } + + end { + Write-Verbose "[$commandName] - End" + } } diff --git a/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 b/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 index 2b98f1304..331bbe848 100644 --- a/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 +++ b/src/functions/public/Branches/Get-GitHubRepoBranch.ps1 @@ -18,11 +18,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Config/Get-GitHubConfig.ps1 b/src/functions/public/Config/Get-GitHubConfig.ps1 index ca595aeb0..524579deb 100644 --- a/src/functions/public/Config/Get-GitHubConfig.ps1 +++ b/src/functions/public/Config/Get-GitHubConfig.ps1 @@ -1,31 +1,40 @@ -#Requires -Modules @{ ModuleName = 'Store'; RequiredVersion = '0.3.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } function Get-GitHubConfig { <# .SYNOPSIS - Get configuration value. + Get a GitHub module configuration. .DESCRIPTION - Get a named configuration value from the GitHub configuration file. + Get a GitHub module configuration. .EXAMPLE - Get-GitHubConfig -Name ApiBaseUri + Get-GitHubConfig -Name DefaultUser - Get the current GitHub configuration for the ApiBaseUri. + Get the DefaultUser value from the GitHub module configuration. #> - [Alias('Get-GHConfig')] - [Alias('GGHC')] - [OutputType([object])] + [OutputType([void])] [CmdletBinding()] param ( - # Choose a configuration name to get. + # The name of the configuration to get. [Parameter()] [string] $Name ) - if (-not $Name) { - return Get-GitHubContext + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" } - Get-StoreConfig -Name $Name -Store $script:Config.Name + process { + if (-not $Name) { + return Get-Context -ID $script:Config.Name + } + + Get-ContextSetting -Name $Name -ID $script:Config.Name + } + + end { + Write-Verbose "[$commandName] - End" + } } diff --git a/src/functions/public/Config/Get-GitHubContext.ps1 b/src/functions/public/Config/Get-GitHubContext.ps1 deleted file mode 100644 index 4242dd8bd..000000000 --- a/src/functions/public/Config/Get-GitHubContext.ps1 +++ /dev/null @@ -1,21 +0,0 @@ -#Requires -Modules @{ ModuleName = 'Store'; RequiredVersion = '0.3.1' } - -function Get-GitHubContext { - <# - .SYNOPSIS - Get the current GitHub context. - - .DESCRIPTION - Get the current GitHub context. - - .EXAMPLE - Get-GitHubContext - - Gets the current GitHub context. - #> - [OutputType([object])] - [CmdletBinding()] - param () - - Get-Store -Name $script:Config.Name -} diff --git a/src/functions/public/Config/Remove-GitHubConfig.ps1 b/src/functions/public/Config/Remove-GitHubConfig.ps1 new file mode 100644 index 000000000..0389ce1d9 --- /dev/null +++ b/src/functions/public/Config/Remove-GitHubConfig.ps1 @@ -0,0 +1,37 @@ +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } + +function Remove-GitHubConfig { + <# + .SYNOPSIS + Remove a GitHub module configuration. + + .DESCRIPTION + Remove a GitHub module configuration. + + .EXAMPLE + Remove-GitHubConfig -Name DefaultUser + + Removes the 'DefaultUser' item in the GitHub module configuration. + #> + [CmdletBinding(SupportsShouldProcess)] + param ( + # Set the access token type. + [Parameter()] + [string] $Name + ) + + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + + try { + if ($PSCmdlet.ShouldProcess('ContextSetting', 'Remove')) { + Remove-ContextSetting -Name $Name -ID $script:Config.Name + } + } catch { + Write-Error $_ + Write-Error (Get-PSCallStack | Format-Table | Out-String) + throw 'Failed to connect to GitHub.' + } + + Write-Verbose "[$commandName] - End" +} diff --git a/src/functions/public/Config/Set-GitHubConfig.ps1 b/src/functions/public/Config/Set-GitHubConfig.ps1 index 0d3486b00..2be9e9a55 100644 --- a/src/functions/public/Config/Set-GitHubConfig.ps1 +++ b/src/functions/public/Config/Set-GitHubConfig.ps1 @@ -1,135 +1,30 @@ -#Requires -Modules @{ ModuleName = 'Store'; RequiredVersion = '0.3.1' } +#Requires -Modules @{ ModuleName = 'Context'; RequiredVersion = '4.0.0' } function Set-GitHubConfig { <# .SYNOPSIS - Set the GitHub configuration. + Set a GitHub module configuration. .DESCRIPTION - Set the GitHub configuration. Specific scopes can be set by using the parameters. + Set a GitHub module configuration. .EXAMPLE - Set-GitHubConfig -APIBaseURI 'https://api.github.com" -APIVersion '2022-11-28' + Set-GitHubConfig -Name DefaultUser -Value 'Octocat' - Sets the App.API scope of the GitHub configuration. - - .EXAMPLE - Set-GitHubConfig -Name "MyFavouriteRepo" -Value 'https://github.com/PSModule/GitHub' - - Sets a item called 'MyFavouriteRepo' in the GitHub configuration. + Sets the value of DefaultUser to 'Octocat' in the GitHub module configuration. #> - [Alias('Set-GHConfig')] [CmdletBinding(SupportsShouldProcess)] param ( # Set the access token type. [Parameter()] - [string] $SecretType, - - # The Node ID of the context. - [Parameter()] - [string] $NodeID, - - # The Database ID of the context. - [Parameter()] - [string] $DatabaseID, - - # Set the access token. - [Parameter()] - [securestring] $Secret, - - # Set the access token expiration date. - [Parameter()] - [datetime] $SecretExpirationDate, - - # Set the API Base URI. - [Parameter()] - [string] $ApiBaseUri, - - # Set the GitHub API Version. - [Parameter()] - [string] $ApiVersion, - - # Set the authentication client ID. - [Parameter()] - [string] $AuthClientID, - - # Set the authentication type. - [Parameter()] - [string] $AuthType, - - # Set the client ID. - [Parameter()] - [string] $ClientID, + [string] $Name, - # Set the device flow type. - [Parameter()] - [string] $DeviceFlowType, - - # Set the API hostname. - [Parameter()] - [string] $HostName, - - # Set the default for the Owner parameter. - [Parameter()] - [string] $Owner, - - # Set the refresh token. - [Parameter()] - [securestring] $RefreshToken, - - # Set the refresh token expiration date. - [Parameter()] - [datetime] $RefreshTokenExpirationDate, - - # Set the default for the Repo parameter. - [Parameter()] - [string] $Repo, - - # Set the scope. - [Parameter()] - [string] $Scope, - - # Set the GitHub username. + # Set the access token type. [Parameter()] - [string] $Name + [string] $Value ) - $storeName = $Script:Config.Name - - if ($PSCmdlet.ShouldProcess('Config', 'Set')) { - - if ($RefreshToken) { - Set-Store -Name "$storeName/RefreshToken" -Secret $RefreshToken -Variables @{ - RefreshTokenExpirationDate = $RefreshTokenExpirationDate - } - } - - $variables = @{ - ApiBaseUri = $ApiBaseUri - ApiVersion = $ApiVersion - AuthClientID = $AuthClientID - AuthType = $AuthType - ClientID = $ClientID - DeviceFlowType = $DeviceFlowType - HostName = $HostName - NodeID = $NodeID - DatabaseID = $DatabaseID - Name = $Name - Owner = $Owner - Repo = $Repo - Scope = $Scope - Secret = $Secret - SecretExpirationDate = $SecretExpirationDate - SecretType = $SecretType - } - - $variables | Remove-HashtableEntry -NullOrEmptyValues - - foreach ($key in $variables.Keys) { - if ($PSCmdlet.ShouldProcess("Setting [$key]", "to [$($variables[$key])]")) { - Write-Verbose "Setting [$key] to [$($variables[$key])]" - Set-StoreConfig -Name $key -Value $variables[$key] -Store $script:Config.Name - } - } + if ($PSCmdlet.ShouldProcess('ContextSetting', 'Set')) { + Set-ContextSetting -Name $Name -Value $Value -ID $script:Config.Name } } diff --git a/src/functions/public/Config/Set-GitHubContext.ps1 b/src/functions/public/Config/Set-GitHubContext.ps1 deleted file mode 100644 index 2974c3e1c..000000000 --- a/src/functions/public/Config/Set-GitHubContext.ps1 +++ /dev/null @@ -1,124 +0,0 @@ -#Requires -Modules @{ ModuleName = 'Store'; RequiredVersion = '0.3.1' } - -function Set-GitHubContext { - <# - .SYNOPSIS - Short description - - .DESCRIPTION - Long description - - .EXAMPLE - An example - - .NOTES - General notes - #> - [CmdletBinding(SupportsShouldProcess)] - param ( - # The name of the context. - [Parameter(Mandatory)] - [string] $Name, - - # The Node ID of the context. - [Parameter()] - [string] $NodeID, - - # The Database ID of the context. - [Parameter()] - [string] $DatabaseID, - - # Set the access token type. - [Parameter(Mandatory)] - [string] $SecretType, - - # Set the client ID. - [Parameter()] - [string] $ClientID, - - # Set the access token. - [Parameter(Mandatory)] - [securestring] $Secret, - - # Set the expiration date of the contexts secret. - [Parameter()] - [datetime] $SecretExpirationDate, - - # Set the API Base URI. - [Parameter(Mandatory)] - [string] $ApiBaseUri, - - # Set the GitHub API Version. - [Parameter(Mandatory)] - [string] $ApiVersion, - - # Set the authentication client ID. - [Parameter()] - [string] $AuthClientID, - - # Set the authentication type. - [Parameter(Mandatory)] - [string] $AuthType, - - # Set the device flow type. - [Parameter()] - [string] $DeviceFlowType, - - # Set the API hostname. - [Parameter(Mandatory)] - [string] $HostName, - - # Set the default for the Owner parameter. - [Parameter()] - [string] $Owner, - - # Set the refresh token. - [Parameter()] - [securestring] $RefreshToken, - - # Set the refresh token expiration date. - [Parameter()] - [datetime] $RefreshTokenExpirationDate, - - # Set the default for the Repo parameter. - [Parameter()] - [string] $Repo, - - # Set the scope. - [Parameter()] - [string] $Scope - ) - - $storeName = $Script:Config.Name - # $storeName = $Script:Config.Name, $HostName, $Name -join '/' - - if ($PSCmdlet.ShouldProcess('Context', 'Set')) { - - if ($RefreshToken) { - Set-Store -Name "$storeName/RefreshToken" -Secret $RefreshToken -Variables @{ - RefreshTokenExpirationDate = $RefreshTokenExpirationDate - } - } - $variables = @{ - ApiBaseUri = $ApiBaseUri # https://api.github.com - ApiVersion = $ApiVersion # 2022-11-28 - AuthClientID = $AuthClientID # Client ID for UAT - AuthType = $AuthType # UAT / PAT / App / IAT - ClientID = $ClientID # Client ID for GitHub Apps - DeviceFlowType = $DeviceFlowType # GitHubApp / OAuthApp - HostName = $HostName # github.com / msx.ghe.com / github.local - NodeID = $NodeID # User ID / app ID (GraphQL Node ID) - DatabaseID = $DatabaseID # Database ID - Name = $Name # Username / app slug - Owner = $Owner # Owner name - Repo = $Repo # Repo name - Scope = $Scope # 'gist read:org repo workflow' - SecretExpirationDate = $SecretExpirationDate # 2024-01-01-00:00:00 - SecretType = $SecretType # ghu / gho / ghp / github_pat / PEM / ghs / - } - - $variables | Remove-HashtableEntry -NullOrEmptyValues - - Set-Store -Name $storeName -Secret $Secret -Variables $variables - } -} diff --git a/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 b/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 index 686711d87..081c7aacf 100644 --- a/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 +++ b/src/functions/public/GraphQL/Invoke-GitHubGraphQLQuery.ps1 @@ -17,10 +17,14 @@ [string] $Query, # The variables to pass to the query. - [hashtable] $Variables + [hashtable] $Variables, + + # The context to run the command in. + [string] $Context = (Get-GitHubConfig -Name 'DefaultContext') ) $inputObject = @{ + Context = $Context APIEndpoint = '/graphql' Method = 'Post' Body = @{ diff --git a/src/functions/public/License/Get-GitHubLicense.ps1 b/src/functions/public/License/Get-GitHubLicense.ps1 index 565d4fb3d..5a4efc21b 100644 --- a/src/functions/public/License/Get-GitHubLicense.ps1 +++ b/src/functions/public/License/Get-GitHubLicense.ps1 @@ -38,11 +38,11 @@ filter Get-GitHubLicense { param ( # The account owner of the repository. The name is not case sensitive. [Parameter(ParameterSetName = 'Repository')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter(ParameterSetName = 'Repository')] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) dynamicparam { diff --git a/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 index b98a4ed9e..f2086ee52 100644 --- a/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Add-GitHubReleaseAsset.ps1 @@ -49,11 +49,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 index 699be6046..90bb38cf8 100644 --- a/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Get-GitHubReleaseAsset.ps1 @@ -25,11 +25,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the asset. [Parameter( diff --git a/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 index 0c11f52ea..75bbcf0e0 100644 --- a/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Remove-GitHubReleaseAsset.ps1 @@ -19,11 +19,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the asset. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 b/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 index e7b4bf778..3bfb3c3ba 100644 --- a/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 +++ b/src/functions/public/Releases/Assets/Set-GitHubReleaseAsset.ps1 @@ -19,11 +19,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the asset. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 index 8b1bdee84..038070ed2 100644 --- a/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/Get-GitHubRelease.ps1 @@ -38,11 +38,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter(ParameterSetName = 'All')] diff --git a/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 index e5b607712..a3523734b 100644 --- a/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/New-GitHubRelease.ps1 @@ -25,11 +25,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the tag. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 b/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 index 2b0d3568a..07e64114f 100644 --- a/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 +++ b/src/functions/public/Releases/Releases/New-GitHubReleaseNote.ps1 @@ -59,11 +59,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The tag name for the release. This can be an existing tag or a new one. [Parameter(Mandatory)] diff --git a/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 index c1593fa93..6a29a900d 100644 --- a/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/Remove-GitHubRelease.ps1 @@ -20,11 +20,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter( diff --git a/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 b/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 index 34d378bff..2993b6f0c 100644 --- a/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 +++ b/src/functions/public/Releases/Releases/Set-GitHubRelease.ps1 @@ -20,11 +20,11 @@ param ( # The account owner of the repository. The name is not case sensitive. [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the release. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 b/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 index c1f9bc093..d9c43dd25 100644 --- a/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 +++ b/src/functions/public/Repositories/Autolinks/Get-GitHubRepositoryAutolink.ps1 @@ -28,11 +28,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the autolink. [Parameter( diff --git a/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 b/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 index 14246562a..7dff0bc03 100644 --- a/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 +++ b/src/functions/public/Repositories/CustomProperties/Get-GitHubRepositoryCustomProperty.ps1 @@ -24,11 +24,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 index 0722bc0d9..580c24b4b 100644 --- a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 +++ b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 index 351bb170e..cd6158d98 100644 --- a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositorySecurityFix.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 index d2d9d6c41..0b9eb8af6 100644 --- a/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 +++ b/src/functions/public/Repositories/Repositories/Disable-GitHubRepositoryVulnerabilityAlert.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 index 884b887d5..0889ca16b 100644 --- a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 +++ b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryPrivateVulnerabilityReporting.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 index f62a5c51c..66b608b79 100644 --- a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositorySecurityFix.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 index ce63b877c..f20658e26 100644 --- a/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 +++ b/src/functions/public/Repositories/Repositories/Enable-GitHubRepositoryVulnerabilityAlert.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 index 8ce82e0e6..26ff63958 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepository.ps1 @@ -82,14 +82,14 @@ filter Get-GitHubRepository { # The account owner of the repository. The name is not case sensitive. [Parameter(ParameterSetName = 'ByName')] [Parameter(ParameterSetName = 'ListByOrg')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter( Mandatory, ParameterSetName = 'ByName' )] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The handle for the GitHub user account. [Parameter( diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 index eeb98ad21..690710b74 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryActivity.ps1 @@ -54,11 +54,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The direction to sort the results by. [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 index 9fc9967d9..9d3fff276 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryCodeownersError.ps1 @@ -24,11 +24,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # A branch, tag or commit name used to determine which version of the CODEOWNERS file to use. # Default: the repository's default branch (e.g. main) diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 index 0c4475f3c..7e6477830 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryContributor.ps1 @@ -25,11 +25,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # Wether to include anonymous contributors in results. [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 index 8f699b9f0..35f2a2671 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryFork.ps1 @@ -20,11 +20,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The direction to sort the results by. [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 index 97e7dd0e8..ee26ec371 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryLanguage.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 index 3cc87e91c..78005111d 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositorySecurityFix.ps1 @@ -24,11 +24,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 index 9f01df1a6..264f51b3e 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTag.ps1 @@ -21,11 +21,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 index 56ef4948e..1b0d53e82 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTeam.ps1 @@ -29,11 +29,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 index a5725700b..86139402e 100644 --- a/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 +++ b/src/functions/public/Repositories/Repositories/Get-GitHubRepositoryTopic.ps1 @@ -17,11 +17,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 index 0bdd16791..bbd1cf1c3 100644 --- a/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Move-GitHubRepository.ps1 @@ -25,11 +25,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The username or organization name the repository will be transferred to. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 index 0a1c75c51..1f9e16f61 100644 --- a/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/New-GitHubRepository.ps1 @@ -113,7 +113,7 @@ filter New-GitHubRepository { [Parameter(ParameterSetName = 'org')] [Parameter(ParameterSetName = 'fork')] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository. [Parameter(ParameterSetName = 'fork')] diff --git a/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 b/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 index f0655a3ea..84321e3c6 100644 --- a/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 +++ b/src/functions/public/Repositories/Repositories/Set-GitHubRepositoryTopic.ps1 @@ -19,11 +19,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The number of results per page (max 100). [Parameter()] diff --git a/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 b/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 index 841231d09..1351cf4ef 100644 --- a/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 +++ b/src/functions/public/Repositories/Repositories/Start-GitHubRepositoryEvent.ps1 @@ -46,11 +46,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # A custom webhook event name. Must be 100 characters or fewer. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 b/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 index 20d7a15c8..dfb8ace31 100644 --- a/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 +++ b/src/functions/public/Repositories/Repositories/Test-GitHubRepositoryVulnerabilityAlert.ps1 @@ -24,11 +24,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 b/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 index a95b7c121..5df971400 100644 --- a/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 +++ b/src/functions/public/Repositories/Repositories/Update-GitHubRepository.ps1 @@ -28,11 +28,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the repository. [Parameter()] diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 index f4a6db95b..b9bd1f72f 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuite.ps1 @@ -37,11 +37,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the ref. Cannot contain wildcard characters. # When specified, only rule evaluations triggered for this ref will be returned. diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 index 0c0d92b99..2e7e08306 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteById.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the rule suite result. To get this ID, you can use GET /repos/ { owner }/ { repo }/rulesets/rule-suites for repositories and GET /orgs/ { org }/rulesets/rule-suites for organizations. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 index 4544d818c..1168ce9c4 100644 --- a/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 +++ b/src/functions/public/Repositories/RuleSuite/Get-GitHubRepositoryRuleSuiteList.ps1 @@ -31,11 +31,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The name of the ref. Cannot contain wildcard characters. # When specified, only rule evaluations triggered for this ref will be returned. diff --git a/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 b/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 index 5fb0b0f62..ad089c4ac 100644 --- a/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 +++ b/src/functions/public/Repositories/Tags/Get-GitHubRepositoryTagProtection.ps1 @@ -23,11 +23,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 b/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 index 3549d5a03..df107bb7b 100644 --- a/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 +++ b/src/functions/public/Repositories/Tags/New-GitHubRepositoryTagProtection.ps1 @@ -21,11 +21,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # An optional glob pattern to match against when enforcing tag protection. [Parameter(Mandatory)] diff --git a/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 b/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 index cd59eadd2..414af87f4 100644 --- a/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 +++ b/src/functions/public/Repositories/Tags/Remove-GitHubRepositoryTagProtection.ps1 @@ -22,11 +22,11 @@ # The account owner of the repository. The name is not case sensitive. [Parameter()] [Alias('org')] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), # The name of the repository without the .git extension. The name is not case sensitive. [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo), + [string] $Repo = (Get-GitHubContextSetting -Name Repo), # The unique identifier of the tag protection. [Parameter(Mandatory)] diff --git a/src/functions/public/Teams/Get-GitHubRepoTeam.ps1 b/src/functions/public/Teams/Get-GitHubRepoTeam.ps1 index 1431fa83e..c472512a5 100644 --- a/src/functions/public/Teams/Get-GitHubRepoTeam.ps1 +++ b/src/functions/public/Teams/Get-GitHubRepoTeam.ps1 @@ -6,10 +6,10 @@ filter Get-GitHubRepoTeam { [CmdletBinding()] param ( [Parameter()] - [string] $Owner = (Get-GitHubConfig -Name Owner), + [string] $Owner = (Get-GitHubContextSetting -Name Owner), [Parameter()] - [string] $Repo = (Get-GitHubConfig -Name Repo) + [string] $Repo = (Get-GitHubContextSetting -Name Repo) ) $inputObject = @{ diff --git a/src/loader.ps1 b/src/loader.ps1 index afedb29d5..d3d47b9ee 100644 --- a/src/loader.ps1 +++ b/src/loader.ps1 @@ -1,6 +1,6 @@ $scriptFilePath = $MyInvocation.MyCommand.Path - -Write-Verbose "[$scriptFilePath] - Initializing GitHub PowerShell module..." +Write-Verbose "Initializing GitHub PowerShell module..." +Write-Verbose "Path: $scriptFilePath" if ($env:GITHUB_ACTIONS -eq 'true') { Write-Verbose 'Detected running on a GitHub Actions runner, preparing environment...' @@ -8,9 +8,10 @@ if ($env:GITHUB_ACTIONS -eq 'true') { Set-GitHubEnv -Name 'GITHUB_REPOSITORY_NAME' -Value $env:GITHUB_REPOSITORY_NAME } -### This is the store config for this module -$storeParams = @{ - Name = $script:Config.Name - Variables = @{} +### This is the context for this module +# Get current module context +$context = (Get-Context -ID $script:Config.Name) +if (-not $context) { + Write-Verbose 'No context found, creating a new context...' + Set-Context -ID $script:Config.Name -Context @{ Name = 'GitHub' } } -Set-Store @storeParams diff --git a/tests/GitHub.Tests.ps1 b/tests/GitHub.Tests.ps1 index 21dcfbd94..067d52ee3 100644 --- a/tests/GitHub.Tests.ps1 +++ b/tests/GitHub.Tests.ps1 @@ -1,40 +1,79 @@ -BeforeAll { - Connect-GitHub -} +Describe 'GitHub' { + Context 'Auth' { + It 'Can connect and disconnect without parameters in GitHubActions' { + { Connect-GitHubAccount } | Should -Not -Throw + { Disconnect-GitHubAccount } | Should -Not -Throw + } -Describe 'GitHub' { - Context 'Invoke-GitHubAPI' { - It 'Invoke-GitHubAPI function exists' { - Get-Command Invoke-GitHubAPI | Should -Not -BeNullOrEmpty + It 'Can connect and disconnect - a second time' { + Connect-GitHubAccount + Write-Verbose (Get-GitHubContext | Out-String) -Verbose + Write-Verbose (Get-GitHubConfig | Out-String) -Verbose + Connect-GitHubAccount + Write-Verbose (Get-GitHubContext | Out-String) -Verbose + Write-Verbose (Get-GitHubConfig | Out-String) -Verbose + { Disconnect-GitHubAccount } | Should -Not -Throw } - It 'Can be called directly to get ratelimits' { - { Invoke-GitHubAPI -ApiEndpoint '/rate_limit' -Method GET } | Should -Not -Throw + It 'Can connect multiple sessions, GITHUB_TOKEN + classic PAT token' { + { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw + { Connect-GitHubAccount -Token $env:TEST_PAT } | Should -Not -Throw + { Connect-GitHubAccount } | Should -Not -Throw # Logs on with GitHub Actions' token + (Get-GitHubContext -ListAvailable).Count | Should -Be 2 + Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/github-actions[bot]' + Write-Verbose (Get-GitHubContext | Out-String) -Verbose } - } - Context 'Get-GitHubConfig' { - It 'Get-GitHubConfig function exists' { - Get-Command Get-GitHubConfig | Should -Not -BeNullOrEmpty + + It 'Can reconfigure an existing context to be fine-grained PAT token' { + { Connect-GitHubAccount -Token $env:TEST_FG_PAT } | Should -Not -Throw + (Get-GitHubContext -ListAvailable).Count | Should -Be 2 + Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose + } + + It 'Can be called with a GitHub App' { + { Connect-GitHubAccount -ClientID $env:TEST_APP_CLIENT_ID -PrivateKey $env:TEST_APP_PRIVATE_KEY } | Should -Not -Throw + { Connect-GitHubAccount -ClientID $env:TEST_APP_CLIENT_ID -PrivateKey $env:TEST_APP_PRIVATE_KEY } | Should -Not -Throw + Write-Verbose (Get-GitHubContext | Out-String) -Verbose + } + + It 'Can list all contexts' { + Write-Verbose (Get-GitHubContext -ListAvailable | Out-String) -Verbose + (Get-GitHubContext -ListAvailable).Count | Should -Be 3 + } + + It 'Can swap context to another' { + { Set-GitHubDefaultContext -Context 'github.com/github-actions[bot]' } | Should -Not -Throw + Get-GitHubConfig -Name 'DefaultContext' | Should -Be 'github.com/github-actions[bot]' + } + + # It 'Can be called with a GitHub App Installation Access Token' { + # { Connect-GitHubAccount -Token $env:TEST_APP_INSTALLATION_ACCESS_TOKEN } | Should -Not -Throw + # } + + It 'Get-GitHubViewer can be called' { + Get-GitHubViewer | Should -Not -BeNullOrEmpty } - It 'Can be called directly to get the ApiBaseUri' { - Write-Verbose (Get-GitHubConfig -Name ApiBaseUri) -Verbose - { Get-GitHubConfig -Name ApiBaseUri } | Should -Not -Throw + It 'Get-GitHubConfig gets the DefaultContext' { + Write-Verbose (Get-GitHubConfig -Name 'DefaultContext') -Verbose + { Get-GitHubConfig -Name 'DefaultContext' } | Should -Not -Throw } It 'Can be called without a parameter' { $config = Get-GitHubConfig - Write-Verbose ($config.Secrets | Format-List | Out-String) -Verbose - Write-Verbose ($config.Variables | Format-List | Out-String) -Verbose + Write-Verbose ($config | Format-Table | Out-String) -Verbose { Get-GitHubConfig } | Should -Not -Throw + $config.ID | Should -Be 'PSModule.GitHub' } } - Context 'Get-GitHubViewer' { - It 'Get-GitHubViewer function exists' { - Get-Command Get-GitHubViewer | Should -Not -BeNullOrEmpty - } - It 'Get-GiTubViewer can be called' { - Get-GitHubViewer | Should -Not -BeNullOrEmpty - } +} + +Context 'API' { + It 'Can be called directly to get ratelimits' { + { + $rateLimit = Invoke-GitHubAPI -ApiEndpoint '/rate_limit' + Write-Verbose ($rateLimit | Format-Table | Out-String) -Verbose + } | Should -Not -Throw + } } diff --git a/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 b/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 deleted file mode 100644 index 164e0be21..000000000 --- a/tests/GitHub/Auth/Connect-GitHubAccount.Tests.ps1 +++ /dev/null @@ -1,15 +0,0 @@ -Describe 'Connect-GitHubAccount' { - It 'Function exists' { - Get-Command Connect-GitHubAccount | Should -Not -BeNullOrEmpty - } - - Context 'Parameter Set: autologon IAT' { - It 'Can be called with without parameters' { - { Connect-GitHubAccount } | Should -Not -Throw - } - - It 'Can be called with without parameters - a second time' { - { Connect-GitHubAccount } | Should -Not -Throw - } - } -} diff --git a/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 b/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 deleted file mode 100644 index 811bcd1f3..000000000 --- a/tests/GitHub/Auth/Disconnect-GitHubAccount.Tests.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -Describe 'Disconnect-GitHubAccount' { - It 'Function exists' { - Get-Command Disconnect-GitHubAccount | Should -Not -BeNullOrEmpty - } - - It 'Can be called with no parameters' { - { Disconnect-GitHubAccount } | Should -Not -Throw - } - - It 'Can reconnect after disconnecting' { - { Connect-GitHubAccount } | Should -Not -Throw - } -} diff --git a/tools/dev/UserJourney.ps1 b/tools/dev/UserJourney.ps1 index 8b327f98a..400191fbb 100644 --- a/tools/dev/UserJourney.ps1 +++ b/tools/dev/UserJourney.ps1 @@ -3,10 +3,12 @@ ### # Connect to GitHub interactively using GitHub App and Device Flow (User Access Token, UAT) -Connect-GitHub (-Host github.com) (-ClientID '') +Connect-GitHub (-Host github.com) (-ClientID '') # First should set default context # Log on to a specific instance of GitHub (enterprise) -Connect-GitHub -Host 'msx.ghe.com' +Connect-GitHub -Host 'msx.ghe.com' # Adds context, but is not default +Connect-GitHub -Host 'msx.ghe.com' -Default # Can be added as default by setting the default flag +Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug' # Contexts should be selectable/overrideable on any call # Connect to GitHub interactively using OAuth App and Device Flow (should not use this, should we even support it?) Connect-GitHub -Mode 'OAuthApp' -Scope 'gist read:org repo workflow' @@ -31,6 +33,29 @@ Connect-GitHub -Token *********** # When you connect, a context is saved. # Variables, stored under "Contexts" on the existing config.json. # Secrets, names are stored in the variables. +# Context = [ +# { +# name: "github.com/MariusStorhaug" +# id: 1 +# host: "github.com" -> Public +# default: true +# type: UAT +# }, +# { +# name: "github.com/qweqweqwe" +# id: 1 +# host: "github.com" +# default: false +# type: UAT +# }, +# { +# name: "dnb.ghe.com/Marius-Storhaug" +# id: 2 +# host: "dnb.ghe.com" +# default: false +# type: UAT +# } +# ] <# $Config = @{ ConfigFilePath = 'C:\Repos\GitHub\PSModule\src\functions\private\Config\config.json' @@ -64,4 +89,14 @@ Disconnect-GitHub -Context 'name' # Removes the context variables and secrets # Calling specific functions with context or an ad-hoc token? +Get-GitHubRepository Get-GitHubRepository -Context 'msx.ghe.com/MariusStorhaug' + + + +Connect-GitHub -ClientID '' -PrivateKey '' +Get-GitHubOrganization +# foreach (org) { +# Connect-GitHub -Token *********** +# Get-GitHubRepository +# } diff --git a/tools/dev/contexts.ps1 b/tools/dev/contexts.ps1 index bc4c8f14b..8e6220dca 100644 --- a/tools/dev/contexts.ps1 +++ b/tools/dev/contexts.ps1 @@ -4,8 +4,8 @@ ApiVersion = $ApiVersion HostName = $HostName AuthType = $authType # 'UAT', 'PAT', 'IAT', 'APP' - Secret = $tokenResponse.access_token - SecretType = $AccessTokenType # 'UAT', 'PAT classic' 'PAT modern', 'PEM', 'IAT' + Token = $tokenResponse.access_token + TokenType = $AccessTokenType # 'UAT', 'PAT classic' 'PAT modern', 'PEM', 'IAT' id = 'MariusStorhaug' # username/slug, clientid } UAT = @{ @@ -13,7 +13,7 @@ DeviceFlowType = $Mode UATGHA = @{ - SecretExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) + TokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.expires_in) RefreshToken = $tokenResponse.refresh_token RefreshTokenExpirationDate = (Get-Date).AddSeconds($tokenResponse.refresh_token_expires_in) } @@ -23,14 +23,14 @@ } } PAT = @{ - Secret = $accessTokenValue + Token = $accessTokenValue AccessTokenType = $accessTokenType } APP = @{ - Secret = $PEM + Token = $PEM } # => Generates JWT when used towards an org/user IAT = @{ - Secret = $AccessToken + Token = $AccessToken AccessTokenType = $accessTokenType } } diff --git a/tools/dev/store.ps1 b/tools/dev/store.ps1 index 4542c05d0..7112807e2 100644 --- a/tools/dev/store.ps1 +++ b/tools/dev/store.ps1 @@ -1,19 +1,19 @@ -Set-Store -Name 'PSModule.Store' -Secret 'qwe' -Metadata @{ +Set-Context -Name 'PSModule.Store' -Secret 'qwe' -Metadata @{ SecretVaultName = 'SecretStore' SecretVaultType = 'Microsoft.PowerShell.SecretStore' } -Set-StoreConfig -Name SecretVaultName -Value $null -Store 'PSModule.Store' +Set-ContextSetting -Name SecretVaultName -Value $null -Context 'PSModule.Store' -Get-StoreConfig -Name SecretVaultName -Store 'PSModule.Store' +Get-ContextSetting -Name SecretVaultName -Context 'PSModule.Store' -Get-Store -Name 'PSModule.Store' +Get-Context -Name 'PSModule.Store' Set-Secret -Name 'PSModule.GitHub' -Secret 'qwe' -Metadata @{ defaultContext = 'github.com/MariusStorhaug' } -Get-Store -Name 'PSModule.GitHub' -AsPlainText +Get-Context -Name 'PSModule.GitHub' -AsPlainText Set-Secret -Name 'GitHubPowerShell/github.com/MariusStorhaug' -Secret 'qwe' -Metadata @{ Username = 'MariusStorhaug' diff --git a/tools/utilities/New-Function.ps1 b/tools/utilities/New-Function.ps1 new file mode 100644 index 000000000..f58eafa12 --- /dev/null +++ b/tools/utilities/New-Function.ps1 @@ -0,0 +1,53 @@ +function New-Function { + <# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .EXAMPLE + An example + + .NOTES + General notes + #> + [CmdletBinding(SupportsShouldProcess)] + param( + # This parameter is mandatory + [Parameter(Mandatory)] + [string]$Name, + + # This parameter is mandatory + [Parameter(Mandatory)] + [string]$Value + ) + + begin { + $commandName = $MyInvocation.MyCommand.Name + Write-Verbose "[$commandName] - Start" + Write-Verbose 'Begin' + } + + process { + try { + Write-Verbose 'Process' + if ($PSCmdlet.ShouldProcess('Target', 'Operation')) { + Write-Verbose "Name: $Name" + Write-Verbose "Value: $Value" + } + } catch { + Write-Verbose "Error: $_" + } finally { + Write-Verbose 'Finally' + } + } + + end { + Write-Verbose "[$commandName] - End" + } + + clean { + Write-Verbose 'Clean' + } +}