go-graylog icon indicating copy to clipboard operation
go-graylog copied to clipboard

Implement Generic() func on Client

Open gprossliner opened this issue 3 years ago • 2 comments

This PR allows to call any API that is not (yet) implemented by the module itself, like "/authz/shares":

func shareStream(context context.Context, streamID string, userID string)  error
{
	request := struct {
		Selected_grantee_capabilities map[string]interface{} `json:"selected_grantee_capabilities"`
	}{map[string]interface{}{
		"grn::::user:" + userID: "view",
	}}

	grn := "grn::::stream:" + streamID
	_, err = client.Generic(ctx, http.MethodPost, "/authz/shares/entities/"+grn, request, nil)
	return err
}

To make my fork build successfully, I had to execute go mod tidy. I did not commit the resulting changes to go.sum to avoid merge-conflicts.

I tried to keep the coding-style like the existing files.

I added unit-tests for the constructing the Endpoint URL, but no integration tests incl. Mock-Server. Please let me know if you are interested in merging this PR, than I can implement these as well.

gprossliner avatar May 17 '21 11:05 gprossliner