diff --git a/example/plugins/api-call-example/main.go b/example/plugins/api-call-example/main.go index bf78cac..fa2e751 100644 --- a/example/plugins/api-call-example/main.go +++ b/example/plugins/api-call-example/main.go @@ -32,7 +32,7 @@ func main() { PermittedAPIEndpoints: []plugin.PermittedAPIEndpoint{ { Method: http.MethodGet, - Endpoint: "/api/access/list", + Endpoint: "/plugin/api/access/list", Reason: "Used to display all configured Access Rules", }, }, diff --git a/example/plugins/api-call-example/ui.go b/example/plugins/api-call-example/ui.go index b7ec67e..68d49a3 100644 --- a/example/plugins/api-call-example/ui.go +++ b/example/plugins/api-call-example/ui.go @@ -28,17 +28,17 @@ func allowedEndpoint(cfg *plugin.ConfigureSpec) (string, error) { } defer resp.Body.Close() - // Check if the response status is OK - if resp.StatusCode != http.StatusOK { - return "", fmt.Errorf("received non-OK response status %d", resp.StatusCode) - } - respDump, err := httputil.DumpResponse(resp, true) if err != nil { return "", fmt.Errorf("error dumping response: %v", err) } + // Check if the response status is OK + if resp.StatusCode != http.StatusOK { + return string(respDump), fmt.Errorf("received non-OK response status %d", resp.StatusCode) + } + return string(respDump), nil } @@ -126,7 +126,11 @@ func RenderUI(config *plugin.ConfigureSpec, w http.ResponseWriter, r *http.Reque accessList, err := allowedEndpoint(config) var RenderedAccessListHTML string if err != nil { - RenderedAccessListHTML = fmt.Sprintf("

Error fetching access list: %v

", err) + if accessList != "" { + RenderedAccessListHTML = fmt.Sprintf("

Error fetching access list: %v

%s
", err, html.EscapeString(accessList)) + } else { + RenderedAccessListHTML = fmt.Sprintf("

Error fetching access list: %v

", err) + } } else { // Render the access list as HTML RenderedAccessListHTML = fmt.Sprintf("
%s
", html.EscapeString(accessList))