File tree 5 files changed +63
-4
lines changed
5 files changed +63
-4
lines changed Original file line number Diff line number Diff line change 33
33
- name : Build package
34
34
run : poetry build
35
35
36
- - uses : actions/upload-artifact@v3
36
+ - uses : actions/upload-artifact@v4
37
37
with :
38
38
path : |
39
39
./dist/*.tar.gz
Original file line number Diff line number Diff line change 16
16
from ctfcli .cli .pages import PagesCommand
17
17
from ctfcli .cli .plugins import PluginsCommand
18
18
from ctfcli .cli .templates import TemplatesCommand
19
- from ctfcli .core .exceptions import ProjectNotInitialized
19
+ from ctfcli .core .exceptions import (
20
+ MissingAPIKey ,
21
+ MissingInstanceURL ,
22
+ ProjectNotInitialized ,
23
+ )
20
24
from ctfcli .core .plugins import load_plugins
21
25
from ctfcli .utils .git import check_if_dir_is_inside_git_repo
22
26
@@ -148,6 +152,14 @@ def main():
148
152
if isinstance (ret , int ):
149
153
sys .exit (ret )
150
154
155
+ except MissingInstanceURL as e :
156
+ click .secho (e , fg = "red" )
157
+ sys .exit (1 )
158
+
159
+ except MissingAPIKey as e :
160
+ click .secho (e , fg = "red" )
161
+ sys .exit (1 )
162
+
151
163
except ProjectNotInitialized :
152
164
if click .confirm (
153
165
"Outside of a ctfcli project, would you like to start a new project in this directory?" ,
Original file line number Diff line number Diff line change 3
3
from requests import Session
4
4
5
5
from ctfcli .core .config import Config
6
+ from ctfcli .core .exceptions import MissingAPIKey , MissingInstanceURL
6
7
7
8
8
9
class API (Session ):
9
10
def __init__ (self ):
10
11
config = Config ()
11
12
12
13
# Load required configuration values
13
- self .url = config ["config" ]["url" ]
14
- self .access_token = config ["config" ]["access_token" ]
14
+ try :
15
+ self .url = config ["config" ]["url" ]
16
+ except KeyError :
17
+ raise MissingInstanceURL ()
18
+
19
+ try :
20
+ self .access_token = config ["config" ]["access_token" ]
21
+ except KeyError :
22
+ raise MissingAPIKey ()
15
23
16
24
# Handle SSL verification disabling
17
25
try :
Original file line number Diff line number Diff line change 10
10
11
11
12
12
class Config :
13
+ _env_vars = {
14
+ "CTFCLI_ACCESS_TOKEN" : "access_token" ,
15
+ "CTFCLI_URL" : "url" ,
16
+ }
17
+
13
18
def __init__ (self ):
14
19
self .base_path = self .get_base_path ()
15
20
self .project_path = self .get_project_path ()
@@ -26,6 +31,24 @@ def __init__(self):
26
31
self .config = parser
27
32
self .challenges = dict (self .config ["challenges" ])
28
33
34
+ # Load environment variables
35
+ self ._env_overrides ()
36
+
37
+ def _env_overrides (self ):
38
+ """
39
+ For each environment variable specified in _env_vars, check if it exists
40
+ and if so, add it to the config under the "config" section.
41
+ """
42
+ for env_var , config_key in self ._env_vars .items ():
43
+ env_value = os .getenv (env_var )
44
+ if not env_value :
45
+ continue
46
+
47
+ if not self .config .has_section ("config" ):
48
+ self .config .add_section ("config" )
49
+
50
+ self .config ["config" ][config_key ] = env_value
51
+
29
52
def __getitem__ (self , key ):
30
53
return self .config [key ]
31
54
Original file line number Diff line number Diff line change 3
3
import click
4
4
5
5
6
+ class MissingAPIKey (Exception ):
7
+ def __str__ (self ):
8
+ return (
9
+ "Missing API key. "
10
+ "Please set the API key in your configuration file or set the CTFCLI_ACCESS_TOKEN environment variable."
11
+ )
12
+
13
+
14
+ class MissingInstanceURL (Exception ):
15
+ def __str__ (self ):
16
+ return (
17
+ "Missing CTFd instance URL. "
18
+ "Please set the instance URL in your configuration file or set the CTFCLI_URL environment variable."
19
+ )
20
+
21
+
6
22
class ProjectNotInitialized (Exception ):
7
23
pass
8
24
You can’t perform that action at this time.
0 commit comments