@@ -5,6 +5,8 @@ Mix.install([
5
5
{:grading_client , path: " #{ __DIR__ } /grading_client" }
6
6
])
7
7
8
+ System .put_env (" envar_secret" , " some-secret-password" )
9
+
8
10
:ok
9
11
```
10
12
@@ -45,12 +47,40 @@ A very easy way to prevent secrets being added to files is to access them via En
45
47
46
48
_ Use ` System.get_env/1 ` on line 2._
47
49
48
- ``` elixir
49
- # let's assume there is an environment variable named 'envar_secret'
50
- super_secret_password = " p@ssw0rd"
50
+ <!-- livebook:{"attrs":"eyJzb3VyY2UiOiIjIEVTQ1Q6MVxuc3VwZXJfc2VjcmV0X3Bhc3N3b3JkID0gXCJwQHNzdzByZFwiIn0","chunks":null,"kind":"Elixir.GradingClient.GradedCell","livebook_object":"smart_cell"} -->
51
51
52
- # DO NOT CHANGE CODE BELOW THIS COMMENT
53
- IO .puts (super_secret_password)
52
+ ``` elixir
53
+ result = super_secret_password = " p@ssw0rd"
54
+
55
+ [module_id, question_id] =
56
+ " # ESCT:1\n super_secret_password = \" p@ssw0rd\" "
57
+ |> String .split (" \n " , parts: 2 )
58
+ |> hd ()
59
+ |> String .trim_leading (" #" )
60
+ |> String .split (" :" , parts: 2 )
61
+
62
+ module_id =
63
+ case %{" ESCT" => ESCT , " OWASP" => OWASP }[String .trim (module_id)] do
64
+ nil -> raise " invalid module id: #{ module_id } "
65
+ module_id -> module_id
66
+ end
67
+
68
+ question_id =
69
+ case Integer .parse (String .trim (question_id)) do
70
+ {id, " " } -> id
71
+ _ -> raise " invalid question id: #{ question_id } "
72
+ end
73
+
74
+ case GradingClient .check_answer (module_id, question_id, result) do
75
+ :correct ->
76
+ IO .puts ([IO .ANSI .green (), " Correct!" , IO .ANSI .reset ()])
77
+
78
+ {:incorrect , help_text} when is_binary (help_text) - >
79
+ IO .puts ([IO .ANSI .red (), " Incorrect: " , IO .ANSI .reset (), help_text])
80
+
81
+ _ ->
82
+ IO .puts ([IO .ANSI .red (), " Incorrect." , IO .ANSI .reset ()])
83
+ end
54
84
```
55
85
56
86
## Making Secret Rotation Easy
0 commit comments