Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions adhoc/issue-156/publish-credentials.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Select-AzSubscription -SubscriptionName 'Microsoft Azure Sponsorship'
$SubscriptionName = 'Microsoft Azure Sponsorship'
if ($null -eq (Get-AzContext)) { Connect-AzAccount }
Select-AzSubscription -SubscriptionName $SubscriptionName
Get-AzContext

. .\adhoc\~~Load-all-cmdlets-locally.ps1 # Load to this session
Expand All @@ -14,7 +16,7 @@ $json = $body | ConvertFrom-Json


#$resType = Get-AzureResourceType $obj.Type
$DataFactoryName = "$testAdf-17274af2"
$DataFactoryName = "$testAdf-7d6cdb5f"
$ResourceGroupName = 'rg-devops-factory'
$resType = 'Microsoft.DataFactory/factories/credentials'
$resName = "$DataFactoryName/credential1"
Expand All @@ -28,7 +30,7 @@ New-AzResource `
-IsFullObject -Force

# ------------------------------------------------------------
Select-AzSubscription -SubscriptionName 'MVP'
Select-AzSubscription -SubscriptionName $SubscriptionName

# Delete credential
$adfi = Get-AzDataFactoryV2 -ResourceGroupName "$ResourceGroupName" -Name "$DataFactoryName"
Expand All @@ -48,3 +50,6 @@ $adf = Import-AdfFromFolder -FactoryName "$DataFactoryName" -RootFolder "$testPa
Remove-AdfObjectIfNotInSource -adfSource $adf -adfTargetObj $adfIns.Credentials[0] -adfInstance $adfIns

$adfIns.Credentials[0].Name


Import-Module ".\azure.datafactory.tools.psd1" -Force
7 changes: 4 additions & 3 deletions azure.datafactory.tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'azure.datafactory.tools.psm1'

# Version number of this module.
ModuleVersion = '1.11.2'
ModuleVersion = '1.12.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand All @@ -27,7 +27,7 @@
CompanyName = 'SQLPlayer'

# Copyright statement for this module
Copyright = '(c) 2020-2024 Kamil Nowinski. All rights reserved.'
Copyright = '(c) 2020-2025 Kamil Nowinski. All rights reserved.'

# Description of the functionality provided by this module
Description = 'PowerShell module to help with CI&CD for Azure Data Factory, mainly to publish to ADF service in multiple environments. Check https://github.com/Azure-Player/azure.datafactory.tools/ & https://azureplayer.net/adf/'
Expand All @@ -51,7 +51,7 @@
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @('Az.DataFactory')
RequiredModules = @('Az.Resources', 'Az.DataFactory')

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
Expand Down Expand Up @@ -82,6 +82,7 @@
, 'Get-AdfDocDiagram'
, 'Export-AdfToArmTemplate'
, 'Test-AdfArmTemplate'
, 'Set-AdfToolsAuthToken'
)

# 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.
Expand Down
6 changes: 4 additions & 2 deletions azure.datafactory.tools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if (Test-Path -Path "$PSScriptRoot\public" -ErrorAction Ignore)
}
}

$script:BaseApiUrl = "https://management.azure.com"
$moduleName = 'Az.DataFactory'
$module = Get-Module $moduleName
$minVer = "1.10.0"
Expand All @@ -39,7 +40,8 @@ if ($null -ne $module -and $module.Version -lt [System.Version]$minVer)
}
elseif ($null -eq $module)
{
Write-Host "Importing module $module (> $minVer)..."
Write-Host "Importing module $moduleName (> $minVer)..."
Import-Module -Name $moduleName -MinimumVersion "$minVer" -Scope Global
Write-Host "Module imported."
$module = Get-Module $moduleName
Write-Host "Module $ModuleName (v.$($module.Version)) imported."
}
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [1.12.0] - 2025-03-20
### Added
* Error during the import when required Az.Resource module is not loaded #336
* Az.DataFactory module is required to import adftools
* Added function `Set-AdfToolsAuthToken` to enable changing URL to API when target environment is different than default Global Azure #356 #441
### Fixed
* Error when deleting credentials #403

## [1.11.2] - 2024-12-04
### Fixed
* Unknown object type: SparkJobDefinition #428 by adding the type to the ignored list
Expand Down
7 changes: 5 additions & 2 deletions private/GlobalParam.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ function Get-GlobalParam([string]$ResourceGroupName, [string]$DataFactoryName)
'Authorization'='Bearer ' + $token.AccessToken
}

$restUri = "https://management.azure.com/subscriptions/$SubscriptionID/resourcegroups/$ResourceGroupName/providers/Microsoft.DataFactory/factories/$DataFactoryName/globalParameters/default?api-version=2018-06-01"
$restUri = "$BaseApiUrl/subscriptions/$SubscriptionID/resourcegroups/$ResourceGroupName/providers/Microsoft.DataFactory/factories/$DataFactoryName/globalParameters/default?api-version=2018-06-01"
Write-Debug "Get-GlobalParam:Request preparing to URL: $restUri"

$params = @{
Headers = $authHeader
Method = 'GET'
Expand Down Expand Up @@ -51,7 +53,8 @@ function Set-GlobalParam([Adf] $adf)
""properties"": $gp
}"

$restUri = "https://management.azure.com/subscriptions/$SubscriptionID/resourcegroups/$ResourceGroupName/providers/Microsoft.DataFactory/factories/$DataFactoryName/globalParameters/default?api-version=2018-06-01"
$restUri = "$BaseApiUrl/subscriptions/$SubscriptionID/resourcegroups/$ResourceGroupName/providers/Microsoft.DataFactory/factories/$DataFactoryName/globalParameters/default?api-version=2018-06-01"
Write-Debug "Set-GlobalParam:Request preparing to URL: $restUri"
$params = @{
Headers = $authHeader
Body = $body
Expand Down
2 changes: 1 addition & 1 deletion private/Remove-AdfObjectRestAPI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Remove-AdfObjectRestAPI {
'Content-Type' = 'application/json'
'Authorization' = 'Bearer ' + $token.Token
}
$url = "https://management.azure.com$($adfi.DataFactoryId)/$type_plural/$($name)?api-version=2018-06-01"
$url = "https://management.azure.com$($adfInstance.Id)/$type_plural/$($name)?api-version=2018-06-01"

# Delete given object via Rest API
$r = Invoke-RestMethod -Method 'DELETE' -Uri $url -Headers $authHeader -ContentType "application/json"
Expand Down
6 changes: 4 additions & 2 deletions private/Test-LinkedServiceConnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function Get-LinkedServiceBody(
)
{
Write-Debug "BEGIN: Get-LinkedServiceBody()"
$ADFEndpoint = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName/providers/Microsoft.DataFactory/factories/$DataFactoryName/linkedservices/$($LinkedServiceName)?api-version=2018-06-01"
$ADFEndpoint = "$BaseApiUrl/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName/providers/Microsoft.DataFactory/factories/$DataFactoryName/linkedservices/$($LinkedServiceName)?api-version=2018-06-01"
Write-Debug "Get-LinkedServiceBody:Request preparing to URL: $ADFEndpoint"

$request = @{
ContentType = 'application/json'
Expand Down Expand Up @@ -93,7 +94,8 @@ function Test-LinkedServiceConnection(

$body = Get-LinkedServiceBody -LinkedServiceName $LinkedServiceName -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName -BearerToken $bearerToken -SubscriptionID $SubscriptionID

$AzureEndpoint = "https://management.azure.com/subscriptions/$SubscriptionID/resourcegroups/$ResourceGroupName/providers/Microsoft.DataFactory/factories/$DataFactoryName/testConnectivity?api-version=2018-06-01"
$AzureEndpoint = "$BaseApiUrl/subscriptions/$SubscriptionID/resourcegroups/$ResourceGroupName/providers/Microsoft.DataFactory/factories/$DataFactoryName/testConnectivity?api-version=2018-06-01"
Write-Debug "Test-LinkedServiceConnection:Request preparing to URL: $AzureEndpoint"

if ($Params) {
Write-Verbose "Found input parameters for this Linked Service, adding to the API request..."
Expand Down
2 changes: 1 addition & 1 deletion public/Export-AdfToArmTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function Export-AdfToArmTemplate {
[parameter(Mandatory = $false)]
[String] $ResourceGroup = 'abcxyz',
[parameter(Mandatory = $false)]
[String] $AdfUtilitiesVersion = '0.1.6',
[String] $AdfUtilitiesVersion = '1.0.2',
[parameter(Mandatory = $false)]
[String] $OutputFolder = 'ArmTemplate'
)
Expand Down
39 changes: 39 additions & 0 deletions public/Set-AdfToolsAuthToken.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<#
.SYNOPSIS
Sets the tool's URL of base API. Default is "https://management.azure.com"

.DESCRIPTION
Sets the tool's URL of base API. Default is "https://management.azure.com".
Currently function accepts only one parameter, apiUrl, which is the URL of the Azure cloud.
In the future, the function will accept additional parameters to aquire the authentication token.

.PARAMETER apiUrl
The Azure context. If not provided, the function connects to the Azure account and gets the context.

.EXAMPLE
Set-AdfToolsAuthToken -apiUrl "https://management.usgovcloudapi.net"

This command sets BaseApiUrl to "https://management.usgovcloudapi.net", which is the URL of the Azure Government cloud.

.INPUTS
None. This function does not accept pipeline input.

.OUTPUTS
None. This function does not return any output.

.NOTES

#>

function Set-AdfToolsAuthToken {
param
(
[string] $apiUrl
)

if ($apiUrl) {
$script:BaseApiUrl = $apiUrl
Write-Host "BaseApiUrl set to $apiUrl"
}

}
2 changes: 1 addition & 1 deletion test/Export-AdfToArmTemplate.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ InModuleScope azure.datafactory.tools {
Describe 'Export-AdfToArmTemplate' -Tag 'Unit' {

It 'Should exist' {
{ Get-Command -Name 'Publish-AdfV2UsingArm' -ErrorAction Stop } | Should -Not -Throw
{ Get-Command -Name 'Export-AdfToArmTemplate' -ErrorAction Stop } | Should -Not -Throw
}
It 'Should completed successfully' {
{ Export-AdfToArmTemplate -RootFolder $script:RootFolder } | Should -Not -Throw
Expand Down
49 changes: 49 additions & 0 deletions test/Remove-AdfObjectRestAPI.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
BeforeDiscovery {
$ModuleRootPath = $PSScriptRoot | Split-Path -Parent
$moduleManifestName = 'azure.datafactory.tools.psd1'
$moduleManifestPath = Join-Path -Path $ModuleRootPath -ChildPath $moduleManifestName

Import-Module -Name $moduleManifestPath -Force -Verbose:$false
}

InModuleScope azure.datafactory.tools {
$testHelperPath = $PSScriptRoot | Join-Path -ChildPath 'TestHelper'
Import-Module -Name $testHelperPath -Force

# Variables for use in tests
$t = Get-TargetEnv 'adf2'
$script:DataFactoryOrigName = $t.DataFactoryOrigName
$script:DataFactoryName = $t.DataFactoryName
$script:Location = $t.Location
$script:ResourceGroupName = $t.ResourceGroupName
$script:Stage = 'UAT'
$script:RootFolder = Join-Path $PSScriptRoot $t.DataFactoryOrigName
$script:adf = Import-AdfFromFolder -FactoryName $script:DataFactoryName -RootFolder $script:RootFolder
$adf.ResourceGroupName = $t.ResourceGroupName
$adf.Region = $t.Location
$o = New-AdfPublishOption
$o.StopStartTriggers = $false
$o.Includes.Add('cred*.*','')
$adf.PublishOptions = $o
Publish-AdfV2FromJson -RootFolder $RootFolder -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName -Option $o -Location $Location
$script:adfIns = Get-AdfFromService -FactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName


Describe 'Remove-AdfObjectRestAPI' {
It 'Should exist' {
{ Get-Command -Name 'Remove-AdfObjectRestAPI' -ErrorAction Stop } | Should -Not -Throw
}

Context 'When called Remove-AdfObjectRestAPI' {
It 'Should delete the existing credential object' {
$objCountBefore = $adfIns.AllObjects().Count
Remove-AdfObjectRestAPI -type_plural 'credentials' -name 'credential1' -adfInstance $script:adfIns
$adfIns = Get-AdfFromService -FactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
$objCountAfter = $adfIns.AllObjects().Count
$objCountAfter | Should -Be ($objCountBefore-1)
}
}


}
}
2 changes: 1 addition & 1 deletion test/adf2/credential/credential1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"properties": {
"type": "ManagedIdentity",
"typeProperties": {
"resourceId": "/subscriptions/7d6cdb5f-be97-4907-a34c-66635a3f607d/resourceGroups/ADF.procfwk/providers/Microsoft.ManagedIdentity/userAssignedIdentities/iau-test1"
"resourceId": "/subscriptions/7d6cdb5f-be97-4907-a34c-66635a3f607d/resourceGroups/rg-devops-factory/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adftoolstest1"
}
}
}
34 changes: 34 additions & 0 deletions test/adf2/trigger/TR_without_pipeline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "tr_without_pipeline",
"properties": {
"description": "Backend will fail with this",
"annotations": [],
"runtimeState": "Started",
"pipelines": [
],
"type": "ScheduleTrigger",
"typeProperties": {
"recurrence": {
"frequency": "Week",
"interval": 1,
"startTime": "2023-02-15T19:32:00",
"timeZone": "FLE Standard Time",
"schedule": {
"minutes": [
11
],
"hours": [
5
],
"weekDays": [
"Thursday",
"Friday",
"Monday",
"Tuesday",
"Wednesday"
]
}
}
}
}
}
Loading