major refactor
- change autogenerated folder to autodocs/httpyac - renamed many environment variables - add config section to env template to manage different apps - cleanup bruno environments for easier automation of env files - add pre-request and post-response scripts from bruno - manage EFTL-specific scripts - add scripts to setup json template - add scripts to update environment files
This commit is contained in:
+1
-1
@@ -11,6 +11,6 @@ node_modules
|
|||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# Automatically generated stuff
|
# Automatically generated stuff
|
||||||
autogen/**/*
|
autodocs/**/*
|
||||||
|
|
||||||
*.temp
|
*.temp
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
name: "ESSE3 Pre-Prod #2"
|
name: "ESSE3 Anagrafica Pre-Prod #2"
|
||||||
variables:
|
variables:
|
||||||
- name: rootUrl
|
- name: esse3apiRootUrl
|
||||||
value: https://unipr2.esse3.pp.cineca.it
|
value: https://unipr2.esse3.pp.cineca.it
|
||||||
- name: esse3apiUsername
|
- name: esse3apiUsername
|
||||||
value: "{{process.env.esse3apiUsername}}"
|
value: "{{process.env.esse3apiUsername}}"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ request:
|
|||||||
password: "{{esse3apiPassword}}"
|
password: "{{esse3apiPassword}}"
|
||||||
variables:
|
variables:
|
||||||
- name: baseUrl
|
- name: baseUrl
|
||||||
value: "{{rootUrl}}/e3rest/api/anagrafica-service-v2"
|
value: "{{esse3apiRootUrl}}/anagrafica-service-v2"
|
||||||
bundled: false
|
bundled: false
|
||||||
extensions:
|
extensions:
|
||||||
bruno:
|
bruno:
|
||||||
|
|||||||
@@ -4,3 +4,5 @@ variables:
|
|||||||
value: "{{process.env.esse3apiUsername}}"
|
value: "{{process.env.esse3apiUsername}}"
|
||||||
- name: esse3apiPassword
|
- name: esse3apiPassword
|
||||||
value: "{{process.env.esse3apiPassword}}"
|
value: "{{process.env.esse3apiPassword}}"
|
||||||
|
- name: esse3apiRootUrl
|
||||||
|
value: https://unipr2.esse3.pp.cineca.it/e3rest/api
|
||||||
|
|||||||
@@ -21,11 +21,7 @@ request:
|
|||||||
password: "{{esse3apiPassword}}"
|
password: "{{esse3apiPassword}}"
|
||||||
variables:
|
variables:
|
||||||
- name: baseUrl
|
- name: baseUrl
|
||||||
value: https://unipr2.esse3.pp.cineca.it/e3rest/api
|
value: "{{esse3apiRootUrl}}"
|
||||||
- name: esse3apiUsername
|
|
||||||
value: da2.rest
|
|
||||||
- name: esse3apiPassword
|
|
||||||
value: paperino
|
|
||||||
bundled: false
|
bundled: false
|
||||||
extensions:
|
extensions:
|
||||||
bruno:
|
bruno:
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
IdemApiPassword_Test=
|
IdemApiUsername=
|
||||||
IdemApiPassword_Prod=
|
IdemApiPassword=
|
||||||
IdemApiKey_Prod=
|
IdemApiKey=
|
||||||
IdemApiKey_Test=
|
|
||||||
|
|||||||
@@ -5,43 +5,11 @@ info:
|
|||||||
|
|
||||||
http:
|
http:
|
||||||
method: GET
|
method: GET
|
||||||
url: "{{IdemApiUrl}}/contratto_fs_esteso_ap.php?cod_con=DONO_G_25_ACC_ACC_ZOETIS_01"
|
url: "{{IdemApiUrl}}/contratto_fs_esteso_ap.php?cod_con=GATT_M_26_CCS_IST_RA_UNIFE_01"
|
||||||
params:
|
params:
|
||||||
- name: cod_con
|
- name: cod_con
|
||||||
value: CHIA_L_26_ACC_ACC_PROROGASTUDIOBALLERINI_01
|
value: GATT_M_26_CCS_IST_RA_UNIFE_01
|
||||||
type: query
|
type: query
|
||||||
disabled: true
|
|
||||||
- name: cod_con
|
|
||||||
value: BUTT_F_26_SPONSOR_CHIESI_02
|
|
||||||
type: query
|
|
||||||
disabled: true
|
|
||||||
- name: cod_con
|
|
||||||
value: GIUL_F_25_CRCT_RA_MOVYON_01
|
|
||||||
type: query
|
|
||||||
disabled: true
|
|
||||||
- name: cod_con
|
|
||||||
value: VIGN_G_26_SERV_CON_DULEVO_01
|
|
||||||
type: query
|
|
||||||
disabled: true
|
|
||||||
- name: cod_con
|
|
||||||
value: VILL_P_26_SPONSOR_CREDIT_01
|
|
||||||
type: query
|
|
||||||
disabled: true
|
|
||||||
- name: cod_con
|
|
||||||
value: STOR_F_26_CONV_QUA_AMICIPILOTTA_01
|
|
||||||
type: query
|
|
||||||
disabled: true
|
|
||||||
- name: cod_con
|
|
||||||
value: DONO_G_25_ACC_ACC_ZOETIS_01
|
|
||||||
type: query
|
|
||||||
- name: cod_con
|
|
||||||
value: VERO_L_26_CRCT_RA_AOUPR_01
|
|
||||||
type: query
|
|
||||||
disabled: true
|
|
||||||
- name: cod_con
|
|
||||||
value: POGL_F_25_SERV_CON_02
|
|
||||||
type: query
|
|
||||||
disabled: true
|
|
||||||
auth: inherit
|
auth: inherit
|
||||||
|
|
||||||
runtime:
|
runtime:
|
||||||
|
|||||||
+4
-4
@@ -1,11 +1,11 @@
|
|||||||
name: IDEM - Prod
|
name: Produzione
|
||||||
color: "#2E8A54"
|
color: "#2E8A54"
|
||||||
variables:
|
variables:
|
||||||
- name: IdemApiUrl
|
- name: IdemApiUrl
|
||||||
value: https://www.idem.unipr.it/ws/elix
|
value: https://www.idem.unipr.it/ws/elix
|
||||||
- name: IdemApiUsername
|
- name: IdemApiUsername
|
||||||
value: elix_ws
|
value: "{{process.env.IdemApiUsername}}"
|
||||||
- name: IdemApiPassword
|
- name: IdemApiPassword
|
||||||
value: "{{process.env.IdemApiPassword_Prod}}"
|
value: "{{process.env.IdemApiPassword}}"
|
||||||
- name: IdemApiKey
|
- name: IdemApiKey
|
||||||
value: "{{process.env.IdemApiKey_Prod}}"
|
value: "{{process.env.IdemApiKey}}"
|
||||||
+4
-4
@@ -1,11 +1,11 @@
|
|||||||
name: IDEM - Test
|
name: Test
|
||||||
color: "#C77A0F"
|
color: "#C77A0F"
|
||||||
variables:
|
variables:
|
||||||
- name: IdemApiUrl
|
- name: IdemApiUrl
|
||||||
value: https://www.idem2.unipr.it/ws/elix
|
value: https://www.idem2.unipr.it/ws/elix
|
||||||
- name: IdemApiUsername
|
- name: IdemApiUsername
|
||||||
value: elix_ws
|
value: "{{process.env.IdemApiUsername}}"
|
||||||
- name: IdemApiPassword
|
- name: IdemApiPassword
|
||||||
value: "{{process.env.IdemApiPassword_Test}}"
|
value: "{{process.env.IdemApiPassword}}"
|
||||||
- name: IdemApiKey
|
- name: IdemApiKey
|
||||||
value: "{{process.env.IdemApiKey_Test}}"
|
value: "{{process.env.IdemApiKey}}"
|
||||||
@@ -2,9 +2,7 @@ name: elixForms - Prod
|
|||||||
color: "#2E8A54"
|
color: "#2E8A54"
|
||||||
variables:
|
variables:
|
||||||
- name: elixFormsApiUrl
|
- name: elixFormsApiUrl
|
||||||
value: "{{elixFormsRootUrl}}/eF/services/api"
|
value: https://procedure.unipr.it/eF/services/api
|
||||||
- name: elixFormsRootUrl
|
|
||||||
value: https://procedure.unipr.it
|
|
||||||
- name: elixFormsApiUsername
|
- name: elixFormsApiUsername
|
||||||
value: "{{process.env.elixFormsApiUsername}}"
|
value: "{{process.env.elixFormsApiUsername}}"
|
||||||
- name: elixRegisterResultColumns
|
- name: elixRegisterResultColumns
|
||||||
@@ -12,6 +10,6 @@ variables:
|
|||||||
- name: elixFormsWsAuthenticationToken
|
- name: elixFormsWsAuthenticationToken
|
||||||
value: "{{process.env.elixFormsWsAuthenticationToken}}"
|
value: "{{process.env.elixFormsWsAuthenticationToken}}"
|
||||||
- name: elixFormsApiUrl_Default
|
- name: elixFormsApiUrl_Default
|
||||||
value: "{{elixFormsRootUrl}}/eF/api"
|
value: https://procedure.unipr.it/eF/api
|
||||||
- name: elixFormsApiPassword
|
- name: elixFormsApiPassword
|
||||||
value: "{{process.env.elixFormsApiPassword}}"
|
value: "{{process.env.elixFormsApiPassword}}"
|
||||||
|
|||||||
+22
-8
@@ -1,27 +1,41 @@
|
|||||||
{
|
{
|
||||||
|
"Config": {
|
||||||
|
"ExcludeFromBruno": [
|
||||||
|
"elixFormsApiUrl",
|
||||||
|
"elixFormsApiUrl_Default",
|
||||||
|
"esse3apiRootUrl",
|
||||||
|
"IdemApiUrl",
|
||||||
|
"IrisApiUrl"
|
||||||
|
]
|
||||||
|
},
|
||||||
"API": {
|
"API": {
|
||||||
"elixForms API v2": {
|
"elixForms API v2": {
|
||||||
"elixFormsWsAuthenticationToken": null,
|
"elixFormsApiUrl": "https://procedure.unipr.it/eF/services/api",
|
||||||
|
"elixFormsApiUrl_Default": "https://procedure.unipr.it/eF/api",
|
||||||
|
"elixFormsApiUsername": null,
|
||||||
"elixFormsApiPassword": null,
|
"elixFormsApiPassword": null,
|
||||||
"elixFormsApiUsername": null
|
"elixFormsWsAuthenticationToken": null
|
||||||
},
|
},
|
||||||
"ESSE3 Anagrafica API": {
|
"ESSE3 Anagrafica API": {
|
||||||
|
"esse3apiRootUrl": "https://unipr2.esse3.pp.cineca.it/e3rest/api",
|
||||||
"esse3apiUsername": null,
|
"esse3apiUsername": null,
|
||||||
"esse3apiPassword": null
|
"esse3apiPassword": null
|
||||||
},
|
},
|
||||||
"ESSE3 Common Auth API": {
|
"ESSE3 Common Auth API": {
|
||||||
|
"esse3apiRootUrl": "https://unipr2.esse3.pp.cineca.it/e3rest/api",
|
||||||
"esse3apiUsername": null,
|
"esse3apiUsername": null,
|
||||||
"esse3apiPassword": null
|
"esse3apiPassword": null
|
||||||
},
|
},
|
||||||
"IDEM WebServices": {
|
"IDEM WebServices": {
|
||||||
"IdemApiPassword_Test": null,
|
"IdemApiUrl": "https://www.idem.unipr.it/ws/elix",
|
||||||
"IdemApiPassword_Prod": null,
|
"IdemApiUsername": null,
|
||||||
"IdemApiKey_Prod": null,
|
"IdemApiPassword": null,
|
||||||
"IdemApiKey_Test": null
|
"IdemApiKey": null
|
||||||
},
|
},
|
||||||
"IRIS GW (Gateway) REST API (v1)": {
|
"IRIS GW (Gateway) REST API (v1)": {
|
||||||
"IrisApiPassword": null,
|
"IrisApiUrl": "https://air.unipr.it/gw/rest/api",
|
||||||
"IrisApiUsername": null
|
"IrisApiUsername": null,
|
||||||
|
"IrisApiPassword": null
|
||||||
},
|
},
|
||||||
"Scopus": {
|
"Scopus": {
|
||||||
"ScopusApiKey1": null,
|
"ScopusApiKey1": null,
|
||||||
|
|||||||
@@ -201,12 +201,24 @@ function Parse-HttpBlock ($text) {
|
|||||||
$body = $http.body
|
$body = $http.body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$preRequestScript = $parsed.runtime?.scripts | Where-Object { $_.type -eq 'before-request' } | Select-Object -First 1 -ExpandProperty 'code'
|
||||||
|
# $preRequestScript = $null
|
||||||
|
# if ($parsed.runtime -and ($parsed.runtime -is [psobject] -or $parsed.runtime -is [hashtable])) {
|
||||||
|
# }
|
||||||
|
|
||||||
|
$postResponseScript = $parsed.runtime?.scripts | Where-Object { $_.type -eq 'after-response' } | Select-Object -First 1 -ExpandProperty 'code'
|
||||||
|
# $postResponseScript = $null
|
||||||
|
# if ($parsed.runtime -and ($parsed.runtime -is [psobject] -or $parsed.runtime -is [hashtable])) {
|
||||||
|
# }
|
||||||
|
|
||||||
return @{
|
return @{
|
||||||
method = $http.method ?? 'GET'
|
method = $http.method ?? 'GET'
|
||||||
url = $http.url ?? ''
|
url = $http.url ?? ''
|
||||||
params = $params
|
params = $params
|
||||||
headers = $headers
|
headers = $headers
|
||||||
body = $body
|
body = $body
|
||||||
|
preRequestScript = $preRequestScript
|
||||||
|
postResponseScript = $postResponseScript
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,7 +382,13 @@ function Get-RequestConfigForFile ($yamlFile, $sourceDir) {
|
|||||||
$dirChain = @()
|
$dirChain = @()
|
||||||
$currentDir = Split-Path -LiteralPath $yamlFile
|
$currentDir = Split-Path -LiteralPath $yamlFile
|
||||||
|
|
||||||
|
$result = @{}
|
||||||
|
|
||||||
while ($true) {
|
while ($true) {
|
||||||
|
if ($currentDir -match [regex]::Escape("EFTL processing")) {
|
||||||
|
$result.hasEftlProcessing = $true
|
||||||
|
}
|
||||||
|
|
||||||
$dirChain = ,$currentDir + $dirChain
|
$dirChain = ,$currentDir + $dirChain
|
||||||
if ($currentDir -eq $sourceDir) {
|
if ($currentDir -eq $sourceDir) {
|
||||||
break
|
break
|
||||||
@@ -390,7 +408,6 @@ function Get-RequestConfigForFile ($yamlFile, $sourceDir) {
|
|||||||
# Aggiungi il file principale
|
# Aggiungi il file principale
|
||||||
Add-File $yamlFile
|
Add-File $yamlFile
|
||||||
|
|
||||||
$result = @{}
|
|
||||||
foreach ($config in $resolved.Value) {
|
foreach ($config in $resolved.Value) {
|
||||||
$result = Merge-RequestConfig $result $config
|
$result = Merge-RequestConfig $result $config
|
||||||
}
|
}
|
||||||
@@ -513,6 +530,38 @@ function Build-RequestContent ($request, $requestName, $requestConfig = @{}, [re
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Replace-PreRequestEftlScript ($inputText) {
|
||||||
|
# Sostituisce tutto fino al primo [EFTL] con codice specifico
|
||||||
|
$processedPreRequest = ($inputText -replace '^[\s\S]*?(?=\[EFTL\])', "exports.elixBase64EftlDocument = btoa(String.raw```n")
|
||||||
|
# Sostituisce tutto fino al primo [EFTL] con codice specifico
|
||||||
|
$processedPreRequest = ($processedPreRequest -replace '(?s)(.*\[/EFTL\]).*$', "`$1`n``);")
|
||||||
|
return $processedPreRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
function Add-DefaultPostResponseEftlScript {
|
||||||
|
return @"
|
||||||
|
var status = response.statusCode;
|
||||||
|
|
||||||
|
if (status !== 200) {
|
||||||
|
console.log("ERRORE HTTP! Response status code: " + status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var decodedDocument = "";
|
||||||
|
var response = response.parsedBody;
|
||||||
|
|
||||||
|
if (response.value.code === "ERROR") {
|
||||||
|
decodedDocument = "ERRORE EFTL!\n";
|
||||||
|
decodedDocument += response.value.description.split("\n").slice(0, 3).join("\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
decodedDocument = atob(response.value.processedDocument);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(decodedDocument);
|
||||||
|
"@
|
||||||
|
}
|
||||||
|
|
||||||
# -------------------------
|
# -------------------------
|
||||||
# Variabili da requestConfig
|
# Variabili da requestConfig
|
||||||
# -------------------------
|
# -------------------------
|
||||||
@@ -679,6 +728,24 @@ function Build-RequestContent ($request, $requestName, $requestConfig = @{}, [re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# -------------------------
|
||||||
|
# Super-special treatment for requests belonging to elixForms API v2\EFTL Processing folder
|
||||||
|
# Here we blindly assume that ALL requests must be treated in the same way!
|
||||||
|
# Pre-request script is taken from the original request and manipulated so it can be integrated into the generated .http file
|
||||||
|
# -------------------------
|
||||||
|
if ($request.preRequestScript) {
|
||||||
|
$lines += ''
|
||||||
|
$lines += "{{"
|
||||||
|
$lines += "// Pre-request script"
|
||||||
|
if ($requestConfig.hasEftlProcessing) {
|
||||||
|
$lines += (Replace-PreRequestEftlScript $request.preRequestScript)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$lines += $request.preRequestScript
|
||||||
|
}
|
||||||
|
$lines += "}}"
|
||||||
|
}
|
||||||
|
|
||||||
# -------------------------
|
# -------------------------
|
||||||
# Final request line
|
# Final request line
|
||||||
# -------------------------
|
# -------------------------
|
||||||
@@ -703,6 +770,26 @@ function Build-RequestContent ($request, $requestName, $requestConfig = @{}, [re
|
|||||||
$lines += $requestBody
|
$lines += $requestBody
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# -------------------------
|
||||||
|
# Super-special treatment for requests belonging to elixForms API v2\EFTL Processing folder
|
||||||
|
# Here we blindly assume that ALL requests must be treated in the same way!
|
||||||
|
# Post-response script is overwritten by default so it should magically work
|
||||||
|
# -------------------------
|
||||||
|
if ($requestConfig.hasEftlProcessing) {
|
||||||
|
$lines += ''
|
||||||
|
$lines += "{{"
|
||||||
|
$lines += "// Post-response script (EFTL)"
|
||||||
|
$lines += Add-DefaultPostResponseEftlScript
|
||||||
|
$lines += "}}"
|
||||||
|
}
|
||||||
|
elseif ($request.postResponseScript) {
|
||||||
|
$lines += ''
|
||||||
|
$lines += "{{"
|
||||||
|
$lines += "// Post-response script"
|
||||||
|
$lines += $request.postResponseScript
|
||||||
|
$lines += "}}"
|
||||||
|
}
|
||||||
|
|
||||||
return ($lines -join "`n")
|
return ($lines -join "`n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -729,7 +816,7 @@ function Clean-Folder($dir) {
|
|||||||
Remove-Item -LiteralPath $entry.FullName -Force
|
Remove-Item -LiteralPath $entry.FullName -Force
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!$entry.PSIsContainer -and $entry.Name -match '\.js$|\.http$|\.env\.template$') {
|
if (!$entry.PSIsContainer -and $entry.Name -match '\.js$|\.http$|^\.env\..*$') {
|
||||||
Remove-Item -LiteralPath $entry.FullName -Force
|
Remove-Item -LiteralPath $entry.FullName -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -922,7 +1009,7 @@ function Invoke-Main {
|
|||||||
throw "No collections found in workspace.yml"
|
throw "No collections found in workspace.yml"
|
||||||
}
|
}
|
||||||
|
|
||||||
$outputBaseRoot = Join-Path $workspaceRoot 'autogen/httpyac_ps1'
|
$outputBaseRoot = Join-Path $workspaceRoot 'autodocs/httpyac'
|
||||||
Clean-Folder $outputBaseRoot
|
Clean-Folder $outputBaseRoot
|
||||||
|
|
||||||
foreach ($collection in $collections) {
|
foreach ($collection in $collections) {
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ function Ask-YesNo($message) {
|
|||||||
while ($true) {
|
while ($true) {
|
||||||
$resp = Read-Host "$message [YySs/Nn]"
|
$resp = Read-Host "$message [YySs/Nn]"
|
||||||
switch ($resp.ToUpper()) {
|
switch ($resp.ToUpper()) {
|
||||||
"N" { return $false }
|
"Y" { return $true }
|
||||||
default { return $true }
|
"S" { return $true }
|
||||||
|
default { return $false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,14 +33,17 @@ function Ask-Value($key) {
|
|||||||
$newJson = [ordered]@{}
|
$newJson = [ordered]@{}
|
||||||
|
|
||||||
foreach ($topKey in $parsedJson.Keys) {
|
foreach ($topKey in $parsedJson.Keys) {
|
||||||
|
if ($topKey -eq "Config") {
|
||||||
|
# Copia Config senza modifiche, i parametri serviranno dopo la generazione
|
||||||
|
$newJson["Config"] = $parsedJson["Config"]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
# Sezione API → trattamento speciale
|
# Sezione API → trattamento speciale
|
||||||
if ($topKey -eq "API") {
|
if ($topKey -eq "API") {
|
||||||
|
|
||||||
$newJson["API"] = [ordered]@{}
|
$newJson["API"] = [ordered]@{}
|
||||||
|
|
||||||
foreach ($sectionName in $parsedJson["API"].Keys) {
|
foreach ($sectionName in $parsedJson["API"].Keys) {
|
||||||
|
|
||||||
$section = $parsedJson["API"][$sectionName]
|
$section = $parsedJson["API"][$sectionName]
|
||||||
|
|
||||||
$shouldConfigure = Ask-YesNo "Vuoi configurare la sezione '$sectionName'?"
|
$shouldConfigure = Ask-YesNo "Vuoi configurare la sezione '$sectionName'?"
|
||||||
@@ -69,6 +73,12 @@ foreach ($topKey in $parsedJson.Keys) {
|
|||||||
$newSection = [ordered]@{}
|
$newSection = [ordered]@{}
|
||||||
|
|
||||||
foreach ($key in $section.Keys) {
|
foreach ($key in $section.Keys) {
|
||||||
|
if ($key -eq "_httpyac_only") {
|
||||||
|
# Mantieni la chiave speciale senza chiedere input
|
||||||
|
$newSection[$key] = $section[$key]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
$inputValue = Ask-Value $key
|
$inputValue = Ask-Value $key
|
||||||
|
|
||||||
if ($existingEnv -and $existingEnv["API"] -and $existingEnv["API"].Contains($sectionName)) {
|
if ($existingEnv -and $existingEnv["API"] -and $existingEnv["API"].Contains($sectionName)) {
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
# Percorsi file
|
||||||
|
$envFile = Join-Path $PSScriptRoot ".." "env.json" # JSON originale
|
||||||
|
$collectionsRoot = Join-Path $PSScriptRoot ".." "collections" # cartella di partenza delle collezioni
|
||||||
|
|
||||||
|
# Costanti
|
||||||
|
$ENV_JSON_FILENAME = "env.json"
|
||||||
|
$CFG_SECTION_NAME = "Config"
|
||||||
|
$EXCLUDE_BRUNO_CFG_NAME = "ExcludeFromBruno"
|
||||||
|
$API_SECTION_NAME = "API"
|
||||||
|
$ENV_TEMPLATE_FILENAME = ".env.template"
|
||||||
|
$ENV_FILENAME = ".env"
|
||||||
|
|
||||||
|
# 1. Se il file non esiste → errore
|
||||||
|
if (-not (Test-Path $envFile)) {
|
||||||
|
Write-Error "File '$ENV_JSON_FILENAME' non trovato."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Carica JSON mantenendo ordine
|
||||||
|
$raw = Get-Content $envFile -Raw
|
||||||
|
$data = $raw | ConvertFrom-Json -AsHashtable
|
||||||
|
|
||||||
|
if (-not $data.ContainsKey($API_SECTION_NAME)) {
|
||||||
|
Write-Error "Il file '$ENV_JSON_FILENAME' non contiene la sezione '$API_SECTION_NAME'."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Funzione per leggere file .env (KEY=VALUE)
|
||||||
|
function Read-EnvFile($path) {
|
||||||
|
$result = [ordered]@{}
|
||||||
|
foreach ($line in Get-Content $path) {
|
||||||
|
if ($line.Trim() -eq "" -or $line.Trim().StartsWith("#")) { continue }
|
||||||
|
if ($line -match "^\s*([^=]+)\s*=\s*(.*)$") {
|
||||||
|
$key = $matches[1].Trim()
|
||||||
|
$value = $matches[2]
|
||||||
|
$result[$key] = $value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
|
# Funzione per scrivere file .env
|
||||||
|
function Write-EnvFile($path, $hashtable) {
|
||||||
|
$lines = foreach ($k in $hashtable.Keys) {
|
||||||
|
"$k=$(Format-EnvValue $hashtable[$k])"
|
||||||
|
}
|
||||||
|
Set-Content $path -Value $lines -Encoding UTF8
|
||||||
|
}
|
||||||
|
|
||||||
|
function Format-EnvValue($value) {
|
||||||
|
if ($null -eq $value) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if ($value -match "#") {
|
||||||
|
return "'$value'"
|
||||||
|
}
|
||||||
|
return $value
|
||||||
|
}
|
||||||
|
|
||||||
|
function KeysMatch($a, $b) {
|
||||||
|
$diff = Compare-Object -ReferenceObject ($a | Sort-Object -Unique) -DifferenceObject ($b | Sort-Object -Unique)
|
||||||
|
|
||||||
|
return -not $diff
|
||||||
|
}
|
||||||
|
|
||||||
|
# 2a. Leggi la configurazione di base (Config) se presente
|
||||||
|
$config = $null
|
||||||
|
$noBrunoKeys = @()
|
||||||
|
if ($data.ContainsKey($CFG_SECTION_NAME)) {
|
||||||
|
$config = $data[$CFG_SECTION_NAME]
|
||||||
|
if ($config.ContainsKey($EXCLUDE_BRUNO_CFG_NAME)) {
|
||||||
|
$noBrunoKeys = $config[$EXCLUDE_BRUNO_CFG_NAME]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 2. Scorri tutte le sezioni sotto API
|
||||||
|
foreach ($sectionName in $data[$API_SECTION_NAME].Keys) {
|
||||||
|
|
||||||
|
Write-Host "`n--- Sezione: $sectionName ---"
|
||||||
|
|
||||||
|
$section = $data[$API_SECTION_NAME][$sectionName]
|
||||||
|
|
||||||
|
# a. Verifica esistenza cartella
|
||||||
|
$folder = Join-Path $collectionsRoot $sectionName
|
||||||
|
if (-not (Test-Path $folder)) {
|
||||||
|
Write-Warning "La cartella '$folder' non esiste. Sezione ignorata."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# b. Verifica .env.template
|
||||||
|
$templatePath = Join-Path $folder $ENV_TEMPLATE_FILENAME
|
||||||
|
if (Test-Path $templatePath) {
|
||||||
|
$template = Read-EnvFile $templatePath
|
||||||
|
|
||||||
|
$templateKeys = $template.Keys
|
||||||
|
$sectionKeys = $section.Keys | Where-Object { $_ -notin $noBrunoKeys }
|
||||||
|
|
||||||
|
if ($templateKeys.Count -ne $sectionKeys.Count -or -not (KeysMatch $templateKeys $sectionKeys)) {
|
||||||
|
Write-Warning "Il file '$ENV_TEMPLATE_FILENAME' in '$sectionName' non ha le stesse chiavi della sezione."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# c/d/e. Gestione file .env
|
||||||
|
$envPath = Join-Path $folder $ENV_FILENAME
|
||||||
|
|
||||||
|
if (-not (Test-Path $envPath)) {
|
||||||
|
# c. Genera nuovo file .env
|
||||||
|
Write-Host "Generazione nuovo file '$ENV_FILENAME' per '$sectionName'."
|
||||||
|
$newEnv = [ordered]@{}
|
||||||
|
foreach ($key in $sectionKeys) {
|
||||||
|
$newEnv[$key] = $section[$key]
|
||||||
|
}
|
||||||
|
Write-EnvFile $envPath $newEnv
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# d. Verifica chiavi .env esistente
|
||||||
|
$existingEnv = Read-EnvFile $envPath
|
||||||
|
|
||||||
|
$envKeys = $existingEnv.Keys
|
||||||
|
$sectionKeys = $section.Keys | Where-Object { $_ -notin $noBrunoKeys }
|
||||||
|
|
||||||
|
if ($envKeys.Count -ne $sectionKeys.Count -or -not (KeysMatch $envKeys $sectionKeys)) {
|
||||||
|
Write-Warning "Il file '$ENV_FILENAME' in '$sectionName' non ha le stesse chiavi della sezione."
|
||||||
|
}
|
||||||
|
|
||||||
|
# e. Aggiorna valori
|
||||||
|
$updatedEnv = [ordered]@{}
|
||||||
|
|
||||||
|
foreach ($key in $sectionKeys) {
|
||||||
|
$valueFromJson = $section[$key]
|
||||||
|
|
||||||
|
if ($existingEnv.Contains($key)) {
|
||||||
|
if ($null -ne $valueFromJson) {
|
||||||
|
# aggiorna
|
||||||
|
$updatedEnv[$key] = $valueFromJson
|
||||||
|
} else {
|
||||||
|
# mantieni
|
||||||
|
$updatedEnv[$key] = $existingEnv[$key]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
# chiave mancante → aggiungi
|
||||||
|
$updatedEnv[$key] = $valueFromJson
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Aggiornamento file '$ENV_FILENAME' per '$sectionName'..."
|
||||||
|
Write-EnvFile $envPath $updatedEnv
|
||||||
|
Write-Host "File '$(Resolve-Path -LiteralPath $envPath)' aggiornato."
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "`nOperazione completata."
|
||||||
+28
-13
@@ -1,11 +1,15 @@
|
|||||||
# Percorsi file
|
# Percorsi file
|
||||||
$envFile = Join-Path $PSScriptRoot ".." "env.json" # JSON originale
|
$envFile = Join-Path $PSScriptRoot ".." "env.json" # JSON originale
|
||||||
$collectionsRoot = Join-Path $PSScriptRoot ".." "collections" # cartella di partenza delle collezioni
|
$collectionsRoot = Join-Path $PSScriptRoot ".." "autodocs/httpyac" # cartella di partenza delle collezioni
|
||||||
|
|
||||||
|
# Costanti
|
||||||
|
$API_SECTION_NAME = "API"
|
||||||
|
$ENV_TEMPLATE_FILENAME = ".env.template"
|
||||||
|
$ENV_FILENAME = ".env"
|
||||||
|
|
||||||
# 1. Se il file non esiste → errore
|
# 1. Se il file non esiste → errore
|
||||||
if (-not (Test-Path $envFile)) {
|
if (-not (Test-Path $envFile)) {
|
||||||
Write-Error "File env.json non trovato."
|
Write-Error "File '$ENV_JSON_FILENAME' non trovato."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,8 +17,8 @@ if (-not (Test-Path $envFile)) {
|
|||||||
$raw = Get-Content $envFile -Raw
|
$raw = Get-Content $envFile -Raw
|
||||||
$data = $raw | ConvertFrom-Json -AsHashtable
|
$data = $raw | ConvertFrom-Json -AsHashtable
|
||||||
|
|
||||||
if (-not $data.ContainsKey("API")) {
|
if (-not $data.ContainsKey($API_SECTION_NAME)) {
|
||||||
Write-Error "Il file env.json non contiene la sezione 'API'."
|
Write-Error "Il file '$ENV_JSON_FILENAME' non contiene la sezione '$API_SECTION_NAME'."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,11 +61,11 @@ function KeysMatch($a, $b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 2. Scorri tutte le sezioni sotto API
|
# 2. Scorri tutte le sezioni sotto API
|
||||||
foreach ($sectionName in $data["API"].Keys) {
|
foreach ($sectionName in $data[$API_SECTION_NAME].Keys) {
|
||||||
|
|
||||||
Write-Host "`n--- Sezione: $sectionName ---"
|
Write-Host "`n--- Sezione: $sectionName ---"
|
||||||
|
|
||||||
$section = $data["API"][$sectionName]
|
$section = $data[$API_SECTION_NAME][$sectionName]
|
||||||
|
|
||||||
# a. Verifica esistenza cartella
|
# a. Verifica esistenza cartella
|
||||||
$folder = Join-Path $collectionsRoot $sectionName
|
$folder = Join-Path $collectionsRoot $sectionName
|
||||||
@@ -71,7 +75,7 @@ foreach ($sectionName in $data["API"].Keys) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# b. Verifica .env.template
|
# b. Verifica .env.template
|
||||||
$templatePath = Join-Path $folder ".env.template"
|
$templatePath = Join-Path $folder $ENV_TEMPLATE_FILENAME
|
||||||
if (Test-Path $templatePath) {
|
if (Test-Path $templatePath) {
|
||||||
$template = Read-EnvFile $templatePath
|
$template = Read-EnvFile $templatePath
|
||||||
|
|
||||||
@@ -79,18 +83,18 @@ foreach ($sectionName in $data["API"].Keys) {
|
|||||||
$sectionKeys = $section.Keys
|
$sectionKeys = $section.Keys
|
||||||
|
|
||||||
if ($templateKeys.Count -ne $sectionKeys.Count -or -not (KeysMatch $templateKeys $sectionKeys)) {
|
if ($templateKeys.Count -ne $sectionKeys.Count -or -not (KeysMatch $templateKeys $sectionKeys)) {
|
||||||
Write-Warning "Il file .env.template in '$sectionName' non ha le stesse chiavi della sezione."
|
Write-Warning "Il file '$ENV_TEMPLATE_FILENAME' in '$sectionName' non ha le stesse chiavi della sezione."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# c/d/e. Gestione file .env
|
# c/d/e. Gestione file .env
|
||||||
$envPath = Join-Path $folder ".env"
|
$envPath = Join-Path $folder $ENV_FILENAME
|
||||||
|
|
||||||
if (-not (Test-Path $envPath)) {
|
if (-not (Test-Path $envPath)) {
|
||||||
# c. Genera nuovo file .env
|
# c. Genera nuovo file .env
|
||||||
Write-Host "Generazione nuovo file .env per '$sectionName'."
|
Write-Host "Generazione nuovo file '$ENV_FILENAME' per '$sectionName'."
|
||||||
$newEnv = [ordered]@{}
|
$newEnv = [ordered]@{}
|
||||||
foreach ($key in $section.Keys) {
|
foreach ($key in $sectionKeys) {
|
||||||
$newEnv[$key] = $section[$key]
|
$newEnv[$key] = $section[$key]
|
||||||
}
|
}
|
||||||
Write-EnvFile $envPath $newEnv
|
Write-EnvFile $envPath $newEnv
|
||||||
@@ -104,7 +108,7 @@ foreach ($sectionName in $data["API"].Keys) {
|
|||||||
$sectionKeys = $section.Keys
|
$sectionKeys = $section.Keys
|
||||||
|
|
||||||
if ($envKeys.Count -ne $sectionKeys.Count -or -not (KeysMatch $envKeys $sectionKeys)) {
|
if ($envKeys.Count -ne $sectionKeys.Count -or -not (KeysMatch $envKeys $sectionKeys)) {
|
||||||
Write-Warning "Il file .env in '$sectionName' non ha le stesse chiavi della sezione."
|
Write-Warning "Il file '$ENV_FILENAME' in '$sectionName' non ha le stesse chiavi della sezione."
|
||||||
}
|
}
|
||||||
|
|
||||||
# e. Aggiorna valori
|
# e. Aggiorna valori
|
||||||
@@ -127,8 +131,19 @@ foreach ($sectionName in $data["API"].Keys) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Aggiornamento file .env per '$sectionName'."
|
# f. Aggiungi chiavi mancanti da .env.template
|
||||||
|
if (Test-Path $templatePath) {
|
||||||
|
foreach ($key in $template.Keys) {
|
||||||
|
if (-not $updatedEnv.Contains($key)) {
|
||||||
|
Write-Host "Aggiunta chiave mancante '$key' da '$ENV_TEMPLATE_FILENAME'."
|
||||||
|
$updatedEnv[$key] = $template[$key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Aggiornamento file '$ENV_FILENAME' per '$sectionName'..."
|
||||||
Write-EnvFile $envPath $updatedEnv
|
Write-EnvFile $envPath $updatedEnv
|
||||||
|
Write-Host "File '$(Resolve-Path -LiteralPath $envPath)' aggiornato."
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "`nOperazione completata."
|
Write-Host "`nOperazione completata."
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
@echo off
|
||||||
|
echo %cmdcmdline% | findstr /i /c:"%~nx0" >NUL && set iscommandline=1
|
||||||
|
echo %PSModulePath% | findstr /i /c:"%USERPROFILE%" >NUL && set ispowershell=1
|
||||||
|
|
||||||
|
cd /D "%~dp0"
|
||||||
|
|
||||||
|
echo.
|
||||||
|
|
||||||
|
@pwsh -NoProfile -ExecutionPolicy Bypass -Command .\scripts\setup-json-environment.ps1 %*
|
||||||
|
|
||||||
|
echo.
|
||||||
|
|
||||||
|
IF DEFINED iscommandline IF NOT DEFINED ispowershell pause
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
@echo off
|
||||||
|
echo %cmdcmdline% | findstr /i /c:"%~nx0" >NUL && set iscommandline=1
|
||||||
|
echo %PSModulePath% | findstr /i /c:"%USERPROFILE%" >NUL && set ispowershell=1
|
||||||
|
|
||||||
|
cd /D "%~dp0"
|
||||||
|
|
||||||
|
echo.
|
||||||
|
|
||||||
|
@pwsh -NoProfile -ExecutionPolicy Bypass -Command .\scripts\update-bruno-environments.ps1 %*
|
||||||
|
|
||||||
|
echo.
|
||||||
|
|
||||||
|
IF DEFINED iscommandline IF NOT DEFINED ispowershell pause
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
@echo off
|
||||||
|
echo %cmdcmdline% | findstr /i /c:"%~nx0" >NUL && set iscommandline=1
|
||||||
|
echo %PSModulePath% | findstr /i /c:"%USERPROFILE%" >NUL && set ispowershell=1
|
||||||
|
|
||||||
|
cd /D "%~dp0"
|
||||||
|
|
||||||
|
echo.
|
||||||
|
|
||||||
|
@pwsh -NoProfile -ExecutionPolicy Bypass -Command .\scripts\update-http-requests-environments.ps1 %*
|
||||||
|
|
||||||
|
echo.
|
||||||
|
|
||||||
|
IF DEFINED iscommandline IF NOT DEFINED ispowershell pause
|
||||||
Reference in New Issue
Block a user