Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify requests to send authorization header #197

Merged
merged 2 commits into from
Jan 5, 2022

Conversation

PatMis16
Copy link
Contributor

@PatMis16 PatMis16 commented Jan 4, 2022

I modified the code to use header-based authentication. The following changes where made:

  • pkg/grafana/config.go - add function "getGrafanaToken" which reads the environment variable GRAFANA_TOKEN and returns the token
  • pkg/grafana/dashboards.go - modified all requests to send the API token in the request header (Authorization)
  • pkg/grafana/datasources.go - modified all requests to send the API token in the request header (Authorization)
  • pkg/grafana/folders.go - modified all requests to send the API token in the request header (Authorization)

With this changes, Grizzly can be used even if the basic authentication method cannot be used e.g. because Grafana sits behind a reverse proxy with automatic authentication such as OpenID or similar.

Not sure if all requests are modified or if there are other requests where the Authentication header musst be added. Especially for the rules further modification can be neccesarry.

@PatMis16 PatMis16 mentioned this pull request Jan 4, 2022
Copy link
Collaborator

@malcolmholmes malcolmholmes left a comment

Choose a reason for hiding this comment

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

Can you remove these comments? Then I'd be happy to approve/merge this.

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer " + grafanaToken)

//resp, err := http.Post(grafanaURL, "application/json", bytes.NewBufferString(wrappedJSON))
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can remove this line

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer " + grafanaToken)

//resp, err := http.Post(grafanaURL, "application/json", bytes.NewBufferString(sourceJSON))
Copy link
Collaborator

Choose a reason for hiding this comment

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

can remove

}
req.Header.Set("Authorization", "Bearer " + grafanaToken)

//resp, err := http.Get(grafanaURL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer " + grafanaToken)

//resp, err := http.Post(grafanaURL, "application/json", bytes.NewBufferString(folderJSON))
Copy link
Collaborator

Choose a reason for hiding this comment

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

again

}
req.Header.Set("Authorization", "Bearer " + grafanaToken)

//resp, err := http.Get(grafanaURL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

last one!

@PatMis16
Copy link
Contributor Author

PatMis16 commented Jan 5, 2022

Can you remove these comments? Then I'd be happy to approve/merge this.

@malcolmholmes I have removed the comments.

Copy link
Collaborator

@malcolmholmes malcolmholmes left a comment

Choose a reason for hiding this comment

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

Thanks for providing both a rationale and a fix. Merging now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants