jsonnet-drone-environment/environment.libsonnet

69 lines
1.2 KiB
Plaintext
Raw Normal View History

2020-08-05 08:47:19 +00:00
{
// make secret format
secret(secret): std.asciiLower(
std.strReplace(
secret,
'_',
'-',
),
),
// make environment format
environment(secret): std.asciiUpper(
std.strReplace(
secret,
'-',
'_',
),
),
// make env format
env(secret): std.asciiLower(
std.strReplace(
secret,
'-',
'_',
),
),
// environment from secret
fromSecret(name): {
from_secret: name,
},
// set an environment and an env for ssh
envSet(env): function(step) step {
environment +: {
[$.environment(env)]: $.fromSecret(
$.secret(env)
),
},
settings +: {
envs +: [
$.env(env),
],
},
},
// set an environment to a value
envValue(env, value): function(step) step {
environment +: {
[$.environment(env)]: value,
},
settings +: {
envs +: [
$.env(env),
],
},
},
// makes environment variables and corresponding secrets
environmentSecrets(vars):
std.foldl(
function(obj, value)
obj {
[$.environment(value)]: $.fromSecret(
$.secret(
value,
),
),
},
vars,
{},
),
}