|
14 | 14 | from jupyter_server.services.contents.manager import ContentsManager
|
15 | 15 | from jupyter_server.utils import ensure_async, url2path, url_path_join
|
16 | 16 | from packaging.version import parse
|
| 17 | +from jupyter_server.auth.decorator import authorized |
17 | 18 |
|
18 | 19 | try:
|
19 | 20 | import hybridcontents
|
|
24 | 25 | from .git import DEFAULT_REMOTE_NAME, Git, RebaseAction
|
25 | 26 | from .log import get_logger
|
26 | 27 |
|
| 28 | +from .ssh import SSH |
| 29 | + |
27 | 30 | # Git configuration options exposed through the REST API
|
28 | 31 | ALLOWED_OPTIONS = ["user.name", "user.email"]
|
29 | 32 | # REST API namespace
|
30 | 33 | NAMESPACE = "/git"
|
| 34 | +# SSH Auth Resource to be authorized |
| 35 | +SSH_AUTH_RESOURCE = "ssh" |
| 36 | + |
| 37 | + |
| 38 | +class SSHHandler(APIHandler): |
| 39 | + """ |
| 40 | + Top-level parent class for SSH actions |
| 41 | + """ |
| 42 | + |
| 43 | + auth_resource = SSH_AUTH_RESOURCE |
| 44 | + |
| 45 | + @property |
| 46 | + def ssh(self) -> SSH: |
| 47 | + return SSH() |
31 | 48 |
|
32 | 49 |
|
33 | 50 | class GitHandler(APIHandler):
|
@@ -1096,6 +1113,30 @@ async def get(self, path: str = ""):
|
1096 | 1113 | self.finish(json.dumps(result))
|
1097 | 1114 |
|
1098 | 1115 |
|
| 1116 | +class SshHostHandler(SSHHandler): |
| 1117 | + """ |
| 1118 | + Handler for checking if a host is known by SSH |
| 1119 | + """ |
| 1120 | + |
| 1121 | + @authorized |
| 1122 | + @tornado.web.authenticated |
| 1123 | + async def get(self): |
| 1124 | + """ |
| 1125 | + GET request handler, check if the host is known by SSH |
| 1126 | + """ |
| 1127 | + hostname = self.get_query_argument("hostname") |
| 1128 | + is_known_host = self.ssh.is_known_host(hostname) |
| 1129 | + self.set_status(200) |
| 1130 | + self.finish(json.dumps(is_known_host)) |
| 1131 | + |
| 1132 | + @authorized |
| 1133 | + @tornado.web.authenticated |
| 1134 | + async def post(self): |
| 1135 | + data = self.get_json_body() |
| 1136 | + hostname = data["hostname"] |
| 1137 | + self.ssh.add_host(hostname) |
| 1138 | + |
| 1139 | + |
1099 | 1140 | def setup_handlers(web_app):
|
1100 | 1141 | """
|
1101 | 1142 | Setups all of the git command handlers.
|
@@ -1146,6 +1187,7 @@ def setup_handlers(web_app):
|
1146 | 1187 | handlers = [
|
1147 | 1188 | ("/diffnotebook", GitDiffNotebookHandler),
|
1148 | 1189 | ("/settings", GitSettingsHandler),
|
| 1190 | + ("/known_hosts", SshHostHandler), |
1149 | 1191 | ]
|
1150 | 1192 |
|
1151 | 1193 | # add the baseurl to our paths
|
|
0 commit comments