forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestFx-Tasks.psm1
153 lines (121 loc) · 5.71 KB
/
TestFx-Tasks.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
[CmdletBinding]
Function Set-TestEnvironment
{
<#
.SYNOPSIS
This cmdlet helps you to setup Test Environment for running tests
In order to successfully run a test, you will need SubscriptionId, TenantId
This cmdlet will only prompt you for Subscription and Tenant information, rest all other parameters are optional
#>
[CmdletBinding(DefaultParameterSetName='UserIdParamSet')]
param(
[Parameter(ParameterSetName='UserIdParamSet', Mandatory=$true, HelpMessage = "UserId (OrgId) you would like to use")]
[ValidateNotNullOrEmpty()]
[string]$UserId,
[Parameter(ParameterSetName='UserIdParamSet', Mandatory=$true, HelpMessage = "UserId (OrgId) you would like to use")]
[ValidateNotNullOrEmpty()]
[string]$Password,
[Parameter(ParameterSetName='SpnParamSet', Mandatory=$true, HelpMessage='ServicePrincipal/ClientId you would like to use')]
[ValidateNotNullOrEmpty()]
[string]$ServicePrincipal,
[Parameter(ParameterSetName='SpnParamSet', Mandatory=$true, HelpMessage='ServicePrincipal Secret/ClientId Secret you would like to use')]
[ValidateNotNullOrEmpty()]
[string]$ServicePrincipalSecret,
[Parameter(ParameterSetName='SpnParamSet', Mandatory=$true)]
[Parameter(ParameterSetName='UserIdParamSet', Mandatory=$true, HelpMessage = "SubscriptionId you would like to use")]
[ValidateNotNullOrEmpty()]
[string]$SubscriptionId,
[Parameter(ParameterSetName='SpnParamSet', Mandatory=$true, HelpMessage='AADTenant/TenantId you would like to use')]
[ValidateNotNullOrEmpty()]
[string]$TenantId,
[ValidateSet("Playback", "Record", "None")]
[string]$RecordMode='Playback',
[ValidateSet("Prod", "Dogfood", "Current", "Next")]
[string]$TargetEnvironment='Prod'
)
[string]$uris="https://management.azure.com/"
$formattedConnStr = [string]::Format("SubscriptionId={0};HttpRecorderMode={1};Environment={2}", $SubscriptionId, $RecordMode, $TargetEnvironment)
if([string]::IsNullOrEmpty($UserId) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";UserId={0}"), $UserId)
}
if([string]::IsNullOrEmpty($Password) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";Password={0}"), $Password)
}
if([string]::IsNullOrEmpty($TenantId) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";AADTenant={0}"), $TenantId)
}
if([string]::IsNullOrEmpty($ServicePrincipal) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";ServicePrincipal={0}"), $ServicePrincipal)
}
if([string]::IsNullOrEmpty($ServicePrincipalSecret) -eq $false)
{
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";ServicePrincipalSecret={0}"), $ServicePrincipalSecret)
}
$formattedConnStr = [string]::Format([string]::Concat($formattedConnStr, ";BaseUri={0}"), $uris)
Write-Host "Below connection string is ready to be set"
Print-ConnectionString $UserId $Password $SubscriptionId $TenantId $ServicePrincipal $ServicePrincipalSecret $RecordMode $TargetEnvironment $uris
#Set connection string to Environment variable
$env:TEST_CSM_ORGID_AUTHENTICATION=$formattedConnStr
Write-Host ""
# Retrieve the environment variable
Write-Host ""
Write-Host "Below connection string was set. Start Visual Studio by typing devenv" -ForegroundColor Green
[Environment]::GetEnvironmentVariable($envVariableName)
Write-Host ""
Write-Host "If your needs demand you to set connection string differently, for all the supported Key/Value pairs in connection string"
Write-Host "Please visit https://github.com/Azure/azure-powershell/blob/dev/documentation/Using-Azure-TestFramework.md" -ForegroundColor Yellow
}
Function Print-ConnectionString([string]$uid, [string]$pwd, [string]$subId, [string]$aadTenant, [string]$spn, [string]$spnSecret, [string]$recordMode, [string]$targetEnvironment, [string]$uris)
{
if([string]::IsNullOrEmpty($uid) -eq $false)
{
Write-Host "UserId=" -ForegroundColor Green -NoNewline
Write-Host $uid";" -NoNewline
}
if([string]::IsNullOrEmpty($pwd) -eq $false)
{
Write-Host "Password=" -ForegroundColor Green -NoNewline
Write-Host $pwd";" -NoNewline
}
if([string]::IsNullOrEmpty($subId) -eq $false)
{
Write-Host "SubscriptionId=" -ForegroundColor Green -NoNewline
Write-Host $subId";" -NoNewline
}
if([string]::IsNullOrEmpty($aadTenant) -eq $false)
{
Write-Host "AADTenant=" -ForegroundColor Green -NoNewline
Write-Host $aadTenant";" -NoNewline
}
if([string]::IsNullOrEmpty($spn) -eq $false)
{
Write-Host "ServicePrincipal=" -ForegroundColor Green -NoNewline
Write-Host $spn";" -NoNewline
}
if([string]::IsNullOrEmpty($spnSecret) -eq $false)
{
Write-Host "ServicePrincipalSecret=" -ForegroundColor Green -NoNewline
Write-Host $spnSecret";" -NoNewline
}
if([string]::IsNullOrEmpty($recordMode) -eq $false)
{
Write-Host "HttpRecorderMode=" -ForegroundColor Green -NoNewline
Write-Host $recordMode";" -NoNewline
}
if([string]::IsNullOrEmpty($targetEnvironment) -eq $false)
{
Write-Host "Environment=" -ForegroundColor Green -NoNewline
Write-Host $targetEnvironment";" -NoNewline
}
if([string]::IsNullOrEmpty($uris) -eq $false)
{
Write-Host "BaseUri=" -ForegroundColor Green -NoNewline
Write-Host $uris -NoNewline
}
Write-Host ""
}
export-modulemember -Function Set-TestEnvironment