Skip to content

Commit

Permalink
Add tests for and InvokeSecretVault
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Sep 9, 2023
1 parent cb872e0 commit 178dde5
Show file tree
Hide file tree
Showing 3 changed files with 489 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/GitHub.Core/Private/Initialize-SecretVault.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#Requires -Version 7
#Requires -Modules Microsoft.PowerShell.SecretManagement, Microsoft.PowerShell.SecretStore

function Initialize-SecretVault {
[CmdletBinding()]
param (
[Parameter()]
[string] $Name = 'SecretStore',

[Parameter()]
[Alias('ModuleName')]
[string] $Type = 'Microsoft.PowerShell.SecretStore'
)

$secretVault = Get-SecretVault | Where-Object { $_.ModuleName -eq $Type }
$secretVaultExists = $secretVault.count -ne 0
Write-Verbose "$Name exists: $secretVaultExists"
if (-not $secretVaultExists) {
Write-Verbose "Registering [$Name]"
$vaultParameters = @{
Authentication = 'None'
PasswordTimeout = -1
Interaction = 'None'
Scope = 'CurrentUser'
WarningAction = 'SilentlyContinue'
Confirm = $false
Force = $true
}
Reset-SecretStore @vaultParameters

$secretVault = @{
Name = $Name
ModuleName = $Type
DefaultVault = $true
Description = 'SecretStore'
}
Register-SecretVault @secretVault
}
Get-SecretStoreConfiguration
}
38 changes: 38 additions & 0 deletions src/GitHub.Core/Public/Invoke-GitHubAPI.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function Invoke-GitHubAPI {
[CmdletBinding()]
param (
[Parameter()]
[ValidateSet('GET', 'POST', 'PATCH', 'DELETE')]
[String] $Method = 'GET',

[Parameter()]
[string] $APIEndpoint,

[Parameter()]
[hashtable] $Body = @{},

[Parameter()]
[string] $Owner = $script:Owner,

[Parameter()]
[string] $Repo = $script:Repo,

[Parameter()]
[string] $Token = $script:Token
)
$APICall = @{
Uri = ("$script:APIBaseURI/$APIEndpoint").Replace('\', '/').Replace('//', '/')
Headers = @{
Authorization = "token $Token"
'Content-Type' = 'application/vnd.github.v3+json' #'application/json'
}
Method = $Method
Body = $Body | ConvertTo-Json -Depth 100
}
try {
$Response = Invoke-RestMethod @APICall
} catch {
throw $_
}
return $Response
}
Loading

0 comments on commit 178dde5

Please sign in to comment.