-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghe_config.psm1
110 lines (88 loc) · 3.04 KB
/
ghe_config.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#
# ghe_config.psm1 : GheConfig Exported Functions
#
Function Get-GheConfig
{
<#
.SYNOPSIS
Get GitHub Enterprise Server's configuration.
.DESCRIPTION
The returned object is a Dictionnary containing part or all GitHub Enterprise
Server configuration parameters.
The Filter parameter is a RegEx string allowing to reduce the scope of requested
configuration.
.PARAMETER ServerUri
Full GitHub Enterprise Server URI, including protocol (http or https)
.PARAMETER AdminToken
GitHub Enterprise Administrator token
.PARAMETER SshKeyPath
SSH RSA private key path used to connect to GitHub Enterprise server with SSH
.PARAMETER SshHostPort
SSH port used to connect to GitHub Enterprise server (default is 122)
.PARAMETER GheClient
GheClient object previously created with Get-GheClient (pipeline value)
.PARAMETER Filter
Expression used to limit the configuration result keys to RegEx evaluation.
.OUTPUTS
[GheConfig]
.EXAMPLE
# Return the full GitHub Enterprise Configuration
$Params = @{
ServerUri = "http://github.mycompany.com/"
AdminToken = "636e3227468e4e09f397e3ecb26860eed9fbeaff"
SshKeyPath = join-path $env:HOMEPATH ".ssh/github.mycompany.com_rsa"
}
Get-GheConfig @Params
.EXAMPLE
# Return configuration for smtp, ldap and core
$Params = @{
ServerUri = "http://github.mycompany.com/"
AdminToken = "636e3227468e4e09f397e3ecb26860eed9fbeaff"
SshKeyPath = join-path $env:HOMEPATH ".ssh/github.mycompany.com_rsa"
}
Get-GheClient @Params | Get-GheConfig -Filter "^(smtp|ldap|core)\..*$"
.NOTES
Before using this script, create a SSH key and upload it onto GitHub instance.
https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
https://help.github.com/enterprise/admin/guides/installation/administrative-shell-ssh-access/
.LINK
Get-GheClient
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, ParameterSetName = "Connect")]
[ValidateNotNullOrEmpty()]
[String] $ServerUri,
[Parameter(Mandatory=$true, ParameterSetName = "Connect")]
[ValidateNotNullOrEmpty()]
[String] $AdminToken,
[Parameter(Mandatory=$true, ParameterSetName = "Connect")]
[ValidateNotNullOrEmpty()]
[String] $SshKeyPath,
[Parameter(Mandatory=$false, ParameterSetName = "Connect")]
[UInt16] $SshHostPort = 122,
[Parameter(Mandatory=$true, ParameterSetName = "Session", ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[GheClient] $GheClient,
[Parameter(Mandatory=$false)]
[String] $Filter
)
Begin
{
Write-Debug "PsBoundParameters:"
$PSBoundParameters.GetEnumerator() | % { Write-Debug $_ }
if($PSBoundParameters['Debug']) { $DebugPreference = 'Continue' }
Write-Debug "DebugPreference: $DebugPreference"
Write-Verbose "$($MyInvocation.MyCommand.Name):: Function started"
}
Process
{
if ($PSCmdlet.ParameterSetName -eq "Connect")
{ $GheClient = [GheClient]::new($ServerUri, $AdminToken, $SshHostPort, $SshKeyPath) }
return [GheConfig]::new($GheClient, $Filter)
}
End
{
Write-Verbose "$($MyInvocation.MyCommand.Name):: Function ended"
}
}