squid/.drone/lib/util.libsonnet

60 lines
1.2 KiB
Plaintext

local compose = import '../node_modules/@sigyl/jsonnet-compose/compose.libsonnet';
{
// the head of an array
head(array): array[0],
// the tail of an array
tail(array): std.makeArray(
std.length(array) -1,
function(x) array[x + 1],
),
fromSecret(secret): {
from_secret: secret,
},
secret(secret): std.asciiLower(
std.strReplace(
secret,
'_',
'-',
),
),
environment(secret): std.asciiUpper(
std.strReplace(
secret,
'-',
'_',
),
),
env(secret): std.asciiLower(
std.strReplace(
secret,
'-',
'_',
),
),
envSet(env): function(step) step {
environment +: {
[$.environment(env)]: $.fromSecret(
$.secret(env)
),
},
settings +: {
envs +: [
$.env(env),
],
},
},
printEnv(file, env): function(step) compose([
$.envSet(env),
function(step) step {
settings +: {
script +: [
'echo "export %(environment)s=\'$${%(environment)s}\'" >> %(file)s # "%(secret)s"' % {
environment: $.environment(env),
file: file,
secret: $.secret(env),
},
],
},
},
])(step),
}