Skip to content

Commit 15a5009

Browse files
committed
Show error if instance URL not configured
1 parent e251135 commit 15a5009

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

ctfcli/__main__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
from ctfcli.cli.pages import PagesCommand
1717
from ctfcli.cli.plugins import PluginsCommand
1818
from ctfcli.cli.templates import TemplatesCommand
19-
from ctfcli.core.exceptions import MissingAPIKey, ProjectNotInitialized
19+
from ctfcli.core.exceptions import (
20+
MissingAPIKey,
21+
MissingInstanceURL,
22+
ProjectNotInitialized,
23+
)
2024
from ctfcli.core.plugins import load_plugins
2125
from ctfcli.utils.git import check_if_dir_is_inside_git_repo
2226

@@ -148,6 +152,10 @@ def main():
148152
if isinstance(ret, int):
149153
sys.exit(ret)
150154

155+
except MissingInstanceURL as e:
156+
click.secho(e, fg="red")
157+
sys.exit(1)
158+
151159
except MissingAPIKey as e:
152160
click.secho(e, fg="red")
153161
sys.exit(1)

ctfcli/core/api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
from requests import Session
44

55
from ctfcli.core.config import Config
6-
from ctfcli.core.exceptions import MissingAPIKey
6+
from ctfcli.core.exceptions import MissingAPIKey, MissingInstanceURL
77

88

99
class API(Session):
1010
def __init__(self):
1111
config = Config()
1212

1313
# Load required configuration values
14-
self.url = config["config"]["url"]
14+
try:
15+
self.url = config["config"]["url"]
16+
except KeyError:
17+
raise MissingInstanceURL()
1518

1619
try:
1720
self.access_token = config["config"]["access_token"]

ctfcli/core/exceptions.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
class MissingAPIKey(Exception):
77
def __str__(self):
88
return (
9-
"Missing API key. Please set the API key in your configuration file or set CTFCLI_ACCESS_TOKEN environment variable."
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."
1019
)
1120

1221

0 commit comments

Comments
 (0)