Skip to content

Commit 3e20f72

Browse files
committed
Fix rendering of multiple difficulty modes in init template
Signed-off-by: Robert Detjens <[email protected]>
1 parent adcee17 commit 3e20f72

File tree

3 files changed

+65
-34
lines changed

3 files changed

+65
-34
lines changed

src/asset_files/rcds.yaml.j2

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,51 @@ defaults:
3232
# challenges use dynamic scoring; for static points set both min and max to the
3333
# same value.
3434
points:
35-
{% for pts in points -%}
35+
{%- for pts in points %}
3636
- difficulty: "{{ pts.difficulty }}"
3737
min: {{ pts.min }}
3838
max: {{ pts.max }}
39-
{%- else -%}
39+
{%- else %}
4040
[]
41-
{% endfor %}
41+
{%- endfor %}
4242

4343
# Control what challenges are deployed in each environment profile.
4444
deploy:
45-
{% for name, _conf in profiles | items -%}
45+
{%- for name, _conf in profiles | items %}
4646
{{ name }}: {}
47-
{%- else -%}
47+
{%- else %}
4848
{}
49-
{% endfor %}
49+
{%- endfor %}
5050

5151
# Separate environment profiles to allow for multiple independent deployments
5252
# of challenges, e.g. staging and production to test challenges internally
5353
# before going live for all users.
5454
profiles:
55-
{% for name, p in profiles | items -%}
55+
{%- for name, p in profiles | items %}
5656
{{ name }}:
5757
# Used to push challenge information into the frontend/scoreboard.
58-
frontend_url: {{ p.frontend_url }}
59-
frontend_token: {{ p.frontend_token }}
58+
frontend_url: "{{ p.frontend_url }}"
59+
frontend_token: "{{ p.frontend_token }}"
6060
# Root domain to expose all challenges under.
61-
challenges_domain: {{ p.challenges_domain }}
62-
# TODO: kubeconfig
63-
kubecontext: {{ p.kubecontext }}
61+
challenges_domain: "{{ p.challenges_domain }}"
62+
# Kubernetes kubeconfig and context name of cluster for this profile.
63+
{% if p.kubeconfig -%}
64+
kubeconfig: "{{ p.kubeconfig }}"
65+
{%- endif -%}
66+
kubecontext: "{{ p.kubecontext }}"
6467
# Credentials for the public challenge file asset bucket.
6568
s3:
66-
bucket_name: {{ p.s3.bucket_name }}
67-
endpoint: {{ p.s3.endpoint }}
68-
region: {{ p.s3.region }}
69-
access_key: {{ p.s3.access_key }}
70-
secret_key: {{ p.s3.secret_key }}
69+
bucket_name: "{{ p.s3.bucket_name }}"
70+
endpoint: "{{ p.s3.endpoint }}"
71+
region: "{{ p.s3.region }}"
72+
access_key: "{{ p.s3.access_key }}"
73+
secret_key: "{{ p.s3.secret_key }}"
7174
# Config for the environment's external-dns deployment.
7275
dns:
7376
# Place external-dns configuration options here;
7477
# this yaml will be passed directly to external-dns without modification
7578
# Reference: https://github.com/bitnami/charts/tree/main/bitnami/external-dns
76-
{%- else -%}
79+
{%- else %}
7780
{}
78-
{% endfor %}
79-
81+
{%- endfor %}
8082
{# comment to preserve trailing newline -#}

src/init/example_values.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pub static FLAG_REGEX: &str = "ctf{.*}";
44

55
pub static REGISTRY_DOMAIN: &str = "ghcr.io/youraccount";
6-
pub static REGISTRY_BUILD_USER: &str = "admin";
6+
pub static REGISTRY_BUILD_USER: &str = "build_user";
77
pub static REGISTRY_BUILD_PASS: &str = "notrealcreds";
88
pub static REGISTRY_CLUSTER_USER: &str = "cluster_user";
99
pub static REGISTRY_CLUSTER_PASS: &str = "alsofake";
@@ -12,9 +12,12 @@ pub static DEFAULTS_DIFFICULTY: &str = "easy";
1212
pub static DEFAULTS_RESOURCES_CPU: i64 = 1;
1313
pub static DEFAULTS_RESOURCES_MEMORY: &str = "500M";
1414

15-
pub static POINTS_DIFFICULTY: &str = "easy";
16-
pub static POINTS_MIN: i64 = 200;
17-
pub static POINTS_MAX: i64 = 500;
15+
pub static POINTS_EASY_DIFFICULTY: &str = "easy";
16+
pub static POINTS_EASY_MIN: i64 = 200;
17+
pub static POINTS_EASY_MAX: i64 = 500;
18+
pub static POINTS_HARD_DIFFICULTY: &str = "hard";
19+
pub static POINTS_HARD_MIN: i64 = 300;
20+
pub static POINTS_HARD_MAX: i64 = 600;
1821

1922
pub static PROFILES_PROFILE_NAME: &str = "default";
2023
pub static PROFILES_FRONTEND_URL: &str = "https://ctf.coolguy.invalid";

src/init/mod.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use itertools::Itertools;
44
use minijinja;
55
use regex::Regex;
66
use serde;
7+
use serde_yaml_ng::Value;
78
use std::collections::HashMap;
89
use std::fmt;
910
use tracing::{debug, error, info, trace, warn};
1011

11-
use crate::configparser::config;
12+
use crate::configparser::config::{self, ProfileConfig, S3Config};
1213
use crate::utils::render_strict;
1314

1415
pub mod example_values;
@@ -85,17 +86,17 @@ pub fn interactive_init() -> inquire::error::InquireResult<config::RcdsConfig> {
8586
difficulty: inquire::Text::new("Difficulty class:")
8687
.with_validator(inquire::required!("Please provide a name."))
8788
.with_help_message("The name of the difficulty class.")
88-
.with_placeholder(example_values::POINTS_DIFFICULTY)
89+
.with_placeholder(example_values::POINTS_EASY_DIFFICULTY)
8990
.prompt()?,
9091
min: inquire::CustomType::<i64>::new("Minimum points:")
9192
.with_error_message("Please type a valid number.") // default parser calls std::u64::from_str
9293
.with_help_message("The minimum number of points that challenges within this difficulty class are worth.") // too long to format
93-
.with_default(example_values::POINTS_MIN)
94+
.with_default(example_values::POINTS_EASY_MIN)
9495
.prompt()?,
9596
max: inquire::CustomType::<i64>::new("Maximum points:")
9697
.with_error_message("Please type a valid number.") // default parser calls std::u64::from_str
9798
.with_help_message("The maximum number of points that challenges within this difficulty class are worth.") // too long to format
98-
.with_default(example_values::POINTS_MAX)
99+
.with_default(example_values::POINTS_EASY_MAX)
99100
.prompt()?,
100101
};
101102
points.push(points_obj);
@@ -265,19 +266,44 @@ pub fn example_init() -> config::RcdsConfig {
265266
memory: example_values::DEFAULTS_RESOURCES_MEMORY.to_string(),
266267
},
267268
},
268-
points: vec![config::ChallengePoints {
269-
difficulty: example_values::POINTS_DIFFICULTY.to_string(),
270-
min: example_values::POINTS_MIN,
271-
max: example_values::POINTS_MAX,
272-
}],
269+
points: vec![
270+
config::ChallengePoints {
271+
difficulty: example_values::POINTS_EASY_DIFFICULTY.to_string(),
272+
min: example_values::POINTS_EASY_MIN,
273+
max: example_values::POINTS_EASY_MAX,
274+
},
275+
config::ChallengePoints {
276+
difficulty: example_values::POINTS_HARD_DIFFICULTY.to_string(),
277+
min: example_values::POINTS_HARD_MIN,
278+
max: example_values::POINTS_HARD_MAX,
279+
},
280+
],
273281

