Skip to content

Commit 42939ef

Browse files
authored
Merge pull request #92 from LogicAppCollaborative/development
Support Azure DevOps and Visual Studio Team Services connection object
2 parents ceac2df + 44d52d5 commit 42939ef

File tree

3 files changed

+258
-0
lines changed

3 files changed

+258
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"type": "Microsoft.Web/connections",
3+
"apiVersion": "2016-06-01",
4+
"name": "##NAME##",
5+
"location": "[parameters('logicAppLocation')]",
6+
"properties": {
7+
"api": {
8+
"id": "[subscriptionResourceId('Microsoft.Web/locations/managedApis', parameters('logicAppLocation'), 'visualstudioteamservices')]"
9+
},
10+
"displayName": "##NAME##",
11+
"parameterValueSet": {
12+
"name": "OauthSP",
13+
"values": {
14+
"token:TenantId": {
15+
"value": "##TENANTID##"
16+
},
17+
"token:clientId": {
18+
"value": "##CLIENTID##"
19+
},
20+
"token:clientSecret": {
21+
"value": "##CLIENTSECRET##"
22+
}
23+
}
24+
}
25+
}
26+
}

PsLogicAppExtractor/internal/tasks/All/All.task.ps1

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3000,6 +3000,123 @@ Task -Name "Set-Arm.Connections.ManagedApis.Storage.Table.ListKey.Advanced.AsArm
30003000
Out-TaskFileArm -InputObject $armObj
30013001
}
30023002

