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

Download method needs API key in header #168

Closed
stephenyeargin opened this issue Sep 14, 2023 · 3 comments · Fixed by #169
Closed

Download method needs API key in header #168

stephenyeargin opened this issue Sep 14, 2023 · 3 comments · Fixed by #169
Labels

Comments

@stephenyeargin
Copy link
Owner

stephenyeargin commented Sep 14, 2023

From original reported issue:


I am getting these snippets even though grafana is able to render the dashboards. I only get the error when using hubot-grafana

Any ideas how I could debug this?

Everything seems to be ok, I get the correct URL and statusText from Grafana is OK but it returns an HTML instead of the PNG

I tried the same request with CURL and it worked fine

I think I found the problem.

The API key is not being passed to grafana in the header

  /**
   * Downloads the given URL.
   * @param {string} url The URL.
   * @returns {Promise<{ body: Buffer, contentType: string}>}
   */
  async download(url) {


    console.log(grafanaHeaders(null, null))
    return await fetch(url, {
      method: 'GET',
      headers: grafanaHeaders(null, null, "PUT_YOR_TOKEN_HERE), // By default the token is not set in there
    }).then(async (res) => {
      const contentType = res.headers.get('content-type');

      console.log(res.statusText)

      const body = await res.arrayBuffer();

      return {
        body: Buffer.from(body),
        contentType: contentType,
      };
    });
  }

After adding the key there it worked, however by default it is not passed. Is this a bug on your end?

Originally posted by @gkaskonas in #105 (comment)

@stephenyeargin
Copy link
Owner Author

That appears to be the case. @KeesCBakker did some much-needed refactoring recently and it may not be passing the API key down where it needs to.

* Downloads the given URL.
* @param {string} url The URL.
* @returns {Promise<{ body: Buffer, contentType: string}>}
*/
async download(url) {
return await fetch(url, {
method: 'GET',
headers: grafanaHeaders(null, null),
}).then(async (res) => {
const contentType = res.headers.get('content-type');
const body = await res.arrayBuffer();
return {
body: Buffer.from(body),
contentType: contentType,
};
});
}

Adding this.grafana_api_key as the third argument on L110 will likely resolve it.

@KeesCBakker
Copy link
Collaborator

We might need to add a unit test so it won't get lost again.

@stephenyeargin
Copy link
Owner Author

We might need to add a unit test so it won't get lost again.

Added via 5742eaf

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

Successfully merging a pull request may close this issue.

2 participants