274282
deploy: HashMap::from([(
275283
example_values::PROFILES_PROFILE_NAME.to_string(),
276284
config::ProfileDeploy {
277285
challenges: HashMap::new(),
278286
},
279287
)]),
280-
profiles: HashMap::from([]),
288+
289+
profiles: HashMap::from([(
290+
example_values::PROFILES_PROFILE_NAME.to_string(),
291+
ProfileConfig {
292+
frontend_url: example_values::PROFILES_FRONTEND_URL.to_string(),
293+
frontend_token: example_values::PROFILES_FRONTEND_TOKEN.to_string(),
294+
challenges_domain: example_values::PROFILES_CHALLENGES_DOMAIN.to_string(),
295+
kubeconfig: None,
296+
kubecontext: example_values::PROFILES_KUBECONTEXT.to_string(),
297+
s3: S3Config {
298+
bucket_name: example_values::PROFILES_S3_BUCKET_NAME.to_string(),
299+
endpoint: example_values::PROFILES_S3_ENDPOINT.to_string(),
300+
region: example_values::PROFILES_S3_REGION.to_string(),
301+
access_key: example_values::PROFILES_S3_ACCESSKEY.to_string(),
302+
secret_key: example_values::PROFILES_S3_SECRETACCESSKEY.to_string(),
303+
},
304+
dns: Value::Null,
305+
},
306+
)]),
281307
}
282308
}
283309

0 commit comments

Comments
 (0)