From 6dd2f99c8061f3336d06e560bc7c4e4cdb24718f Mon Sep 17 00:00:00 2001 From: shahabhijeet Date: Wed, 16 Nov 2016 09:04:07 -0800 Subject: [PATCH 1/5] refactoring task modules --- tools/Modules/TestFx-Tasks.psd1 | Bin 0 -> 7796 bytes tools/Modules/TestFx-Tasks.psm1 | 255 ++++++++++++++++++++++++ tools/Modules/Tests/CommonTestUtil.psm1 | 19 ++ tools/Modules/Tests/RepoModuleTests.ps1 | 7 + 4 files changed, 281 insertions(+) create mode 100644 tools/Modules/TestFx-Tasks.psd1 create mode 100644 tools/Modules/TestFx-Tasks.psm1 create mode 100644 tools/Modules/Tests/CommonTestUtil.psm1 create mode 100644 tools/Modules/Tests/RepoModuleTests.ps1 diff --git a/tools/Modules/TestFx-Tasks.psd1 b/tools/Modules/TestFx-Tasks.psd1 new file mode 100644 index 0000000000000000000000000000000000000000..f5bcc35723c69d6faa0bc9508f125bb0df0e9d84 GIT binary patch literal 7796 zcmd^^Yi}Dx6o%(B692(cJ|smXB~a3Wgj6eO+DM^PxfH%SzST6oU^`7K)V~hA&m5o3 zj(0b4LW&T`vUhiO=FEHU=ZydSV=a6hJ_~E15q=Eg&DHC(kF2fw4t%y5~jqJ;VEKRre%n>!U1M`8n^LzY$Z8-YEahK=wb)80YY)A)rXV3sr&J)W`I-*oMY zB3c`0f9#H3dT|7;xIPl^@bNsH2BT|y?u5s(r(XCjJkh5m>)zJLqwuZn9?8mf!Z*4* z)8~oqH#N?@$J%j6W7~0MPjhlfHH8igW@Fds15EjB!&T=k`94X)qsX`I_by7Kv*PYK zjhB+aQ0q-6>$28C^r3OI|DL!iBbaD!ysR&di6X=j^AaebmlRp*H3N=iN+yd9A$TAf z?(_ArWJ|M}vWjzE6C(U_DkRv^G$5UhtUKppFTPLF!aXbL4w>|#^|i&3y>DqJEFUYJ zi1t|2%^E%O<*^~R#Wk&}+t)bHF`^4>e<&0~t%Z}RxT?nbbDWJ8Txw23p2r<4uq}KC zDWRW!oC$wO3C|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Fx-Tasks.psm1 new file mode 100644 index 000000000000..a3766e8a1c59 --- /dev/null +++ b/tools/Modules/TestFx-Tasks.psm1 @@ -0,0 +1,255 @@ +Function Get-ActiveDirectoryApp +{ + param( + [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] + [ValidateNotNullOrEmpty()] + [string]$ADAppDisplayName, + + [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] + [ValidateNotNullOrEmpty()] + [string]$SubscriptionId, + + [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] + [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47", + + [Parameter(Mandatory=$false, HelpMessage="True: AD App is created if does not exist")] + [bool]$createADAppIfNotFound = $false, + + [Parameter(Mandatory=$false, HelpMessage="True: AD SPN is created if does not exist")] + [bool]$createADSpnIfNotFound = $false + + ) + + $displayName = $ADAppDisplayName + $homePage = "http://www.$displayName.com" + $identityUri = "http://$displayName" + + Select-AzureRmSubscription -SubscriptionId $SubscriptionId -TenantId $TenantId + $azSub = Get-AzureRmSubscription -SubscriptionId $SubscriptionId + + if($azSub -ne $null) + { + if($azSub.SubscriptionId -ne $SubscriptionId) + { + throw [System.ApplicationException] "'$SubscriptionId' subscriptionId is not selected'. Exiting......" + } + } + + $azAdApp = Get-AzureRmADApplication -DisplayNameStartWith $displayName + if($azAdApp -eq $null -and $createADAppIfNotFound -eq $true) + { + $azAdApp = New-AzureRmADApplication -DisplayName $displayName -HomePage $homePage -IdentifierUris $identityUri + } + + if($azAdApp -ne $null -and $createADSpnIfNotFound -eq $true) + { + $adAppSpn = New-AzureRmADServicePrincipal -ApplicationId $psAutoADApp.ApplicationId + } + else + { + throw [System.ApplicationException] "Unable to create new Azure AD Applicaiton using 'New-AzureRmADApplication'. Exiting......" + } + + Get-ADAppSpnDetails -AdApp $azAdApp -AdSpn $adAppSpn +} + +[cmdletBinding] +Function Get-ADAppSpnDetails +{ + param( + [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication")] + [Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADApplication] $AdApp, + + [Parameter(Mandatory=$false, HelpMessage="Azure AD ServicePrincipal")] + [Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADServicePrincipal] $AdSpn + ) + + if($AdApp -ne $null) + { + Write-Host "AD App Info" + Write-Host $AdApp + } + + if($AdSpn -ne $null) + { + Write-Host "AD SPN Info" + Write-Host $AdSpn + } +} + +[cmdletBinding] +Function Get-ServicePrincipal +{ + param( + [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] + [string]$ADAppDisplayName, + + [Parameter(Mandatory=$false, HelpMessage="Please provide the role that needs to be assigned to ServicePrinciple")] + [string]$Role, + + [Parameter(Mandatory=$false, HelpMessage="True: Spn is created if does not exist")] + [bool]$createIfNotFound = $false + ) + + +} + + +[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 +export-modulemember -Function Create-Spn \ No newline at end of file diff --git a/tools/Modules/Tests/CommonTestUtil.psm1 b/tools/Modules/Tests/CommonTestUtil.psm1 new file mode 100644 index 000000000000..a055396cc212 --- /dev/null +++ b/tools/Modules/Tests/CommonTestUtil.psm1 @@ -0,0 +1,19 @@ +Function Log-Info +{ + [CmdletBinding()] + param( [string] [Parameter(Position=0)] $info = "") + + $info = [string]::Format("[INFO]: {0}", $info) + Write-Host $info -ForegroundColor Yellow +} + + +function Write-Log +{ + [CmdletBinding()] + param( [Object] [Parameter(Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$false)] $obj = "") + PROCESS + { + $obj | Out-String | Write-Verbose + } +} \ No newline at end of file diff --git a/tools/Modules/Tests/RepoModuleTests.ps1 b/tools/Modules/Tests/RepoModuleTests.ps1 new file mode 100644 index 000000000000..7cf6a172bdeb --- /dev/null +++ b/tools/Modules/Tests/RepoModuleTests.ps1 @@ -0,0 +1,7 @@ +Function CreateAdApp_Test +{ + $adDisplayName = "TestAdAppForNodeCliTestCase" + $subId = '2c224e7e-3ef5-431d-a57b-e71f4662e3a6' + + +} From f4f759810644e1456329aa5cab45c08c1d1cf99b Mon Sep 17 00:00:00 2001 From: shahabhijeet Date: Wed, 16 Nov 2016 09:04:46 -0800 Subject: [PATCH 2/5] missed Refactoring modules --- tools/Repo-Tasks.psd1 | Bin 8118 -> 8194 bytes tools/Repo-Tasks.psm1 | 152 ------------------------------------------ 2 files changed, 152 deletions(-) diff --git a/tools/Repo-Tasks.psd1 b/tools/Repo-Tasks.psd1 index f8e52b1f750b904acccc7d02e80173044542fbe2..5d1825daf811ac9aeaa58cf56af7fb55b5bc3646 100644 GIT binary patch delta 137 zcmdmH-{i327>l?gLlr|QLlHwNg91Y^gA0QE$ns^#XGj66$N{SKV@PDk1sh}wlu>600kVr3N*LT2Du9ND0A-6A TvVm9~C|k<_G;8y3p4~zK8?GE9 delta 36 ucmV+<0Nek9K(;@y#sras7_;64@&}VZ2n3VZ4G@#y3>cH10uHlQ4XhFw77hRa diff --git a/tools/Repo-Tasks.psm1 b/tools/Repo-Tasks.psm1 index d67b1bdbc487..ea09c9d5993e 100644 --- a/tools/Repo-Tasks.psm1 +++ b/tools/Repo-Tasks.psm1 @@ -4,158 +4,6 @@ $userPsFileDir = [string]::Empty [string]$envVariableName="TEST_CSM_ORGID_AUTHENTICATION" -[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 "" -} - [CmdletBinding] Function Get-BuildScopes { From dcb9cc7aafb63513cbdb3078f0792412d2b88b45 Mon Sep 17 00:00:00 2001 From: shahabhijeet Date: Wed, 16 Nov 2016 18:14:06 -0800 Subject: [PATCH 3/5] Making modular modules for various tasks --- tools/Modules/Build-Tasks.psd1 | 127 +++++++++++ tools/Modules/Build-Tasks.psm1 | 99 ++++++++ tools/Modules/Foo.ps1 | 286 ++++++++++++++++++++++++ tools/Modules/TestFx-Tasks.psd1 | Bin 7796 -> 3907 bytes tools/Modules/TestFx-Tasks.psm1 | 41 +++- tools/Modules/Tests/CommonTestUtil.psd1 | Bin 0 -> 7774 bytes tools/Modules/Tests/CommonTestUtil.psm1 | 4 +- tools/PS-VSPrompt.lnk | Bin 2210 -> 2180 bytes tools/PSRepoStart.cmd | 4 + tools/Repo-Tasks.psd1 | Bin 8194 -> 4055 bytes tools/Repo-Tasks.psm1 | 101 +-------- 11 files changed, 561 insertions(+), 101 deletions(-) create mode 100644 tools/Modules/Build-Tasks.psd1 create mode 100644 tools/Modules/Build-Tasks.psm1 create mode 100644 tools/Modules/Foo.ps1 create mode 100644 tools/Modules/Tests/CommonTestUtil.psd1 create mode 100644 tools/PSRepoStart.cmd diff --git a/tools/Modules/Build-Tasks.psd1 b/tools/Modules/Build-Tasks.psd1 new file mode 100644 index 000000000000..5d32dd30d56c --- /dev/null +++ b/tools/Modules/Build-Tasks.psd1 @@ -0,0 +1,127 @@ +# +# Module manifest for module 'Build-Tasks' +# +# Generated by: abhishah +# +# Generated on: 11/16/2016 +# + +@{ + +# Script module or binary module file associated with this manifest. +RootModule = 'Build-Tasks.psm1' + +# Version number of this module. +ModuleVersion = '1.0' + +# Supported PSEditions +# CompatiblePSEditions = @() + +# ID used to uniquely identify this module +GUID = 'cda2be3c-14a7-4c83-9393-d5ebad9df7e4' + +# Author of this module +Author = 'abhishah' + +# Company or vendor of this module +CompanyName = 'Microsoft' + +# Copyright statement for this module +Copyright = '(c) 2016 abhishah. All rights reserved.' + +# Description of the functionality provided by this module +# Description = '' + +# Minimum version of the Windows PowerShell engine required by this module +# PowerShellVersion = '' + +# Name of the Windows PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the Windows PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# CLRVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +# RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = 'Get-BuildScopes', 'Start-Build', 'Invoke-CheckinTests', + 'Install-VSProjectTemplates' + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = @() + +# Variables to export from this module +# VariablesToExport = @() + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = @() + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + # External dependent modules of this module + # ExternalModuleDependencies = '' + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} + diff --git a/tools/Modules/Build-Tasks.psm1 b/tools/Modules/Build-Tasks.psm1 new file mode 100644 index 000000000000..c6b235dd056a --- /dev/null +++ b/tools/Modules/Build-Tasks.psm1 @@ -0,0 +1,99 @@ +[CmdletBinding] +Function Get-BuildScopes +{ +<# +.SYNOPSIS +You can build a particular package rather than doing a full build by providing Build Scope. +This cmdlet will help to identify existing Scope available +This will enable to execute Start-RepoBuild + +#> + + Write-Host "Below are available scopes you can specify for building specific projects" + Write-Host "" + Get-ChildItem -path "$env:repoRoot\src\ResourceManager" -dir | Format-Wide -Column 5 | Format-Table -Property Name + Write-Host "e.g of a scope would be 'ResourceManager\Compute'" -ForegroundColor Yellow + + Get-ChildItem -path "$env:repoRoot\src\ServiceManagement" -dir -Exclude "ResourceManager" | Format-Wide -Column 5 | Format-Table -Property Name + Write-Host "e.g of a scope would be 'ServiceManagement\ExpressRoute'" -ForegroundColor Yellow +} + +[CmdletBinding] +Function Start-Build +{ +<# +.SYNOPSIS +This cmdlet will help to do either with full build or targeted build for specific scopes. + +.PARAMETER BuildScope +Use Get-BuildScope cmdLet to get list of existing scopes that can be used to build +#> + param( + [parameter(Mandatory=$false, Position=0, HelpMessage='BuildScope that you would like to use. For list of build scopes, run List-BuildScopes')] + [string]$BuildScope + ) + + if([string]::IsNullOrEmpty($BuildScope) -eq $true) + { + Write-Host "Starting Full build" + msbuild.exe "$env:repoRoot\build.proj" /t:Build + } + else + { + Write-Host "Building $BuildScope" + msbuild.exe "$env:repoRoot\build.proj" /t:Build /p:Scope=$BuildScope + } +} + +[CmdletBinding] +Function Invoke-CheckinTests +{ +<# +.SYNOPSIS +Runs all the check in tests +#> + Write-Host "cmdline Args: msbuild.exe $env:repoRoot\build.proj /t:Test" + msbuild.exe "$env:repoRoot\build.proj" /t:Test +} + +[cmdletBinding] +Function Install-VSProjectTemplates +{ +<# +.SYNOPSIS + +Install-VSProjectTemplates will install getting started project templates for +1) Autorest-.NET SDKProject +2) .NET SDK Test projectct + +After executing the cmdlet, restart VS (if already open), create new project +Search for the project template as we install the following three project templates +AutoRest-AzureDotNetSDK +AzureDotNetSDK-TestProject +AzurePowerShell-TestProject +#> + if($env:VisualStudioVersion -eq "14.0") + { + if((Test-Path "$env:repoRoot\tools\ProjectTemplates\") -eq $true) + { + Write-Host "Installing VS templates for 'AutoRest as well as Test Project'" + Copy-Item "$env:repoRoot\tools\ProjectTemplates\*.zip" "$env:USERPROFILE\Documents\Visual Studio 2015\Templates\ProjectTemplates\" + Write-Host "Installed VS Test Project Templates for Powershell test projects" + Write-Host "" + Write-Host "Restart VS (if already open), search for 'AzurePowerShell-TestProject'" -ForegroundColor Yellow + } + else + { + Write-Host "Missing templates to install, make sure you have project templates available in the repo under $env:repoRoot\tools\ProjectTemplates\" + } + } + else + { + Write-Host "Unsupported VS Version detected. Visual Studio 2015 is the only supported version for current set of project templates" + } +} + +export-modulemember -Function Get-BuildScopes +export-modulemember -Function Start-Build +export-modulemember -Function Invoke-CheckinTests +export-modulemember -Function Install-VSProjectTemplates \ No newline at end of file diff --git a/tools/Modules/Foo.ps1 b/tools/Modules/Foo.ps1 new file mode 100644 index 000000000000..5720d05b25d8 --- /dev/null +++ b/tools/Modules/Foo.ps1 @@ -0,0 +1,286 @@ +Function Get-ActiveDirectoryApp +{ + param( + [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] + [ValidateNotNullOrEmpty()] + [string]$ADAppDisplayName, + + [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] + [ValidateNotNullOrEmpty()] + [string]$SubscriptionId, + + [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] + [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47", + + [Parameter(Mandatory=$false, HelpMessage="True: AD App is created if does not exist")] + [bool]$createADAppIfNotFound = $false, + + [Parameter(Mandatory=$false, HelpMessage="True: AD SPN is created if does not exist")] + [bool]$createADSpnIfNotFound = $false + + ) + + $displayName = $ADAppDisplayName + $homePage = "http://www.$displayName.com" + $identityUri = "http://$displayName" + + Select-AzureRmSubscription -SubscriptionId $SubscriptionId -TenantId $TenantId + $azSub = Get-AzureRmSubscription -SubscriptionId $SubscriptionId + + if($azSub -ne $null) + { + if($azSub.SubscriptionId -ne $SubscriptionId) + { + throw [System.ApplicationException] "'$SubscriptionId' subscriptionId is not selected'. Exiting......" + } + } + + $azAdApp = Get-AzureRmADApplication -DisplayNameStartWith $displayName + if($azAdApp -eq $null -and $createADAppIfNotFound -eq $true) + { + $azAdApp = New-AzureRmADApplication -DisplayName $displayName -HomePage $homePage -IdentifierUris $identityUri + } + + if($azAdApp -ne $null -and $createADSpnIfNotFound -eq $true) + { + $adAppSpn = New-AzureRmADServicePrincipal -ApplicationId $psAutoADApp.ApplicationId + } + else + { + throw [System.ApplicationException] "Unable to create new Azure AD Applicaiton using 'New-AzureRmADApplication'. Exiting......" + } + + Get-ADAppSpnDetails -AdApp $azAdApp -AdSpn $adAppSpn +} + +[cmdletBinding] +Function Get-ADAppSpnDetails +{ + param( + [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication")] + [Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADApplication] $AdApp, + + [Parameter(Mandatory=$false, HelpMessage="Azure AD ServicePrincipal")] + [Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADServicePrincipal] $AdSpn + ) + + if($AdApp -ne $null) + { + Write-Host "AD App Info" + Write-Host $AdApp + } + + if($AdSpn -ne $null) + { + Write-Host "AD SPN Info" + Write-Host $AdSpn + } +} + +[cmdletBinding] +Function Get-ServicePrincipal +{ + param( + [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] + [string]$ADAppDisplayName, + + [Parameter(Mandatory=$false, HelpMessage="Please provide the role that needs to be assigned to ServicePrinciple")] + [string]$Role, + + [Parameter(Mandatory=$false, HelpMessage="True: Spn is created if does not exist")] + [bool]$createIfNotFound = $false + ) +} + + +Function Delete-ActiveDirectoryApp +{ + [CmdletBinding(SupportsShouldProcess=$true)] + + param( + [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] + #[ValidateNotNullOrEmpty()] + [string]$ADAppDisplayName, + + [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] + #[ValidateNotNullOrEmpty()] + [string]$SubscriptionId, + + [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] + [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" + + ) + + #process + #{ + if($PSCmdlet.ShouldProcess("$ADAppDisplayName")) + { + Write-Host "ShouldProcess is True" + } + else + { + Write-Host "ShouldProcess is False" + } + + #} + +} + +[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 "" +} + +#Delete-ActiveDirectoryApp -ADAppDisplayName "" -SubscriptionId "" -TenantId "" -WhatIf + +export-modulemember -Function Set-TestEnvironment +export-modulemember -Function Delete-ActiveDirectoryApp + +Delete-ActiveDirectoryApp -ADAppDisplayName "Hello" -SubscriptionId "sub" -TenantId "tenant" \ No newline at end of file diff --git a/tools/Modules/TestFx-Tasks.psd1 b/tools/Modules/TestFx-Tasks.psd1 index f5bcc35723c69d6faa0bc9508f125bb0df0e9d84..3d90bf08399c6b7ff14c353c74aa9d5309ffef95 100644 GIT binary patch literal 3907 zcmc&%T~8Z16n&pxaU~uC5}7tF4YX3FMg%Alu!yAHeOo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CI0NWp(wNa&cAstN2VjQpe^*?kZ$Mz zKxsK1w4B85X~eM8bXiM;4){o-a~gT@6XSHo=PUerJvOY?tdmp9Ga>ZTo-#^0!EyWtiOR8Fa@ODQ zPZRV09!}~&Iymzsi`C#T+rYa(U*9>`qdZv9ybV73Z>+~M66YI4Bce{K`pZ>voj&WS zVR7q)O2KvcQRC?InRq7N+pf7^mSYP0^Q~K5jI1dN)YAdMiztbS{?!@9O5be%;0jZ< zZG)m}HGad|WxkoqS$!|Gl%3BdZ9DO2WT5&wbsv6$XMF=2DRwf}Y2DP#5O;oBL=a>` zw}CI)*(Oi*IEcD#i3f_x-a~C>JzPWoW#Ju;->kFD<*qc#d8BbuTv3+M$E$zu{sN}_ B_zVC5 diff --git a/tools/Modules/TestFx-Tasks.psm1 b/tools/Modules/TestFx-Tasks.psm1 index a3766e8a1c59..b97ae967ab9d 100644 --- a/tools/Modules/TestFx-Tasks.psm1 +++ b/tools/Modules/TestFx-Tasks.psm1 @@ -95,6 +95,39 @@ Function Get-ServicePrincipal } +Function Delete-ActiveDirectoryApp +{ + [CmdletBinding(SupportsShouldProcess=$true)] + + param( + [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] + #[ValidateNotNullOrEmpty()] + [string]$ADAppDisplayName, + + [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] + #[ValidateNotNullOrEmpty()] + [string]$SubscriptionId, + + [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] + [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" + + ) + + #process + #{ + if($PSCmdlet.ShouldProcess("$ADAppDisplayName")) + { + Write-Host "ShouldProcess is True" + } + else + { + Write-Host "ShouldProcess is False" + } + + #} + +} + [CmdletBinding] Function Set-TestEnvironment { @@ -247,9 +280,9 @@ Function Print-ConnectionString([string]$uid, [string]$pwd, [string]$subId, [str Write-Host "" } - - - +#Delete-ActiveDirectoryApp -ADAppDisplayName "" -SubscriptionId "" -TenantId "" -WhatIf export-modulemember -Function Set-TestEnvironment -export-modulemember -Function Create-Spn \ No newline at end of file +export-modulemember -Function Delete-ActiveDirectoryApp + +Delete-ActiveDirectoryApp -ADAppDisplayName "Hello" -SubscriptionId "sub" -TenantId "tenant" -WhatIf \ No newline at end of file diff --git a/tools/Modules/Tests/CommonTestUtil.psd1 b/tools/Modules/Tests/CommonTestUtil.psd1 new file mode 100644 index 0000000000000000000000000000000000000000..ea134357ba87d22a45f2a96e31fdff2c74314b7e GIT binary patch literal 7774 zcmeI1X>VIa6o%(B693^!`H&Qml%%B#5>l-!ZKO0*SqfjhW9kjtXMyGcrtf< z?{(~u0z$~L?=mxI-m{-G{^R!z_oe&7ZMe+6b|cqvSFZ2cdK$R88@itB=xOR^dehPP z#E<0XZMuEEALujE{EPYQOReaM(&n6c*yE+fhx$%LeWq(m^cwD?`%c%o?ta#)sebGF z+L~o6*^!mI`aIP4iGKIoH~ucJ=I(|2&C?6i&RtU&dT#7F1AFA$xNK;2C>#@^LmK%R z9nTw5stfH@V@aCJr+H3r9tH?szDc~cIOh#=F-aC zTQA+I5FnjQ-z&{)__vwfbrw)Xz6?y_8GD)agbtf4o1Z!MeBrj-gG7JF?m+LaBm>)Prk#1lVt>`OEsE%^r~R=w z5On+-^b#}@d54de?$Q}u`!$9T?2Ymgxgb>1@Nb=qD-tDA}Rs*YUox>;U` zZ)qe*?QTP>s`fRGQ;e@g8#^Be#XxJ}WFoH0vHs|1qxoyi$>e3+vEp3%!B3D9dg=O^ z@Q0M}qMpB7m4`CQ$k|?{Yf_9Zfd_!Q)R+JE!LGs*7a*1 zO0FaRSY+N(6?Wpzd|Zr@;_f!@{rAb*I9WxeZ)6qJUc_`Pk?NF+t?6wC8zDwtdE3cU zL!4?3)#ulm_meX96Mt8e3|qQ?dAhdXLGY<{p% zXORu8{t4F8mBoxSAHT5JPCi0bLvJsZgYheJ22!*2dD>9z`jM)7X+xuD!j#Vx`RWlq z;I&x2)x5si!b0WO6OH9O!%bZ}GHd=ExXTfhqfdK>&qc%i09DFVohmPl^>-x zN27GF$i~*2b)IS6VrTj==~IiA6QUt`l9&a(MJ~#H>PS&;=%ck&u@(=oqPF{R6YtO< zmP*x&_Z0g$B73L-us@5O@Hm;jw{s1026L&4ksq9felk;i%-Katc<|ho_enA^xinot zOu}=m9tj?8T@EJ)>|tFhy29>>dYn4YD?puE$vV~0nOm)6qeKnR!PP1fGA}Pm6I~r9 zlC&)J)k6QXFLbRrNB`?!Q3uUirDO6>rC2WeVpe?X?SXS7I}f?5{PDsft#TBbZqWkh zo54Vrd{+ejT`#mwW0`c!0#YfK%f4s<2kOc9~(eQ#ASPes?5C zKK8fOO_5#Txf}&GQ_uIF7W-S`nsct8DG<<=gy)bO@-n;c{G0Z2WID?-ec>R7&{b0V z*M*#11X@mA4|HeP={h)n=gFc_UWe4+`A!)-NUeY;vLQ1A&3H=7Nq>1yZeEkhG@>#M z#1s5XRQROWt7e7S8(MK8R9&x?x~z5VW1Uq!GcTd?sv^i0uOuVexfv%1(Y{l?A|-r| zlR)yhWq4$6XA8(5N?qZ>mzZOHkVzt74%ZZW(IUgVaAkf?-%EM@iLQ}5cI|5~;>vK& zPpFuxxW`Ka<#1&Od?eDj^gM)9;&{dvR)p(vY*?*XC#RGRAq=NIMU-@cBlnBu(dSo7 z&ib1$@2}ysDh|HUq{V7*m~GgZ%(Bk88s+hv<~sQ3zp)<6NStpFjfgt2>MvHwRr;)^ zhQ)2>YQ><-PkN6&4mQt%WY1@fEZ+fb)WA_nG@T_k@Bl+BIG3T~!hPd;?Jc1w- zx($5U&Ng|f#zEA@k2u3QR#XoE&21+gS*HK3@Q#4rth31FzBJ2uq;Zp9QIyfAn}6#5 E1c_Ajf&c&j literal 0 HcmV?d00001 diff --git a/tools/Modules/Tests/CommonTestUtil.psm1 b/tools/Modules/Tests/CommonTestUtil.psm1 index a055396cc212..9174a2e7c661 100644 --- a/tools/Modules/Tests/CommonTestUtil.psm1 +++ b/tools/Modules/Tests/CommonTestUtil.psm1 @@ -16,4 +16,6 @@ function Write-Log { $obj | Out-String | Write-Verbose } -} \ No newline at end of file +} +export-modulemember -Function Log-Info +export-modulemember -Function Write-Log \ No newline at end of file diff --git a/tools/PS-VSPrompt.lnk b/tools/PS-VSPrompt.lnk index 3df2242b3e1c1df137a4cf07f2bf3a259a77c62a..560dc664b6d7530ca5fa501ec0ef3cda146b796f 100644 GIT binary patch delta 52 zcmZ1^*dn;$GNZa8gFZtxg93vRLjXfCLl8qMLjglRkX6Ev$WR0%^%#;Fav4%KOE7h@ F0RSwp3ikj2 delta 82 zcmZn>TqL;RGNY>jgFZtxg93vR5UMhSF$6OhGMF$JFgP>#Gx#$2F@ykVe+D0*I7qgb e!G$4}p$sUS%aFpL$B@L3$WX$dwD}if7aIU(hz~~q diff --git a/tools/PSRepoStart.cmd b/tools/PSRepoStart.cmd new file mode 100644 index 000000000000..389dd8c925aa --- /dev/null +++ b/tools/PSRepoStart.cmd @@ -0,0 +1,4 @@ +@echo off +SET currDir=%~dp0 +SET PSModulePath=%PSModulePath%;%currDir%\Modules +"%VS140COMNTOOLS%VsDevCmd.bat" diff --git a/tools/Repo-Tasks.psd1 b/tools/Repo-Tasks.psd1 index 5d1825daf811ac9aeaa58cf56af7fb55b5bc3646..4d07c6140f2916c742240363bddd38a8ba3ab1a9 100644 GIT binary patch literal 4055 zcmc&%U2oeq6n)pPxIi9~0I^)BMV1yQP%lo}U`ZClX}5>I&=PI2kw}%K?07@}`wl-W z%TAg#1GeQQFh!nwcs~z!k{!BKc~f$#m=sfPEKQZBDy;3^@LKh5nYlB&$qx3u=aOq? zc}|n%8!`ne*rX6&IJaA$m3%{kL4R=6KYTGb!pG#@p9uiQnHIHO;lt8INT!#og{c4& zW{k>&x3UnnAX^C2(o2&YrEKKLnnnnJsWb_PSDSz_ zNMHDK!vO9?RW-9>Qu6gOy`^`1`_9<;h#G?Pv zOqX4|$@`Dk3Tv-lzCIlMbj*6$VfL!`YMLMSj$bm~%&)`&aklsJhVwa zi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#_$Wy(?!bRO|q5*Tuax<3iD80~MzI^SNP1I8Ml}6?9v8s`-z7rXUNCoy`5 - -#> - - Write-Host "Below are available scopes you can specify for building specific projects" - Write-Host "" - Get-ChildItem -path "$env:repoRoot\src\ResourceManagement" -dir | Format-Wide -Column 5 | Format-Table -Property Name - Write-Host "e.g of a scope would be 'ResourceManagement\Compute'" -ForegroundColor Yellow - - Get-ChildItem -path "$env:repoRoot\src\" -dir -Exclude "ResourceManagement" | Format-Wide -Column 5 | Format-Table -Property Name - Write-Host "e.g of a scope would be 'Authentication'" -ForegroundColor Yellow -} - -[CmdletBinding] -Function Start-Build -{ -<# -.SYNOPSIS -This cmdlet will help to do either with full build or targeted build for specific scopes. - -.PARAMETER BuildScope -Use Get-BuildScope cmdLet to get list of existing scopes that can be used to build -#> - param( - [parameter(Mandatory=$false, Position=0, HelpMessage='BuildScope that you would like to use. For list of build scopes, run List-BuildScopes')] - [string]$BuildScope - ) - - if([string]::IsNullOrEmpty($BuildScope) -eq $true) - { - Write-Host "Starting Full build" - msbuild.exe "$env:repoRoot\build.proj" /t:Build - } - else - { - Write-Host "Building $BuildScope" - msbuild.exe "$env:repoRoot\build.proj" /t:Build /p:Scope=$BuildScope - } -} - -[CmdletBinding] -Function Invoke-CheckinTests -{ -<# -.SYNOPSIS -Runs all the check in tests -#> - Write-Host "cmdline Args: msbuild.exe $env:repoRoot\build.proj /t:Test" - msbuild.exe "$env:repoRoot\build.proj" /t:Test + #Initialize Code } -[cmdletBinding] -Function Install-VSProjectTemplates -{ -<# -.SYNOPSIS - -Install-VSProjectTemplates will install getting started project templates for -1) Autorest-.NET SDKProject -2) .NET SDK Test projectct - -After executing the cmdlet, restart VS (if already open), create new project -Search for the project template as we install the following three project templates -AutoRest-AzureDotNetSDK -AzureDotNetSDK-TestProject -AzurePowerShell-TestProject -#> - if($env:VisualStudioVersion -eq "14.0") - { - if((Test-Path "$env:repoRoot\tools\ProjectTemplates\") -eq $true) - { - Write-Host "Installing VS templates for 'AutoRest as well as Test Project'" - Copy-Item "$env:repoRoot\tools\ProjectTemplates\*.zip" "$env:USERPROFILE\Documents\Visual Studio 2015\Templates\ProjectTemplates\" - Write-Host "Installed VS Test Project Templates for Powershell test projects" - Write-Host "" - Write-Host "Restart VS (if already open), search for 'AzurePowerShell-TestProject'" -ForegroundColor Yellow - } - else - { - Write-Host "Missing templates to install, make sure you have project templates available in the repo under $env:repoRoot\tools\ProjectTemplates\" - } - } - else - { - Write-Host "Unsupported VS Version detected. Visual Studio 2015 is the only supported version for current set of project templates" - } -} <# We allow users to include any helper powershell scripts they would like to include in the current session @@ -127,8 +38,6 @@ else Write-Host "Loading skipped. 'psuserpreferences' environment variable was not set to load user preferences." -ForegroundColor DarkYellow } -export-modulemember -Function Set-TestEnvironment -export-modulemember -Function Get-BuildScopes -export-modulemember -Function Start-Build -export-modulemember -Function Invoke-CheckinTests -export-modulemember -Function Install-VSProjectTemplates \ No newline at end of file + +#Execute Init +Init \ No newline at end of file From ec3fb1395e98b684dbf2a295cfb73ba8f4beec23 Mon Sep 17 00:00:00 2001 From: shahabhijeet Date: Fri, 18 Nov 2016 14:07:51 -0800 Subject: [PATCH 4/5] Added cmdlet to create Service Principal. Refactored Repo-Tasks to include multiple modular modules (e.g. Build-Tasks, TestFx-Tasks) --- tools/Modules/Build-Tasks.psd1 | 4 +- tools/Modules/Foo.ps1 | 286 ------------------------ tools/Modules/TestFx-Tasks.psd1 | 4 +- tools/Modules/TestFx-Tasks.psm1 | 258 ++++++++++++++++----- tools/Modules/Tests/CommonTestUtil.psd1 | Bin 7774 -> 0 bytes tools/Modules/Tests/RepoModuleTests.ps1 | 3 + tools/Repo-Tasks.psd1 | 6 +- 7 files changed, 213 insertions(+), 348 deletions(-) delete mode 100644 tools/Modules/Foo.ps1 delete mode 100644 tools/Modules/Tests/CommonTestUtil.psd1 diff --git a/tools/Modules/Build-Tasks.psd1 b/tools/Modules/Build-Tasks.psd1 index 5d32dd30d56c..abaee4402785 100644 --- a/tools/Modules/Build-Tasks.psd1 +++ b/tools/Modules/Build-Tasks.psd1 @@ -1,9 +1,9 @@ # -# Module manifest for module 'Build-Tasks' +# Module manifest for module 'PSGet_Build-Tasks' # # Generated by: abhishah # -# Generated on: 11/16/2016 +# Generated on: 11/18/2016 # @{ diff --git a/tools/Modules/Foo.ps1 b/tools/Modules/Foo.ps1 deleted file mode 100644 index 5720d05b25d8..000000000000 --- a/tools/Modules/Foo.ps1 +++ /dev/null @@ -1,286 +0,0 @@ -Function Get-ActiveDirectoryApp -{ - param( - [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] - [ValidateNotNullOrEmpty()] - [string]$ADAppDisplayName, - - [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] - [ValidateNotNullOrEmpty()] - [string]$SubscriptionId, - - [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] - [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47", - - [Parameter(Mandatory=$false, HelpMessage="True: AD App is created if does not exist")] - [bool]$createADAppIfNotFound = $false, - - [Parameter(Mandatory=$false, HelpMessage="True: AD SPN is created if does not exist")] - [bool]$createADSpnIfNotFound = $false - - ) - - $displayName = $ADAppDisplayName - $homePage = "http://www.$displayName.com" - $identityUri = "http://$displayName" - - Select-AzureRmSubscription -SubscriptionId $SubscriptionId -TenantId $TenantId - $azSub = Get-AzureRmSubscription -SubscriptionId $SubscriptionId - - if($azSub -ne $null) - { - if($azSub.SubscriptionId -ne $SubscriptionId) - { - throw [System.ApplicationException] "'$SubscriptionId' subscriptionId is not selected'. Exiting......" - } - } - - $azAdApp = Get-AzureRmADApplication -DisplayNameStartWith $displayName - if($azAdApp -eq $null -and $createADAppIfNotFound -eq $true) - { - $azAdApp = New-AzureRmADApplication -DisplayName $displayName -HomePage $homePage -IdentifierUris $identityUri - } - - if($azAdApp -ne $null -and $createADSpnIfNotFound -eq $true) - { - $adAppSpn = New-AzureRmADServicePrincipal -ApplicationId $psAutoADApp.ApplicationId - } - else - { - throw [System.ApplicationException] "Unable to create new Azure AD Applicaiton using 'New-AzureRmADApplication'. Exiting......" - } - - Get-ADAppSpnDetails -AdApp $azAdApp -AdSpn $adAppSpn -} - -[cmdletBinding] -Function Get-ADAppSpnDetails -{ - param( - [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication")] - [Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADApplication] $AdApp, - - [Parameter(Mandatory=$false, HelpMessage="Azure AD ServicePrincipal")] - [Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADServicePrincipal] $AdSpn - ) - - if($AdApp -ne $null) - { - Write-Host "AD App Info" - Write-Host $AdApp - } - - if($AdSpn -ne $null) - { - Write-Host "AD SPN Info" - Write-Host $AdSpn - } -} - -[cmdletBinding] -Function Get-ServicePrincipal -{ - param( - [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] - [string]$ADAppDisplayName, - - [Parameter(Mandatory=$false, HelpMessage="Please provide the role that needs to be assigned to ServicePrinciple")] - [string]$Role, - - [Parameter(Mandatory=$false, HelpMessage="True: Spn is created if does not exist")] - [bool]$createIfNotFound = $false - ) -} - - -Function Delete-ActiveDirectoryApp -{ - [CmdletBinding(SupportsShouldProcess=$true)] - - param( - [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] - #[ValidateNotNullOrEmpty()] - [string]$ADAppDisplayName, - - [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] - #[ValidateNotNullOrEmpty()] - [string]$SubscriptionId, - - [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] - [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" - - ) - - #process - #{ - if($PSCmdlet.ShouldProcess("$ADAppDisplayName")) - { - Write-Host "ShouldProcess is True" - } - else - { - Write-Host "ShouldProcess is False" - } - - #} - -} - -[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 "" -} - -#Delete-ActiveDirectoryApp -ADAppDisplayName "" -SubscriptionId "" -TenantId "" -WhatIf - -export-modulemember -Function Set-TestEnvironment -export-modulemember -Function Delete-ActiveDirectoryApp - -Delete-ActiveDirectoryApp -ADAppDisplayName "Hello" -SubscriptionId "sub" -TenantId "tenant" \ No newline at end of file diff --git a/tools/Modules/TestFx-Tasks.psd1 b/tools/Modules/TestFx-Tasks.psd1 index 3d90bf08399c..d5709e08e2fa 100644 --- a/tools/Modules/TestFx-Tasks.psd1 +++ b/tools/Modules/TestFx-Tasks.psd1 @@ -3,7 +3,7 @@ # # Generated by: ShahAbhijeet # -# Generated on: 11/16/2016 +# Generated on: 11/18/2016 # @{ @@ -69,7 +69,7 @@ Copyright = '(c) 2016 ShahAbhijeet. All rights reserved.' # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = 'Set-TestEnvironment', 'Create-Spn' +FunctionsToExport = 'Set-TestEnvironment', 'Remove-ServicePrincipal', 'New-ServicePrincipal', 'Set-SPNRole' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() diff --git a/tools/Modules/TestFx-Tasks.psm1 b/tools/Modules/TestFx-Tasks.psm1 index b97ae967ab9d..a193ee1d637c 100644 --- a/tools/Modules/TestFx-Tasks.psm1 +++ b/tools/Modules/TestFx-Tasks.psm1 @@ -1,5 +1,13 @@ -Function Get-ActiveDirectoryApp +[cmdletBinding] +Function New-ServicePrincipal { +<# +.SYNOPSIS +This cmdlet helps you create: +1) AD Apllication needed for SPN +2) AD SPN +3) Assigning Reader role to the newly created SPN +#> param( [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] [ValidateNotNullOrEmpty()] @@ -20,41 +28,145 @@ ) - $displayName = $ADAppDisplayName - $homePage = "http://www.$displayName.com" - $identityUri = "http://$displayName" + Set-Subscription -SubscriptionId $SubscriptionId -TenantId $TenantId + + $azAdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName + if($azAdApp -eq $null -and $createADAppIfNotFound -eq $true) + { + $displayName = $ADAppDisplayName + $homePage = "http://www.$displayName.psmodule" + $identityUri = "http://$displayName" + $azAdApp = New-AzureRmADApplication -DisplayName $displayName -HomePage $homePage -IdentifierUris $identityUri + } - Select-AzureRmSubscription -SubscriptionId $SubscriptionId -TenantId $TenantId - $azSub = Get-AzureRmSubscription -SubscriptionId $SubscriptionId + $azSpn = Get-SPN -ADAppId $azAdApp.ApplicationId - if($azSub -ne $null) + if(($azAdApp -ne $null) -and ($azSpn -eq $null)) { - if($azSub.SubscriptionId -ne $SubscriptionId) + if($createADSpnIfNotFound -eq $true) { - throw [System.ApplicationException] "'$SubscriptionId' subscriptionId is not selected'. Exiting......" + $azSpn = New-AzureRmADServicePrincipal -ApplicationId $azAdApp.ApplicationId + Write-Host "Waiting for SPN to fully create and able to query ....." + + for($i=0; $i -lt 3; $i++) + { + #need to find a better deterministic way + #Cases are when you try to assign roles to newly created SPN, it is not able to find it and hence Role Assignment fails + #Get-SPN -ADAppId $azAdApp.ApplicationId + Start-Sleep -Seconds 5 + } } } - - $azAdApp = Get-AzureRmADApplication -DisplayNameStartWith $displayName - if($azAdApp -eq $null -and $createADAppIfNotFound -eq $true) + + if($azSpn -ne $null) { - $azAdApp = New-AzureRmADApplication -DisplayName $displayName -HomePage $homePage -IdentifierUris $identityUri + $spnScope = [string]::Format("{0}{1}", "/subscriptions/", "$SubscriptionId/") + + $rdStr = [string]::Format("{0} Role will be assigned to SPNName:{1} for scope {2}", "Reader", $azAdApp.ApplicationId, $spnScope) + Write-Host $rdStr + + $roleDef = Get-AzureRmRoleAssignment -ServicePrincipalName $azAdApp.ApplicationId -Scope $spnScope + if($roleDef -eq $null) + { + New-AzureRmRoleAssignment -RoleDefinitionName "Reader" -ServicePrincipalName $azAdApp.ApplicationId -scope $spnScope + } } - if($azAdApp -ne $null -and $createADSpnIfNotFound -eq $true) + Get-ServicePrincipalDetails -AdApp $azAdApp -AdSpn $azSpn + + Write-Host "Log onto Azure Portal and use Above SPN Details to find your Service Principal and obtain SPN Secret/ Authentication Key/ Secret Key for the newly created Service Principal" -ForegroundColor DarkYellow + Write-Host "Visit https://docs.microsoft.com/en-us/azure/resource-group-create-service-principal-portal" -ForegroundColor DarkYellow +} + +Function Get-ADApp +{ + param( + [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] + [ValidateNotNullOrEmpty()] + [string]$ADAppDisplayName + ) + + $displayName = $ADAppDisplayName + $homePage = "http://www.$displayName.psmodule" + $identityUri = "http://$displayName" + + $azAdApp = Get-AzureRmADApplication -IdentifierUri $identityUri + + $PsCmdLet.WriteObject($azAdApp) +} + +[CmdletBinding] +Function Get-SPN +{ + param( + [Parameter(Mandatory=$true, ParameterSetName="DisplayName", HelpMessage="Azure AD Apllication Display Name")] + [ValidateNotNullOrEmpty()] + [string]$ADAppDisplayName, + + [Parameter(Mandatory=$true, ParameterSetName="AppId", HelpMessage="Azure AD Apllication ID")] + [ValidateNotNullOrEmpty()] + [string]$ADAppId + ) + + $appId = "" + if([string]::IsNullOrEmpty($ADAppDisplayName) -eq $false) { - $adAppSpn = New-AzureRmADServicePrincipal -ApplicationId $psAutoADApp.ApplicationId + $azAdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName + $appId = $azAdApp.ApplicationId } - else + + if([string]::IsNullOrEmpty($ADAppDisplayName) -eq $true) { - throw [System.ApplicationException] "Unable to create new Azure AD Applicaiton using 'New-AzureRmADApplication'. Exiting......" + $appId = $ADAppId } - Get-ADAppSpnDetails -AdApp $azAdApp -AdSpn $adAppSpn + $azSpn = Get-AzureRmADServicePrincipal -ServicePrincipalName $appId + + + $Pscmdlet.WriteObject($azSpn) +} + +[CmdletBinding] +Function Set-Subscription +{ + param( + [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] + [ValidateNotNullOrEmpty()] + [string]$SubscriptionId, + + [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] + [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" + ) + + $azCtx = Get-AzureRmContext + + if($azCtx -ne $null) + { + if($azCtx.Subscription.SubscriptionId -ne $SubscriptionId) + { + $azSub = Get-AzureRmSubscription -SubscriptionId $SubscriptionId -TenantId $TenantId + + if($azSub -ne $null) + { + if($azSub.SubscriptionId -ne $SubscriptionId) + { + throw [System.ApplicationException] "'$SubscriptionId' subscriptionId is not selected'. Exiting......" + } + else + { + Select-AzureRmSubscription -SubscriptionId $SubscriptionId -TenantId $TenantId + } + } + else + { + throw [System.ApplicationException] "Unable to retrieve '$SubscriptionId'. Exiting......" + } + } + } } [cmdletBinding] -Function Get-ADAppSpnDetails +Function Get-ServicePrincipalDetails { param( [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication")] @@ -67,65 +179,103 @@ Function Get-ADAppSpnDetails if($AdApp -ne $null) { Write-Host "AD App Info" - Write-Host $AdApp + Write-Host ([string]::Format("Active Directory App Display Name: {0}", $AdApp.DisplayName)) + Write-Host ([string]::Format("Active Directory App ClientId: {0}", $AdApp.ApplicationId)) + Write-Host ([string]::Format("Active Directory App Identifier Uri: {0}", $AdApp.IdentifierUris[0].ToString())) + Write-Host } if($AdSpn -ne $null) { - Write-Host "AD SPN Info" - Write-Host $AdSpn + Write-Host "SPN Info" + Write-Host ([string]::Format("SPN Id: {0}", $AdSpn.Id)) + Write-Host ([string]::Format("SPN Display Name: {0}", $AdSpn.DisplayName)) + Write-Host ([string]::Format("SPN associated with Active Directory App Id: {0}", $AdSpn.ApplicationId)) + Write-Host } } [cmdletBinding] -Function Get-ServicePrincipal +Function Remove-ServicePrincipal { + [CmdletBinding(SupportsShouldProcess=$true)] + param( - [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] - [string]$ADAppDisplayName, + [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] + [ValidateNotNullOrEmpty()] + [string]$ADAppDisplayName, + + [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] + [ValidateNotNullOrEmpty()] + [string]$SubscriptionId, + + [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] + [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" + ) - [Parameter(Mandatory=$false, HelpMessage="Please provide the role that needs to be assigned to ServicePrinciple")] - [string]$Role, + Set-Subscription -SubscriptionId $SubscriptionId -TenantId $TenantId - [Parameter(Mandatory=$false, HelpMessage="True: Spn is created if does not exist")] - [bool]$createIfNotFound = $false - ) + if($PSCmdlet.ShouldProcess("$ADAppDisplayName")) + { + $AdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName + $azSpn = Get-SPN -ADAppId $adApp.ApplicationId + $adappStr = [string]::Format("{0} ADApp will be deleted", $AdApp.ApplicationId.ToString()) + $spnStr = [string]::Format("{0} SPN will be deleted", $azSpn.DisplayName) + Remove-AzureRmADServicePrincipal -ObjectId $azSpn.Id -Force + Remove-AzureRmADApplication -ObjectId $AdApp.ObjectId -Force + Write-Host $adappStr + Write-Host $spnStr -} + } + else + { + $AdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName + $azSpn = Get-SPN -ADAppId $adApp.ApplicationId + $adappStr = [string]::Format("{0} ADApp will be deleted", $AdApp.ApplicationId.ToString()) + $spnStr = [string]::Format("{0} SPN will be deleted", $azSpn.DisplayName) + Write-Host $adappStr + Write-Host $spnStr + } +} -Function Delete-ActiveDirectoryApp +[cmdletBinding] +Function Set-SPNRole { - [CmdletBinding(SupportsShouldProcess=$true)] - param( - [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] - #[ValidateNotNullOrEmpty()] + [Parameter(Mandatory=$true, HelpMessage="Azure AD Application Display Name")] + [ValidateNotNullOrEmpty()] [string]$ADAppDisplayName, [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] - #[ValidateNotNullOrEmpty()] + [ValidateNotNullOrEmpty()] [string]$SubscriptionId, - + [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" - ) - #process - #{ - if($PSCmdlet.ShouldProcess("$ADAppDisplayName")) - { - Write-Host "ShouldProcess is True" - } - else + Set-Subscription -SubscriptionId $SubscriptionId -TenantId $TenantId + $adApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName + + if($adApp -ne $null) + { + $azSpn = Get-SPN -ADAppId $adApp.ApplicationId + $spnScope = [string]::Format("{0}{1}", "/subscriptions/", "$SubscriptionId/") + $roleDef = Get-AzureRmRoleAssignment -ServicePrincipalName $adApp.ApplicationId -Scope $spnScope + + if($roleDef -eq $null) { - Write-Host "ShouldProcess is False" + $rdStr = [string]::Format("{0} Role will be assigned to SPNName:{1} for scope {2}", "Reader", $adApp.ApplicationId, $spnScope) + Write-Host $rdStr + New-AzureRmRoleAssignment -RoleDefinitionName "Reader" -ServicePrincipalName $adApp.ApplicationId -scope $spnScope } - - #} - + } + else + { + Write-Host "Unable to find AD App: $ADAppDisplayName" + } } [CmdletBinding] @@ -280,9 +430,7 @@ Function Print-ConnectionString([string]$uid, [string]$pwd, [string]$subId, [str Write-Host "" } -#Delete-ActiveDirectoryApp -ADAppDisplayName "" -SubscriptionId "" -TenantId "" -WhatIf - export-modulemember -Function Set-TestEnvironment -export-modulemember -Function Delete-ActiveDirectoryApp - -Delete-ActiveDirectoryApp -ADAppDisplayName "Hello" -SubscriptionId "sub" -TenantId "tenant" -WhatIf \ No newline at end of file +export-modulemember -Function Remove-ServicePrincipal +export-modulemember -Function New-ServicePrincipal +export-modulemember -Function Set-SPNRole \ No newline at end of file diff --git a/tools/Modules/Tests/CommonTestUtil.psd1 b/tools/Modules/Tests/CommonTestUtil.psd1 deleted file mode 100644 index ea134357ba87d22a45f2a96e31fdff2c74314b7e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7774 zcmeI1X>VIa6o%(B693^!`H&Qml%%B#5>l-!ZKO0*SqfjhW9kjtXMyGcrtf< z?{(~u0z$~L?=mxI-m{-G{^R!z_oe&7ZMe+6b|cqvSFZ2cdK$R88@itB=xOR^dehPP z#E<0XZMuEEALujE{EPYQOReaM(&n6c*yE+fhx$%LeWq(m^cwD?`%c%o?ta#)sebGF z+L~o6*^!mI`aIP4iGKIoH~ucJ=I(|2&C?6i&RtU&dT#7F1AFA$xNK;2C>#@^LmK%R z9nTw5stfH@V@aCJr+H3r9tH?szDc~cIOh#=F-aC zTQA+I5FnjQ-z&{)__vwfbrw)Xz6?y_8GD)agbtf4o1Z!MeBrj-gG7JF?m+LaBm>)Prk#1lVt>`OEsE%^r~R=w z5On+-^b#}@d54de?$Q}u`!$9T?2Ymgxgb>1@Nb=qD-tDA}Rs*YUox>;U` zZ)qe*?QTP>s`fRGQ;e@g8#^Be#XxJ}WFoH0vHs|1qxoyi$>e3+vEp3%!B3D9dg=O^ z@Q0M}qMpB7m4`CQ$k|?{Yf_9Zfd_!Q)R+JE!LGs*7a*1 zO0FaRSY+N(6?Wpzd|Zr@;_f!@{rAb*I9WxeZ)6qJU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 E1c_Ajf&c&j diff --git a/tools/Modules/Tests/RepoModuleTests.ps1 b/tools/Modules/Tests/RepoModuleTests.ps1 index 7cf6a172bdeb..75c537b1b153 100644 --- a/tools/Modules/Tests/RepoModuleTests.ps1 +++ b/tools/Modules/Tests/RepoModuleTests.ps1 @@ -3,5 +3,8 @@ $adDisplayName = "TestAdAppForNodeCliTestCase" $subId = '2c224e7e-3ef5-431d-a57b-e71f4662e3a6' + Create-ServicePrincipal -ADAppDisplayName "MyModTestApp1" -SubscriptionId 2c224e7e-3ef5-431d-a57b-e71f4662e3a6 -TenantId 72f988bf-86f1-41af-91ab-2d7cd011db47 -createADAppIfNotFound $true -createADSpnIfNotFound $true + Set-SPNRole -ADAppDisplayName "MyModTestApp1" -SubscriptionId 2c224e7e-3ef5-431d-a57b-e71f4662e3a6 + Remove-ServicePrincipal -ADAppDisplayName "MyModTestApp1" -SubscriptionId 2c224e7e-3ef5-431d-a57b-e71f4662e3a6 -TenantId 72f988bf-86f1-41af-91ab-2d7cd011db47 } diff --git a/tools/Repo-Tasks.psd1 b/tools/Repo-Tasks.psd1 index 4d07c6140f29..2fd3d67654f0 100644 --- a/tools/Repo-Tasks.psd1 +++ b/tools/Repo-Tasks.psd1 @@ -1,9 +1,9 @@ # -# Module manifest for module 'Repo-Tasks' +# Module manifest for module 'PSGet_Repo-Tasks' # # Generated by: shahabhijeet # -# Generated on: 11/16/2016 +# Generated on: 11/18/2016 # @{ @@ -70,7 +70,7 @@ RequiredModules = @('.\Modules\TestFx-Tasks.psd1', # NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = 'Init' +FunctionsToExport = '*' # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. CmdletsToExport = @() From 5bd61755dcda9de7d0075da4ebfeb6339627c6e6 Mon Sep 17 00:00:00 2001 From: shahabhijeet Date: Mon, 28 Nov 2016 16:41:37 -0800 Subject: [PATCH 5/5] Removing SPN cmdlets --- tools/Modules/TestFx-Tasks.psm1 | 287 +------------------------------- tools/Repo-Tasks.psm1 | 2 +- 2 files changed, 3 insertions(+), 286 deletions(-) diff --git a/tools/Modules/TestFx-Tasks.psm1 b/tools/Modules/TestFx-Tasks.psm1 index a193ee1d637c..6ff09e64f655 100644 --- a/tools/Modules/TestFx-Tasks.psm1 +++ b/tools/Modules/TestFx-Tasks.psm1 @@ -1,284 +1,4 @@ -[cmdletBinding] -Function New-ServicePrincipal -{ -<# -.SYNOPSIS -This cmdlet helps you create: -1) AD Apllication needed for SPN -2) AD SPN -3) Assigning Reader role to the newly created SPN -#> - param( - [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] - [ValidateNotNullOrEmpty()] - [string]$ADAppDisplayName, - - [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] - [ValidateNotNullOrEmpty()] - [string]$SubscriptionId, - - [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] - [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47", - - [Parameter(Mandatory=$false, HelpMessage="True: AD App is created if does not exist")] - [bool]$createADAppIfNotFound = $false, - - [Parameter(Mandatory=$false, HelpMessage="True: AD SPN is created if does not exist")] - [bool]$createADSpnIfNotFound = $false - - ) - - Set-Subscription -SubscriptionId $SubscriptionId -TenantId $TenantId - - $azAdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName - if($azAdApp -eq $null -and $createADAppIfNotFound -eq $true) - { - $displayName = $ADAppDisplayName - $homePage = "http://www.$displayName.psmodule" - $identityUri = "http://$displayName" - $azAdApp = New-AzureRmADApplication -DisplayName $displayName -HomePage $homePage -IdentifierUris $identityUri - } - - $azSpn = Get-SPN -ADAppId $azAdApp.ApplicationId - - if(($azAdApp -ne $null) -and ($azSpn -eq $null)) - { - if($createADSpnIfNotFound -eq $true) - { - $azSpn = New-AzureRmADServicePrincipal -ApplicationId $azAdApp.ApplicationId - Write-Host "Waiting for SPN to fully create and able to query ....." - - for($i=0; $i -lt 3; $i++) - { - #need to find a better deterministic way - #Cases are when you try to assign roles to newly created SPN, it is not able to find it and hence Role Assignment fails - #Get-SPN -ADAppId $azAdApp.ApplicationId - Start-Sleep -Seconds 5 - } - } - } - - if($azSpn -ne $null) - { - $spnScope = [string]::Format("{0}{1}", "/subscriptions/", "$SubscriptionId/") - - $rdStr = [string]::Format("{0} Role will be assigned to SPNName:{1} for scope {2}", "Reader", $azAdApp.ApplicationId, $spnScope) - Write-Host $rdStr - - $roleDef = Get-AzureRmRoleAssignment -ServicePrincipalName $azAdApp.ApplicationId -Scope $spnScope - if($roleDef -eq $null) - { - New-AzureRmRoleAssignment -RoleDefinitionName "Reader" -ServicePrincipalName $azAdApp.ApplicationId -scope $spnScope - } - } - - Get-ServicePrincipalDetails -AdApp $azAdApp -AdSpn $azSpn - - Write-Host "Log onto Azure Portal and use Above SPN Details to find your Service Principal and obtain SPN Secret/ Authentication Key/ Secret Key for the newly created Service Principal" -ForegroundColor DarkYellow - Write-Host "Visit https://docs.microsoft.com/en-us/azure/resource-group-create-service-principal-portal" -ForegroundColor DarkYellow -} - -Function Get-ADApp -{ - param( - [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] - [ValidateNotNullOrEmpty()] - [string]$ADAppDisplayName - ) - - $displayName = $ADAppDisplayName - $homePage = "http://www.$displayName.psmodule" - $identityUri = "http://$displayName" - - $azAdApp = Get-AzureRmADApplication -IdentifierUri $identityUri - - $PsCmdLet.WriteObject($azAdApp) -} - -[CmdletBinding] -Function Get-SPN -{ - param( - [Parameter(Mandatory=$true, ParameterSetName="DisplayName", HelpMessage="Azure AD Apllication Display Name")] - [ValidateNotNullOrEmpty()] - [string]$ADAppDisplayName, - - [Parameter(Mandatory=$true, ParameterSetName="AppId", HelpMessage="Azure AD Apllication ID")] - [ValidateNotNullOrEmpty()] - [string]$ADAppId - ) - - $appId = "" - if([string]::IsNullOrEmpty($ADAppDisplayName) -eq $false) - { - $azAdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName - $appId = $azAdApp.ApplicationId - } - - if([string]::IsNullOrEmpty($ADAppDisplayName) -eq $true) - { - $appId = $ADAppId - } - - $azSpn = Get-AzureRmADServicePrincipal -ServicePrincipalName $appId - - - $Pscmdlet.WriteObject($azSpn) -} - -[CmdletBinding] -Function Set-Subscription -{ - param( - [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] - [ValidateNotNullOrEmpty()] - [string]$SubscriptionId, - - [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] - [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" - ) - - $azCtx = Get-AzureRmContext - - if($azCtx -ne $null) - { - if($azCtx.Subscription.SubscriptionId -ne $SubscriptionId) - { - $azSub = Get-AzureRmSubscription -SubscriptionId $SubscriptionId -TenantId $TenantId - - if($azSub -ne $null) - { - if($azSub.SubscriptionId -ne $SubscriptionId) - { - throw [System.ApplicationException] "'$SubscriptionId' subscriptionId is not selected'. Exiting......" - } - else - { - Select-AzureRmSubscription -SubscriptionId $SubscriptionId -TenantId $TenantId - } - } - else - { - throw [System.ApplicationException] "Unable to retrieve '$SubscriptionId'. Exiting......" - } - } - } -} - -[cmdletBinding] -Function Get-ServicePrincipalDetails -{ - param( - [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication")] - [Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADApplication] $AdApp, - - [Parameter(Mandatory=$false, HelpMessage="Azure AD ServicePrincipal")] - [Microsoft.Azure.Commands.Resources.Models.ActiveDirectory.PSADServicePrincipal] $AdSpn - ) - - if($AdApp -ne $null) - { - Write-Host "AD App Info" - Write-Host ([string]::Format("Active Directory App Display Name: {0}", $AdApp.DisplayName)) - Write-Host ([string]::Format("Active Directory App ClientId: {0}", $AdApp.ApplicationId)) - Write-Host ([string]::Format("Active Directory App Identifier Uri: {0}", $AdApp.IdentifierUris[0].ToString())) - Write-Host - } - - if($AdSpn -ne $null) - { - Write-Host "SPN Info" - Write-Host ([string]::Format("SPN Id: {0}", $AdSpn.Id)) - Write-Host ([string]::Format("SPN Display Name: {0}", $AdSpn.DisplayName)) - Write-Host ([string]::Format("SPN associated with Active Directory App Id: {0}", $AdSpn.ApplicationId)) - Write-Host - } -} - -[cmdletBinding] -Function Remove-ServicePrincipal -{ - [CmdletBinding(SupportsShouldProcess=$true)] - - param( - [Parameter(Mandatory=$true, HelpMessage="Azure AD Apllication Display Name")] - [ValidateNotNullOrEmpty()] - [string]$ADAppDisplayName, - - [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] - [ValidateNotNullOrEmpty()] - [string]$SubscriptionId, - - [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] - [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" - ) - - Set-Subscription -SubscriptionId $SubscriptionId -TenantId $TenantId - - if($PSCmdlet.ShouldProcess("$ADAppDisplayName")) - { - $AdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName - $azSpn = Get-SPN -ADAppId $adApp.ApplicationId - $adappStr = [string]::Format("{0} ADApp will be deleted", $AdApp.ApplicationId.ToString()) - $spnStr = [string]::Format("{0} SPN will be deleted", $azSpn.DisplayName) - - Remove-AzureRmADServicePrincipal -ObjectId $azSpn.Id -Force - Remove-AzureRmADApplication -ObjectId $AdApp.ObjectId -Force - Write-Host $adappStr - Write-Host $spnStr - - } - else - { - $AdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName - $azSpn = Get-SPN -ADAppId $adApp.ApplicationId - - $adappStr = [string]::Format("{0} ADApp will be deleted", $AdApp.ApplicationId.ToString()) - $spnStr = [string]::Format("{0} SPN will be deleted", $azSpn.DisplayName) - Write-Host $adappStr - Write-Host $spnStr - } -} - -[cmdletBinding] -Function Set-SPNRole -{ - param( - [Parameter(Mandatory=$true, HelpMessage="Azure AD Application Display Name")] - [ValidateNotNullOrEmpty()] - [string]$ADAppDisplayName, - - [Parameter(Mandatory=$true, HelpMessage="Azure Subscription Id")] - [ValidateNotNullOrEmpty()] - [string]$SubscriptionId, - - [Parameter(Mandatory=$false, HelpMessage="Azure AD Apllication Display Name")] - [string]$TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" - ) - - Set-Subscription -SubscriptionId $SubscriptionId -TenantId $TenantId - $adApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName - - if($adApp -ne $null) - { - $azSpn = Get-SPN -ADAppId $adApp.ApplicationId - $spnScope = [string]::Format("{0}{1}", "/subscriptions/", "$SubscriptionId/") - $roleDef = Get-AzureRmRoleAssignment -ServicePrincipalName $adApp.ApplicationId -Scope $spnScope - - if($roleDef -eq $null) - { - $rdStr = [string]::Format("{0} Role will be assigned to SPNName:{1} for scope {2}", "Reader", $adApp.ApplicationId, $spnScope) - Write-Host $rdStr - New-AzureRmRoleAssignment -RoleDefinitionName "Reader" -ServicePrincipalName $adApp.ApplicationId -scope $spnScope - } - } - else - { - Write-Host "Unable to find AD App: $ADAppDisplayName" - } -} - -[CmdletBinding] +[CmdletBinding] Function Set-TestEnvironment { <# @@ -430,7 +150,4 @@ Function Print-ConnectionString([string]$uid, [string]$pwd, [string]$subId, [str Write-Host "" } -export-modulemember -Function Set-TestEnvironment -export-modulemember -Function Remove-ServicePrincipal -export-modulemember -Function New-ServicePrincipal -export-modulemember -Function Set-SPNRole \ No newline at end of file +export-modulemember -Function Set-TestEnvironment \ No newline at end of file diff --git a/tools/Repo-Tasks.psm1 b/tools/Repo-Tasks.psm1 index 95a5254c8f76..32f6506d27fa 100644 --- a/tools/Repo-Tasks.psm1 +++ b/tools/Repo-Tasks.psm1 @@ -40,4 +40,4 @@ else #Execute Init -Init \ No newline at end of file +#Init \ No newline at end of file