blob: 0181c40c11b870013bf4658fc9716c861bccd4b2 [file] [log] [blame]
garciadeblas83775ba2025-07-23 18:35:24 +02001#######################################################################################
2# Copyright ETSI Contributors and Others.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#######################################################################################
17
18# Module with helper functions to manage the replacement of placeholder variables by the values of well-known enviroment variables.
19
20
21# Helper function to replace placeholder variables by the content of their homonym environment variables in a record received from stdin.
22export def vars [
23 environment: record # Record with environment variables to load
24 defaults: record = {
25 FLEET_REPOS_BASE: "/repos"
26 CATALOG_REPOS_BASE: "/repos"
27 PROJECT_NAME: "osm_admin"
28 } # Record with default values for the variables to be replaced
29]: [
30 record -> record
31] {
32 let in_record: record = $in
33
34 # Environment with default values when undefined
35 let full_environment: record = (
36 $defaults
37 | merge $environment
38 )
39
40 let variable_enumeration: string = (
41 $full_environment
42 | columns
43 | each { |col|
44 $"\${($col)}"
45 }
46 | str join ","
47 )
48
49 $in_record
50 | to yaml
51 | with-env $full_environment {
52 $in
53 | (
54 ^envsubst $variable_enumeration
55 )
56 }
57 | from yaml
58}