GUACAMOLE-1174: Add parameters to the endpoint path using function guac_kubernetes_append_endpoint_param.
This commit is contained in:
parent
7a1ba51bae
commit
7809447c3f
@ -137,12 +137,8 @@ int guac_kubernetes_endpoint_uri(char* buffer, int length,
|
|||||||
const char* kubernetes_namespace, const char* kubernetes_pod,
|
const char* kubernetes_namespace, const char* kubernetes_pod,
|
||||||
const char* kubernetes_container, const char* exec_command) {
|
const char* kubernetes_container, const char* exec_command) {
|
||||||
|
|
||||||
int written;
|
|
||||||
|
|
||||||
char escaped_namespace[GUAC_KUBERNETES_MAX_ENDPOINT_LENGTH];
|
char escaped_namespace[GUAC_KUBERNETES_MAX_ENDPOINT_LENGTH];
|
||||||
char escaped_pod[GUAC_KUBERNETES_MAX_ENDPOINT_LENGTH];
|
char escaped_pod[GUAC_KUBERNETES_MAX_ENDPOINT_LENGTH];
|
||||||
char escaped_container[GUAC_KUBERNETES_MAX_ENDPOINT_LENGTH];
|
|
||||||
char escaped_exec_command[GUAC_KUBERNETES_MAX_ENDPOINT_LENGTH];
|
|
||||||
|
|
||||||
/* Escape Kubernetes namespace */
|
/* Escape Kubernetes namespace */
|
||||||
if (guac_kubernetes_escape_url_component(escaped_namespace,
|
if (guac_kubernetes_escape_url_component(escaped_namespace,
|
||||||
@ -154,44 +150,38 @@ int guac_kubernetes_endpoint_uri(char* buffer, int length,
|
|||||||
sizeof(escaped_pod), kubernetes_pod))
|
sizeof(escaped_pod), kubernetes_pod))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Generate endpoint path depending on the call type */
|
/* Determine the call type */
|
||||||
char* call = "attach";
|
char* call = "attach";
|
||||||
if (exec_command != NULL)
|
if (exec_command != NULL)
|
||||||
call = "exec";
|
call = "exec";
|
||||||
|
|
||||||
char endpoint_path[GUAC_KUBERNETES_MAX_ENDPOINT_LENGTH];
|
int written;
|
||||||
|
|
||||||
written = snprintf(endpoint_path, sizeof(endpoint_path),
|
/* Generate the endpoint path and write to the buffer */
|
||||||
|
written = snprintf(buffer, length,
|
||||||
"/api/v1/namespaces/%s/pods/%s/%s", escaped_namespace, escaped_pod, call);
|
"/api/v1/namespaces/%s/pods/%s/%s", escaped_namespace, escaped_pod, call);
|
||||||
|
|
||||||
if (written < 0 || written >= sizeof(endpoint_path))
|
/* Operation successful if the endpoint path was written to the given
|
||||||
return 1;
|
|
||||||
|
|
||||||
/* Generate endpoint params */
|
|
||||||
char endpoint_params[GUAC_KUBERNETES_MAX_ENDPOINT_LENGTH];
|
|
||||||
endpoint_params[0] = 0;
|
|
||||||
|
|
||||||
if (exec_command != NULL) {
|
|
||||||
/* Append exec command param */
|
|
||||||
if (guac_kubernetes_append_endpoint_param(endpoint_params,
|
|
||||||
sizeof(endpoint_params), "command", exec_command))
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kubernetes_container != NULL) {
|
|
||||||
/* Append kubernetes container param */
|
|
||||||
if (guac_kubernetes_append_endpoint_param(endpoint_params,
|
|
||||||
sizeof(endpoint_params), "container", kubernetes_container))
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Combine path and params to uri */
|
|
||||||
written = snprintf(buffer, length, "%s?%sstdin=true&stdout=true&tty=true",
|
|
||||||
endpoint_path, endpoint_params);
|
|
||||||
|
|
||||||
/* Endpoint URL was successfully generated if it was written to the given
|
|
||||||
* buffer without truncation */
|
* buffer without truncation */
|
||||||
return !(written < length - 1);
|
if (written < 0 || written >= length)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
/* Append exec command parameter */
|
||||||
|
if (exec_command != NULL) {
|
||||||
|
if (guac_kubernetes_append_endpoint_param(buffer,
|
||||||
|
length, "command", exec_command))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Append kubernetes container parameter */
|
||||||
|
if (kubernetes_container != NULL) {
|
||||||
|
if (guac_kubernetes_append_endpoint_param(buffer,
|
||||||
|
length, "container", kubernetes_container))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Append stdin, stdout and tty parameters */
|
||||||
|
return (guac_kubernetes_append_endpoint_param(buffer, length, "stdin", "true"))
|
||||||
|
|| (guac_kubernetes_append_endpoint_param(buffer, length, "stdout", "true"))
|
||||||
|
|| (guac_kubernetes_append_endpoint_param(buffer, length, "tty", "true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user