Version 2.0
A Python script used to convert Local Azure Function App Configuration to Azure DevOps Release Pipeline Configuration and Azure Function App Configuration.
For the C# version with executable release click here. (OUTDATED)
- Python 3.x
-
Place the
convert.py
file in your project directory. -
Run the script for the first time to generate a template configuration file:
python convert.py
This will create a
template-converter.json
file in the same directory. -
Rename
template-converter.json
togen-converter.json
and edit it to match your specific requirements. The configuration consists of the following sections:folderName
: The base folder name for output (will be prepended with "gen-").pipelineFolderName
: Folder name for the release pipeline generated config.functionAppFolderName
: Folder name for the Azure Function App generated config.searchPattern
: Pattern to search for configuration files (e.g., "C:\Path\To\Your\Project\FunctionApps.*\{files}").writeMode
: Generation mode for the config, either Overwrite or CreateNew. Overwrite mode replaces the whole base folder. CreateNew mode generates a new folder with the Unix time appended to prevent replacing the previously generated configurations.isSorted
: Sorts the generated configurations alphabetically. (true | false)reversedSort
: Reverses the order of the keys in the generated configurations. (true | false)configPath
: Contains environment mappings and file names.variables
: Defines the value per configuration keys for specific environments (You could use the environment name to reuse the previously set value for that variable e.g. #$Environment_Name$#).ignoreVariables
: List of variables to be ignored in the generated configurations (Instead of removing the variable in the 'variables' key, list out the unnecessary variables for documentation).
Replace the placeholder values with your actual configuration paths, environments, and configuration keys.
Example
gen-converter.json
file:{ "folderName": "OutputFolder", "pipelineFolderName": "PipelineConfig", "functionAppFolderName": "FunctionAppConfig", "searchPattern": "C:\\Path\\To\\Your\\Project\\FunctionApps.*\\{files}", "writeMode": "Overwrite", "isSorted": true, "reversedSort": false, "configPath": { "env": [ { "names": [ "dev", "staging", "production" ], "files": [ "local.settings.json" ] } ] }, "variables": { "dev": { "EXAMPLE_VAR": "dev_value" }, "staging": { "EXAMPLE_VAR": "staging_value" }, "production": { "EXAMPLE_VAR": "prod_value" } }, "ignoreVariables": [ "WEBSITE_RUN_FROM_PACKAGE" ] }
-
Run the script again to process the configurations:
python convert.py
-
The script will process the configurations and generate the formatted code and converted JSON files based on the specified search pattern and environment mappings.
-
The generated output will be placed in separate folders for each environment, as specified in the configuration, all within a "gen-" prefixed base folder.
The script supports the following command-line arguments:
--config
: Specify a custom path to the configuration file (default is "gen-converter.json").--LocalToPipeline
: Convert local config to pipeline config only.--PipelineToAzure
: Convert pipeline config to Azure Function App config only.--AZtoLocal
: Convert Azure Function App config to local config (requires--file
argument).--file
: Specify the input file path for AZtoLocal conversion.
Example:
python convert.py --config my-config.json --LocalToPipeline
You can customize the behavior of the Converter script by modifying the configuration in the gen-converter.json
file according to your specific needs.
Check out the actual sample files here.
For this example, let's base the configuration on the following scenario:
- You have 3 environments:
dev
,staging
, andproduction
. - In production, you have 2 different payment methods:
Paypal
andStripe
. - You have 2 Azure Function Apps:
Account
andPayment
Function Apps. - You have 3 different connection strings for each environment:
dev-connectionstring
,staging-connectionstring
, andproduction-connectionstring
. - You have 2 different API keys for each payment method:
PaypalAPIKey
andStripeAPIKey
.
For our scenario, the local.settings.json for the Payment Function App looks like this:
{
"IsEncrypted": false,
"Values": {
"DBConnectionString": "someValue",
"Version": "someValue",
"PaymentAPIKey": "someValue"
}
}
For example, you have this converter configuration:
{
"folderName": "Sample/Generated Configs",
"pipelineFolderName": "Pipeline Configs",
"functionAppFolderName": "Azure Function App Configs",
"searchPattern": "D:\\Sample\\Local Settings\\*\\local.settings.json",
"writeMode": "Overwrite",
"isSorted": true,
"reversedSort": false,
"configPath": {
"env": [
{
"names": [
"dev",
"staging"
],
"files": ["local.settings.json"]
},
{
"names": [
"production-account"
],
"files": ["local.settings.json"]
},
{
"names": [
"production-paypal",
"production-stripe"
],
"files": ["local.settings.json"]
}
]
},
"variables": {
"dev": {
"DBConnectionString": "dev-connectionstring"
},
"staging": {
"DBConnectionString": "staging-connectionstring"
},
"production-account": {
"DBConnectionString": "production-connectionstring"
},
"production-paypal": {
"DBConnectionString": "#$production-account$#",
"Version": "1.0.0",
"PaymentAPIKey": "PaypalAPIKey"
},
"production-stripe": {
"DBConnectionString": "#$production-account$#",
"Version": "1.0.1",
"PaymentAPIKey": "StripeAPIKey"
}
},
"ignoreVariables": [
"Version"
]
}
The output folder structure would be as follows:
gen-Sample\Generated Configs
|
|---dev_environment
| |
| |---Pipeline Configs
| | |
| | |---dev-AccountFA.txt
| | |---dev-PaymentFA.txt
| |
| |---Azure Function App Configs
| |
| |---dev-AccountFA.json
| |---dev-PaymentFA.json
|
|---staging_environment
| |
| |---Pipeline Configs
| | |
| | |---staging-AccountFA.txt
| | |---staging-PaymentFA.txt
| |
| |---Azure Function App Configs
| |
| |---staging-AccountFA.json
| |---staging-PaymentFA.json
|
|---production-account_environment
| |
| |---Pipeline Configs
| | |
| | |---production-account-AccountFA.txt
| |
| |---Azure Function App Configs
| |
| |---production-account-AccountFA.json
|
|---production-paypal_environment
| |
| |---Pipeline Configs
| | |
| | |---production-paypal-PaymentFA.txt
| |
| |---Azure Function App Configs
| |
| |---production-paypal-PaymentFA.json
|
|---production-stripe_environment
| |
| |---Pipeline Configs
| | |
| | |---production-stripe-PaymentFA.txt
| |
| |---Azure Function App Configs
| |
| |---production-stripe-PaymentFA.json
|
|---variable-list.json
Sample Release Pipeline config output
-DBConnectionString "dev-connectionstring" -PaymentAPIKey "DevTestAPIKey"
Sample Azure Function App config output
[
{
"name": "DBConnectionString",
"value": "dev-connectionstring",
"slotSetting": false
},
{
"name": "PaymentAPIKey",
"value": "DevTestAPIKey",
"slotSetting": false
}
]
The script generates the following outputs:
- Converted configuration files for each environment and function app.
- A
variable-list.json
file in the base output folder, containing a sorted list of all unique variables found during the conversion process.
The script prepends "gen-" to the output folder name. It's recommended to add "gen-*" to your .gitignore file to avoid accidentally pushing sensitive data to version control.
The script includes basic error handling and will print error messages if issues occur during the conversion process.
- Config Generated Metadata for easy identification of generated files (e.g. When was it generated, etc.)
- Add Error Handling
- Add Unit Tests