Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Conversation

@mlclmj
Copy link
Contributor

@mlclmj mlclmj commented Jun 28, 2018

Previous discussion for this PR is here.

This PR adds functionality to the library for better management of Grafana Users and Organizations, as well as adding tests to cover new (and some existing) functions.

@mlclmj mlclmj requested review from msuterski, sbower and tonglil June 28, 2018 19:07
admin.go Outdated
return user.Id, err
}

func (c *Client) CreateUser(email, login, name, password string) (int64, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this exist in addition to CreateUserForm ?

Copy link
Contributor Author

@mlclmj mlclmj Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way for the library and provider to use the same dtos package since the provider was using a vendor'ed one, so this was a workaround. I guess the library could just export one generic method without the use of the dtos package?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure if pulling packages from something that is a client of a library is a good direction. Usually it's the other way around.

I do not think passing in the DTO from a client is necessary (or a good approach here).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry. The dtos come from grafana, not the provider. That's OK, then. :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if there are data structs for all the grafana resources, we should import/use them in the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That dtos package created a compile issue due to it being vendored/not vendored between the two. Maybe we can just have this method use the User struct that the other user methods use?

client.go Outdated
return req, err
}

func (c *Client) newQueryRequest(method, requestPath string, query string) (*http.Request, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? Can query params be passed to newRequest() as part of the requestPath ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that-- any special characters such as ?&= for query parameters get URL-escaped if they're included in the requestPath.

Another option would to modify the existing newRequest() function and to support query parameters if that'd be better?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to add to the existing method over creating a new one that is pretty much a copy of the other one. Or at least extract a common part.

If we're putting query params into the RawQuery, those params themselves need to be encoded, too. Is this something that the library is going to do?

org_users.go Outdated
Role string `json:"role"`
}

func (c *Client) OrgUsers(id int64) ([]OrgUser, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could id be also called orgId as in other methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes definitely

Copy link
Contributor

@tonglil tonglil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change newRequest(method, requestPath, query string, body io.Reader) to newRequest(method, requestPath, query url.Values, body io.Reader).

When there is no query, the user can pass nil instead of an empty string.
When the user needs to add query parameters, they can build a query like this:

v := url.Values{}
v.Add("name", "Ava")
v.Add("friend", "Jess")

In the function: url.RawQuery = query.Encode()

https://golang.org/pkg/net/url/#Values

This is how I think Go expects it to be done: https://golang.org/src/net/url/example_test.go

@mlclmj
Copy link
Contributor Author

mlclmj commented Jul 10, 2018

That seems like a much better way to handle the query parameters, I'll add that in. Thanks!

admin_test.go Outdated
Email: "admin@localhost",
Login: "admin",
Name: "Administrator",
Name: "Administrator",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go fmt?

admin_test.go Outdated
)

const (
createUserJSON = `{"id":1,"message":"User created"}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go fmt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, something must be configured incorrectly with my editor, I'll run it now.

@mlclmj mlclmj merged commit d769eac into master Jul 13, 2018
@mlclmj mlclmj deleted the org-users branch August 8, 2018 13:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants