Public/global.ps1


function Import-RKConfig {
    <#
.Description
Loads a json files of settings into environments.
Useful when running locally - on the build server these would be expected to be there by default
#>

    [CmdletBinding()]
    param (
        [Parameter()]
        [string]
        $ConfigFile = "./config.json"
    )

    $Config = (Get-Content -Path $ConfigFile | ConvertFrom-Json)
    Set-RKEnvironmentVariablesFromObject $Config
}

Function Initialize-RKLocalAzureDevOpsEnvironment {
    [cmdletbinding()]
    
    param(
        [string]$ConfigPath,
        
        [string]$DevOpsLibraryName
    )
        
      Import-RKConfig $ConfigPath
      
      $config = (Get-Content $ConfigPath -Raw) | ConvertFrom-Json -AsHashtable

      $variables = Get-RKAzDevOpsLibrary -LibraryName $DevOpsLibraryName

      $orderedConfig = [Ordered]@{}    
      $i = 0
      
      foreach ($key in ($variables.Keys | Sort-Object)) {
            $orderedConfig.Insert($i, $key, $variables.Item($key))
            $i++
      }
      
      $orderedConfig.Insert(0, 'tenantId', $config.tenantId)
      $orderedConfig.Insert(1, 'subscriptionId', $config.subscriptionId)
      $orderedConfig.Insert(($orderedConfig.Count), 'azureDevOps', $config.azureDevOps)
      
      $orderedConfig | ConvertTo-Json -depth 100 | Set-Content $ConfigPath
      
      Import-RKConfig $ConfigPath
}