Public/Save-AirTableApiKey.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function Save-AirTableApiKey {
    <#
        .SYNOPSIS
            Saves the API key to the configuration file obtained from your AirTable account at https://airtable.com/account.
    
        .EXAMPLE
            PS> Save-AirTableApiKey -ApiKey foobar

            Saves the value 'foobar' in the configuration APIKey value.
    
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$ApiKey
    )

    function encrypt([string]$TextToEncrypt) {
        $secure = ConvertTo-SecureString $TextToEncrypt -AsPlainText -Force
        $encrypted = $secure | ConvertFrom-SecureString
        return $encrypted
    }
    
    $config = Get-PSAirTableConfiguration
    $config.Application.ApiKey = encrypt($ApiKey)
    $config | ConvertTo-Json | Set-Content -Path "$WorkingDir\Configuration.json"
}