-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b30e89
commit 7b2b569
Showing
27 changed files
with
1,043 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
146 changes: 146 additions & 0 deletions
146
containers/controller/src/controller/api/connections/create.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# { | ||
# "parentIdentifier": "ROOT", | ||
# "name": "test", | ||
# "protocol": "rdp", | ||
# "parameters": { | ||
# "port": "", | ||
# "read-only": "", | ||
# "swap-red-blue": "", | ||
# "cursor": "", | ||
# "color-depth": "", | ||
# "clipboard-encoding": "", | ||
# "disable-copy": "", | ||
# "disable-paste": "", | ||
# "dest-port": "", | ||
# "recording-exclude-output": "", | ||
# "recording-exclude-mouse": "", | ||
# "recording-include-keys": "", | ||
# "create-recording-path": "", | ||
# "enable-sftp": "", | ||
# "sftp-port": "", | ||
# "sftp-server-alive-interval": "", | ||
# "enable-audio": "", | ||
# "security": "", | ||
# "disable-auth": "", | ||
# "ignore-cert": "", | ||
# "gateway-port": "", | ||
# "server-layout": "", | ||
# "timezone": "", | ||
# "console": "", | ||
# "width": "", | ||
# "height": "", | ||
# "dpi": "", | ||
# "resize-method": "", | ||
# "console-audio": "", | ||
# "disable-audio": "", | ||
# "enable-audio-input": "", | ||
# "enable-printing": "", | ||
# "enable-drive": "", | ||
# "create-drive-path": "", | ||
# "enable-wallpaper": "", | ||
# "enable-theming": "", | ||
# "enable-font-smoothing": "", | ||
# "enable-full-window-drag": "", | ||
# "enable-desktop-composition": "", | ||
# "enable-menu-animations": "", | ||
# "disable-bitmap-caching": "", | ||
# "disable-offscreen-caching": "", | ||
# "disable-glyph-caching": "", | ||
# "preconnection-id": "", | ||
# "hostname": "", | ||
# "username": "", | ||
# "password": "", | ||
# "domain": "", | ||
# "gateway-hostname": "", | ||
# "gateway-username": "", | ||
# "gateway-password": "", | ||
# "gateway-domain": "", | ||
# "initial-program": "", | ||
# "client-name": "", | ||
# "printer-name": "", | ||
# "drive-name": "", | ||
# "drive-path": "", | ||
# "static-channels": "", | ||
# "remote-app": "", | ||
# "remote-app-dir": "", | ||
# "remote-app-args": "", | ||
# "preconnection-blob": "", | ||
# "load-balance-info": "", | ||
# "recording-path": "", | ||
# "recording-name": "", | ||
# "sftp-hostname": "", | ||
# "sftp-host-key": "", | ||
# "sftp-username": "", | ||
# "sftp-password": "", | ||
# "sftp-private-key": "", | ||
# "sftp-passphrase": "", | ||
# "sftp-root-directory": "", | ||
# "sftp-directory": "" | ||
# }, | ||
# "attributes": { | ||
# "max-connections": "", | ||
# "max-connections-per-user": "", | ||
# "weight": "", | ||
# "failover-only": "", | ||
# "guacd-port": "", | ||
# "guacd-encryption": "", | ||
# "guacd-hostname": "" | ||
# } | ||
# } | ||
|
||
import json | ||
import logging | ||
from urllib.parse import quote | ||
|
||
import requests | ||
|
||
from ..build_url import build_url | ||
|
||
|
||
def api_create_connection( | ||
hostname: str, | ||
port: int, | ||
token: str, | ||
data_source: str, | ||
conn_name: str, | ||
conn_protocol: str, | ||
conn_parent: str, | ||
conn_hostname: str, | ||
conn_port: int | ||
) -> dict: | ||
|
||
logging.debug(f"Creating connection {conn_name=}") | ||
response = requests.post( | ||
build_url( | ||
scheme="http", | ||
netloc=f"{hostname}:{port}", | ||
path=f"/api/session/data/{quote(data_source)}/connections", | ||
query=dict( | ||
token=token | ||
) | ||
), | ||
data=json.dumps(dict( | ||
parentIdentifier=conn_parent, | ||
name=conn_name, | ||
protocol=conn_protocol, | ||
parameters={ | ||
"hostname": conn_hostname, | ||
"port": str(conn_port) | ||
}, | ||
attributes={ | ||
|
||
} | ||
)), | ||
verify=False, | ||
timeout=30, | ||
headers={"Content-Type": "application/json"} | ||
) | ||
|
||
if response.status_code not in (200,): | ||
ex = RuntimeError(("Bad status code!", response.status_code, response.text)) | ||
logging.exception("Bad status code!", exc_info=ex) | ||
raise ex | ||
|
||
response = json.loads(response.text) | ||
logging.debug(f"{response=}") | ||
return response |
38 changes: 38 additions & 0 deletions
38
containers/controller/src/controller/api/connections/delete.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
from urllib.parse import quote | ||
|
||
import requests | ||
|
||
from ..build_url import build_url | ||
from ..error import APIConnectionDoesNotExistError | ||
|
||
|
||
def api_delete_connection( | ||
hostname: str, | ||
port: int, | ||
token: str, | ||
data_source: str, | ||
conn_id: int | ||
): | ||
|
||
logging.debug(f"Delete connection {conn_id=}") | ||
response = requests.delete( | ||
build_url( | ||
scheme="http", | ||
netloc=f"{hostname}:{port}", | ||
|
||
path=f"/api/session/data/{quote(data_source)}/connections/{quote(str(conn_id))}", | ||
query=dict( | ||
token=token | ||
) | ||
), | ||
verify=False, | ||
timeout=30, | ||
headers={"Content-Type": "application/json"} | ||
) | ||
|
||
if response.status_code not in (204,): | ||
# TODO this exception catches too much | ||
ex = APIConnectionDoesNotExistError(("Bad status code!", response.status_code, response.text)) | ||
logging.exception("Bad status code!", exc_info=ex) | ||
raise ex |
78 changes: 78 additions & 0 deletions
78
containers/controller/src/controller/api/connections/get.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
|
||
import json | ||
import logging | ||
from urllib.parse import quote | ||
|
||
import requests | ||
|
||
from ..build_url import build_url | ||
from ..error import APIConnectionDoesNotExistError | ||
|
||
|
||
def api_get_connection( | ||
hostname: str, | ||
port: int, | ||
token: str, | ||
data_source: str, | ||
conn_id: int | ||
) -> dict: | ||
|
||
logging.debug(f"Get connection {conn_id=}") | ||
response = requests.get( | ||
build_url( | ||
scheme="http", | ||
netloc=f"{hostname}:{port}", | ||
|
||
path=f"/api/session/data/{quote(data_source)}/connections/{quote(str(conn_id))}", | ||
query=dict( | ||
token=token | ||
) | ||
), | ||
verify=False, | ||
timeout=30, | ||
headers={"Content-Type": "application/json"} | ||
) | ||
|
||
if response.status_code not in (200,): | ||
# TODO this exception catches too much | ||
ex = APIConnectionDoesNotExistError(("Bad status code!", response.status_code, response.text)) | ||
logging.exception("Bad status code!", exc_info=ex) | ||
raise ex | ||
|
||
response = json.loads(response.text) | ||
logging.debug(f"{response=}") | ||
return response | ||
|
||
|
||
def api_get_connection_parameters( | ||
hostname: str, | ||
port: int, | ||
token: str, | ||
data_source: str, | ||
conn_id: int | ||
) -> dict: | ||
|
||
logging.debug(f"Get connection parameters {conn_id=}") | ||
response = requests.get( | ||
build_url( | ||
scheme="http", | ||
netloc=f"{hostname}:{port}", | ||
path=f"/api/session/data/{quote(data_source)}/connections/{quote(str(conn_id))}/parameters", | ||
query=dict( | ||
token=token | ||
) | ||
), | ||
verify=False, | ||
timeout=30, | ||
headers={"Content-Type": "application/json"} | ||
) | ||
|
||
if response.status_code not in (200,): | ||
# TODO this exception catches too much | ||
ex = APIConnectionDoesNotExistError(("Bad status code!", response.status_code, response.text)) | ||
logging.exception("Bad status code!", exc_info=ex) | ||
raise ex | ||
|
||
response = json.loads(response.text) | ||
logging.debug(f"{response=}") | ||
return response |
41 changes: 41 additions & 0 deletions
41
containers/controller/src/controller/api/connections/list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
import json | ||
import logging | ||
from urllib.parse import quote | ||
|
||
import requests | ||
|
||
from ..build_url import build_url | ||
|
||
|
||
def api_list_connections( | ||
hostname: str, | ||
port: int, | ||
token: str, | ||
data_source: str | ||
) -> dict: | ||
|
||
logging.debug("List connections") | ||
response = requests.get( | ||
build_url( | ||
scheme="http", | ||
netloc=f"{hostname}:{port}", | ||
|
||
path=f"/api/session/data/{quote(data_source)}/connections", | ||
query=dict( | ||
token=token | ||
) | ||
), | ||
verify=False, | ||
timeout=30, | ||
headers={"Content-Type": "application/json"} | ||
) | ||
|
||
if response.status_code not in (200,): | ||
ex = RuntimeError(("Bad status code!", response.status_code, response.text)) | ||
logging.exception("Bad status code!", exc_info=ex) | ||
raise ex | ||
|
||
response = json.loads(response.text) | ||
logging.debug(f"{response=}") | ||
return response |
Oops, something went wrong.