|
1 | 1 | local array_includes = require "api-umbrella.utils.array_includes"
|
2 | 2 | local array_last = require "api-umbrella.utils.array_last"
|
| 3 | +local deep_defaults = require "api-umbrella.utils.deep_defaults" |
3 | 4 | local deep_merge_overwrite_arrays = require "api-umbrella.utils.deep_merge_overwrite_arrays"
|
4 | 5 | local dir = require "pl.dir"
|
5 | 6 | local file = require "pl.file"
|
@@ -376,28 +377,31 @@ local function set_cached_random_tokens()
|
376 | 377 | local cached = {}
|
377 | 378 | if content then
|
378 | 379 | cached = lyaml.load(content)
|
379 |
| - deep_merge_overwrite_arrays(config, cached) |
| 380 | + deep_defaults(config, cached) |
380 | 381 | end
|
381 | 382 |
|
382 | 383 | -- If the tokens haven't already been written to the cache, generate them.
|
383 | 384 | if not config["web"]["rails_secret_token"] or not config["static_site"]["api_key"] then
|
384 | 385 | if not config["web"]["rails_secret_token"] then
|
385 |
| - cached["web"] = { |
386 |
| - rails_secret_token = random_token(128), |
387 |
| - } |
| 386 | + deep_defaults(cached, { |
| 387 | + web = { |
| 388 | + rails_secret_token = random_token(128), |
| 389 | + }, |
| 390 | + }) |
388 | 391 | end
|
389 | 392 |
|
390 | 393 | if not config["static_site"]["api_key"] then
|
391 |
| - cached["static_site"] = { |
392 |
| - api_key = random_token(40), |
393 |
| - } |
| 394 | + deep_defaults(cached, { |
| 395 | + static_site = { |
| 396 | + api_key = random_token(40), |
| 397 | + }, |
| 398 | + }) |
394 | 399 | end
|
395 | 400 |
|
396 | 401 | -- Persist the cached tokens.
|
397 | 402 | dir.makepath(config["run_dir"])
|
398 | 403 | file.write(cached_path, lyaml.dump({ cached }))
|
399 |
| - |
400 |
| - deep_merge_overwrite_arrays(config, cached) |
| 404 | + deep_defaults(config, cached) |
401 | 405 | end
|
402 | 406 | end
|
403 | 407 | end
|
|
0 commit comments