3003+
#Original file: Set-Arm.Connections.ManagedApis.VisualStudioTeamServices.ServicePrincipal.Advanced.AsArmObject.task.ps1
3004+
$parm = @{
3005+
Description = @"
3006+
Loops all `$connections children
3007+
-Validates that is of the type Azure DevOps / Visual Studio Team Services
3008+
--Creates a new resource in the ARM template, for the ApiConnection object
3009+
--With matching ARM Parameters, for the Namespace
3010+
--Makes sure the ARM Parameters logicAppLocation exists
3011+
--The type is based on the Service Principal authentication
3012+
--Name & Display Name is extracted from the connection object
3013+
Requires an authenticated session, either Az.Accounts or az cli
3014+
"@
3015+
Alias = "Arm.Set-Arm.Connections.ManagedApis.VisualStudioTeamServices.ServicePrincipal.Advanced.AsArmObject"
3016+
}
3017+
3018+
Task -Name "Set-Arm.Connections.ManagedApis.VisualStudioTeamServices.ServicePrincipal.Advanced.AsArmObject" @parm -Action {
3019+
Set-TaskWorkDirectory
3020+
3021+
# We can either use the az cli or the Az modules
3022+
$tools = Get-PSFConfigValue -FullName PsLogicAppExtractor.Execution.Tools
3023+
3024+
$found = $false
3025+
$conType = "visualstudioteamservices"
3026+
3027+
$armObj = Get-TaskWorkObject
3028+
3029+
foreach ($connectionObj in $armObj.resources[0].properties.parameters.'$connections'.value.PsObject.Properties) {
3030+
if ($connectionObj.Value.id -like "*managedApis/visualstudioteamservices*") {
3031+
$found = $true
3032+
3033+
# Fetch the details from the connection object
3034+
$uri = "{0}?api-version=2018-07-01-preview" -f $($connectionObj.Value.connectionId)
3035+
3036+
if ($tools -eq "AzCli") {
3037+
$resObj = az rest --url $uri | ConvertFrom-Json
3038+
}
3039+
else {
3040+
$resObj = Invoke-AzRestMethod -Path $uri -Method Get | Select-Object -ExpandProperty content | ConvertFrom-Json
3041+
}
3042+
3043+
# Use the display name as the name of the resource
3044+
$conName = $resObj.Properties.DisplayName
3045+
3046+
$tenantId = $resObj.properties.parameterValueSet.values."token:TenantId".value
3047+
$clientId = $resObj.properties.parameterValueSet.values."token:clientId".value
3048+
3049+
# Fetch base template
3050+
$pathArms = "$(Get-PSFConfigValue -FullName PsLogicAppExtractor.ModulePath.Base)\internal\arms"
3051+
$apiObj = Get-Content -Path "$pathArms\API.AzureDevOps.ServicePrincipal.json" -Raw | ConvertFrom-Json
3052+
3053+
# Set the names of the parameters
3054+
$Prefix = Get-PSFConfigValue -FullName PsLogicAppExtractor.prefixsuffix.connection.prefix
3055+
$parmApicId = Format-Name -Type "Connection" -Prefix $Prefix -Value "$($connectionObj.Name)"
3056+
$parmApicTenant = Format-Name -Type "Connection" -Prefix $Prefix -Suffix "_TenantId" -Value "$($connectionObj.Name)"
3057+
$parmApicClient = Format-Name -Type "Connection" -Prefix $Prefix -Suffix "_ClientId" -Value "$($connectionObj.Name)"
3058+
$parmApicSecret = Format-Name -Type "Connection" -Prefix $Prefix -Suffix "_ClientSecret" -Value "$($connectionObj.Name)"
3059+
3060+
# $idPreSuf = Format-Name -Type "Connection" -Value "$($_.Name)"
3061+
# $displayPreSuf = Format-Name -Type "Connection" -Prefix $Prefix -Suffix "_DisplayName" -Value "$($_.Name)"
3062+
3063+
$armObj = Add-ArmParameter -InputObject $armObj -Name "$parmApicId" `
3064+
-Type "string" `
3065+
-Value $conName `
3066+
-Description "The name / id of the ManagedApi connection object that is being utilized by the Logic App. Will be for the trigger and other actions that depend on connections."
3067+
3068+
$armObj = Add-ArmParameter -InputObject $armObj -Name "$parmApicTenant" `
3069+
-Type "string" `
3070+
-Value "$tenantId" `
3071+
-Description "The Azure tenant id that the Azure DevOps instance is connected to. ($($_.Name))"
3072+
3073+
$armObj = Add-ArmParameter -InputObject $armObj -Name "$parmApicClient" `
3074+
-Type "string" `
3075+
-Value "$clientId" `
3076+
-Description "The ClientId used to authenticate against the Azure DevOps instance. ($($_.Name))"
3077+
3078+
$armObj = Add-ArmParameter -InputObject $armObj -Name "$parmApicSecret" `
3079+
-Type "SecureString" `
3080+
-Value "" `
3081+
-Description "The ClientSecret used to authenticate against the Azure DevOps instance. ($($_.Name))"
3082+
3083+
# Update the api object properties
3084+
$apiObj.Name = "[parameters('$parmApicId')]"
3085+
$apiObj.properties.displayName = "[parameters('$parmApicId')]"
3086+
$apiObj.properties.parameterValueSet.values."token:TenantId".value = "[parameters('$parmApicTenant')]"
3087+
$apiObj.properties.parameterValueSet.values."token:clientId".value = "[parameters('$parmApicClient')]"
3088+
$apiObj.properties.parameterValueSet.values."token:clientSecret".value = "[parameters('$parmApicSecret')]"
3089+
3090+
# Append the new resource to the ARM template
3091+
$armObj.resources += $apiObj
3092+
3093+
if ($null -eq $armObj.resources[0].dependsOn) {
3094+
# Create the dependsOn array if it does not exist
3095+
$armObj.resources[0] | Add-Member -MemberType NoteProperty -Name "dependsOn" -Value @()
3096+
}
3097+
3098+
# Add the new resource to the dependsOn array, so that the deployment will work
3099+
$armObj.resources[0].dependsOn += "[resourceId('Microsoft.Web/connections', parameters('$parmApicId'))]"
3100+
3101+
# Adjust the connection object to depend on the same name
3102+
$connectionObj.Value.connectionId = "[resourceId('Microsoft.Web/connections', parameters('$parmApicId'))]"
3103+
$connectionObj.Value.connectionName = "[parameters('$parmApicId')]"
3104+
$connectionObj.Value.id = "[format('/subscriptions/{0}/providers/Microsoft.Web/locations/{1}/managedApis/$conType', subscription().subscriptionId, parameters('logicAppLocation'))]"
3105+
}
3106+
}
3107+
3108+
if ($found) {
3109+
if ($null -eq $armObj.parameters.logicAppLocation) {
3110+
$armObj = Add-ArmParameter -InputObject $armObj -Name "logicAppLocation" `
3111+
-Type "string" `
3112+
-Value "[resourceGroup().location]" `
3113+
-Description "Location of the Logic App. Best practice recommendation is to make this depending on the Resource Group and its location."
3114+
}
3115+
}
3116+
3117+
Out-TaskFileArm -InputObject $armObj
3118+
}
3119+
30033120
#Original file: Set-Arm.Diagnostics.Settings.Workspace.Advanced.AsArmObject.task.ps1
30043121
$parm = @{
30053122
Description = @"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
$parm = @{
2+
Description = @"
3+
Loops all `$connections children
4+
-Validates that is of the type Azure DevOps / Visual Studio Team Services
5+
--Creates a new resource in the ARM template, for the ApiConnection object
6+
--With matching ARM Parameters, for the Namespace
7+
--Makes sure the ARM Parameters logicAppLocation exists
8+
--The type is based on the Service Principal authentication
9+
--Name & Display Name is extracted from the connection object
10+
Requires an authenticated session, either Az.Accounts or az cli
11+
"@
12+
Alias = "Arm.Set-Arm.Connections.ManagedApis.VisualStudioTeamServices.ServicePrincipal.Advanced.AsArmObject"
13+
}
14+
15+
Task -Name "Set-Arm.Connections.ManagedApis.VisualStudioTeamServices.ServicePrincipal.Advanced.AsArmObject" @parm -Action {
16+
Set-TaskWorkDirectory
17+
18+
# We can either use the az cli or the Az modules
19+
$tools = Get-PSFConfigValue -FullName PsLogicAppExtractor.Execution.Tools
20+
21+
$found = $false
22+
$conType = "visualstudioteamservices"
23+
24+
$armObj = Get-TaskWorkObject
25+
26+
foreach ($connectionObj in $armObj.resources[0].properties.parameters.'$connections'.value.PsObject.Properties) {
27+
if ($connectionObj.Value.id -like "*managedApis/visualstudioteamservices*") {
28+
$found = $true
29+
30+
# Fetch the details from the connection object
31+
$uri = "{0}?api-version=2018-07-01-preview" -f $($connectionObj.Value.connectionId)
32+
33+
if ($tools -eq "AzCli") {
34+
$resObj = az rest --url $uri | ConvertFrom-Json
35+
}
36+
else {
37+
$resObj = Invoke-AzRestMethod -Path $uri -Method Get | Select-Object -ExpandProperty content | ConvertFrom-Json
38+
}
39+
40+
# Use the display name as the name of the resource
41+
$conName = $resObj.Properties.DisplayName
42+
43+
$tenantId = $resObj.properties.parameterValueSet.values."token:TenantId".value
44+
$clientId = $resObj.properties.parameterValueSet.values."token:clientId".value
45+
46+
# Fetch base template
47+
$pathArms = "$(Get-PSFConfigValue -FullName PsLogicAppExtractor.ModulePath.Base)\internal\arms"
48+
$apiObj = Get-Content -Path "$pathArms\API.AzureDevOps.ServicePrincipal.json" -Raw | ConvertFrom-Json
49+
50+
# Set the names of the parameters
51+
$Prefix = Get-PSFConfigValue -FullName PsLogicAppExtractor.prefixsuffix.connection.prefix
52+
$parmApicId = Format-Name -Type "Connection" -Prefix $Prefix -Value "$($connectionObj.Name)"
53+
$parmApicTenant = Format-Name -Type "Connection" -Prefix $Prefix -Suffix "_TenantId" -Value "$($connectionObj.Name)"
54+
$parmApicClient = Format-Name -Type "Connection" -Prefix $Prefix -Suffix "_ClientId" -Value "$($connectionObj.Name)"
55+
$parmApicSecret = Format-Name -Type "Connection" -Prefix $Prefix -Suffix "_ClientSecret" -Value "$($connectionObj.Name)"
56+
57+
# $idPreSuf = Format-Name -Type "Connection" -Value "$($_.Name)"
58+
# $displayPreSuf = Format-Name -Type "Connection" -Prefix $Prefix -Suffix "_DisplayName" -Value "$($_.Name)"
59+
60+
$armObj = Add-ArmParameter -InputObject $armObj -Name "$parmApicId" `
61+
-Type "string" `
62+
-Value $conName `
63+
-Description "The name / id of the ManagedApi connection object that is being utilized by the Logic App. Will be for the trigger and other actions that depend on connections."
64+
65+
$armObj = Add-ArmParameter -InputObject $armObj -Name "$parmApicTenant" `
66+
-Type "string" `
67+
-Value "$tenantId" `
68+
-Description "The Azure tenant id that the Azure DevOps instance is connected to. ($($_.Name))"
69+
70+
$armObj = Add-ArmParameter -InputObject $armObj -Name "$parmApicClient" `
71+
-Type "string" `
72+
-Value "$clientId" `
73+
-Description "The ClientId used to authenticate against the Azure DevOps instance. ($($_.Name))"
74+
75+
$armObj = Add-ArmParameter -InputObject $armObj -Name "$parmApicSecret" `
76+
-Type "SecureString" `
77+
-Value "" `
78+
-Description "The ClientSecret used to authenticate against the Azure DevOps instance. ($($_.Name))"
79+
80+
# Update the api object properties
81+
$apiObj.Name = "[parameters('$parmApicId')]"
82+
$apiObj.properties.displayName = "[parameters('$parmApicId')]"
83+
$apiObj.properties.parameterValueSet.values."token:TenantId".value = "[parameters('$parmApicTenant')]"
84+
$apiObj.properties.parameterValueSet.values."token:clientId".value = "[parameters('$parmApicClient')]"
85+
$apiObj.properties.parameterValueSet.values."token:clientSecret".value = "[parameters('$parmApicSecret')]"
86+
87+
# Append the new resource to the ARM template
88+
$armObj.resources += $apiObj
89+
90+
if ($null -eq $armObj.resources[0].dependsOn) {
91+
# Create the dependsOn array if it does not exist
92+
$armObj.resources[0] | Add-Member -MemberType NoteProperty -Name "dependsOn" -Value @()
93+
}
94+
95+
# Add the new resource to the dependsOn array, so that the deployment will work
96+
$armObj.resources[0].dependsOn += "[resourceId('Microsoft.Web/connections', parameters('$parmApicId'))]"
97+
98+
# Adjust the connection object to depend on the same name
99+
$connectionObj.Value.connectionId = "[resourceId('Microsoft.Web/connections', parameters('$parmApicId'))]"
100+
$connectionObj.Value.connectionName = "[parameters('$parmApicId')]"
101+
$connectionObj.Value.id = "[format('/subscriptions/{0}/providers/Microsoft.Web/locations/{1}/managedApis/$conType', subscription().subscriptionId, parameters('logicAppLocation'))]"
102+
}
103+
}
104+
105+
if ($found) {
106+
if ($null -eq $armObj.parameters.logicAppLocation) {
107+
$armObj = Add-ArmParameter -InputObject $armObj -Name "logicAppLocation" `
108+
-Type "string" `
109+
-Value "[resourceGroup().location]" `
110+
-Description "Location of the Logic App. Best practice recommendation is to make this depending on the Resource Group and its location."
111+
}
112+
}
113+
114+
Out-TaskFileArm -InputObject $armObj
115+
}

0 commit comments

Comments
 (0)