Sweep: Connection with InfluxDB needs Authorization API key, not user/password authentification
Opened this issue · 1 comments
Details
Hello
As it is said in the official doc :
"All requests to the InfluxDB v2 API must include an InfluxDB API token."
Therefore, i'm unable to connect with this reporter to my DB.
Is there a workaround?
Thx
🚀 Here's the PR! #46
5263eb8f83
)For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).
Tip
I can email you next time I complete a pull request if you set up your email here!
Actions (click)
- ↻ Restart Sweep
GitHub Actions✓
Here are the GitHub Actions logs prior to making any changes:
Sandbox logs for adbb171
Checking src/http.service.js for syntax errors... ✅ src/http.service.js has no syntax errors!
1/1 ✓Checking src/http.service.js for syntax errors... ✅ src/http.service.js has no syntax errors!
Sandbox passed on the latest develop
, so sandbox checks will be enabled for this issue.
Step 1: 🔎 Searching
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.
newman-reporter-influxdb/README.md
Lines 11 to 203 in adbb171
newman-reporter-influxdb/src/http.service.js
Lines 8 to 107 in adbb171
I also found the following external resources that might be helpful:
Summaries of links found in the content:
https://docs.influxdata.com/influxdb/v2/admin/tokens:
The page provides documentation on how to manage API tokens in InfluxDB. API tokens are used for secure interaction between InfluxDB and external tools. There are different types of API tokens, including Operator API tokens, All-Access API tokens, and Read/Write tokens. The page explains how to create, view, update, and delete API tokens using the InfluxDB UI, the influx CLI, or the InfluxDB API. It also provides information on how to use API tokens in the InfluxDB UI, the influx CLI, or the InfluxDB API. The page does not mention any specific workaround for connecting to the database without using API tokens.
https://docs.influxdata.com/influxdb/v2/api-guide:
The page is the documentation for the InfluxDB OSS v2 API. It provides information on how to use the API to interact with InfluxDB. The API can be accessed using the /api/v2/ endpoint. The page also mentions that all requests to the API must include an InfluxDB API token. There are developer guides available for using the API, as well as client libraries for different programming languages. The page also mentions that there is InfluxDB v1 compatibility API documentation available for working with InfluxDB 1.x client libraries and third-party integrations. There is a section on how to view the API documentation locally. The page also includes information on how to get support and provide feedback. There is a section on InfluxDB Clustered, which is a highly available InfluxDB 3.0 cluster. It is mentioned that Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. The page also mentions that the documentation for InfluxDB Cloud Serverless is a work in progress.
Step 2: ⌨️ Coding
Modify src/http.service.js with contents:
• Replace the current authentication setup in the constructor with an API token-based approach. Specifically, remove the conditional block that sets `axiosOptions.auth` for InfluxDB version 2.x.
• Instead, add a new condition to check if `this.context.apiToken` is provided. If so, set the `Authorization` header in `axiosOptions.headers` to `Token ${this.context.apiToken}`. This will ensure that all requests made using the `axios` client include the API token in the request headers.
• Example modification: ```javascript if(this.context.apiToken) { axiosOptions.headers = { Authorization: `Token ${this.context.apiToken}`, }; } ```--- +++ @@ -13,10 +13,11 @@ }; if(this.context.version == 2) { - // For InfluxDB version 2.x - axiosOptions.auth = { - username: this.context.username, - password: this.context.password, + // Setting Authorization header for API token-based authentication + if(this.context.apiToken) { + axiosOptions.headers = { + Authorization: `Token ${this.context.apiToken}`, + }; } }
- Running GitHub Actions for
src/http.service.js
✓ Edit
Check src/http.service.js with contents:Ran GitHub Actions for eaf726bac79d7debb73e7b6e67c91273bf04c94d:
Modify src/http.service.js with contents:
• Modify the `_buildInfluxDBUrl` method to include the API token in the query parameters only if the InfluxDB version is 1.x and username/password authentication is used. For InfluxDB version 2.x, the API token should not be included in the URL since it will be provided in the request headers.
• Remove the `u` (username) and `p` (password) parameters from the `params` object for InfluxDB version 2.x.
• Adjust the condition to check for InfluxDB version and whether username and password are provided for version 1.x. If not, do not include these parameters in the query string.
• Example modification: ```javascript if(this.context.version == 1 && this.context.username && this.context.password) { const params = { db: this.context.name, u: this.context.username, p: this.context.password, }; const paramsQuerystring = querystring.stringify(params); const connectionUrl = `${url}?${paramsQuerystring}`; return connectionUrl; } else { return url; } ```--- +++ @@ -13,10 +13,11 @@ }; if(this.context.version == 2) { - // For InfluxDB version 2.x - axiosOptions.auth = { - username: this.context.username, - password: this.context.password, + // Setting Authorization header for API token-based authentication + if(this.context.apiToken) { + axiosOptions.headers = { + Authorization: `Token ${this.context.apiToken}`, + }; } } @@ -29,14 +30,19 @@ _buildInfluxDBUrl(path='write') { const url = `http://${this.context.server}:${this.context.port}/${path}`; - const params = { - db: this.context.name, - u: this.context.username, - p: this.context.password, - }; - + let params = {}; + if(this.context.version == 1 && this.context.username && this.context.password) { + params = { + db: this.context.name, + u: this.context.username, + p: this.context.password, + }; + } else if(this.context.version == 2) { + params = { + db: this.context.name + }; + } const paramsQuerystring = querystring.stringify(params); - const connectionUrl = `${url}?${paramsQuerystring}`; return connectionUrl; }
- Running GitHub Actions for
src/http.service.js
✓ Edit
Check src/http.service.js with contents:Ran GitHub Actions for 4fa97d42efb2796e2d0630c410bcedd0a49b5cce:
Modify src/http.service.js with contents:
• Ensure that the `sendData` method does not attempt to include username and password in the URL for InfluxDB version 2.x, as authentication will be handled via the API token in the request headers.
• Remove the conditional block that appends username and password to the query string for InfluxDB version 2.x.
• This modification ensures that the API token provided in the headers is the sole method of authentication for InfluxDB version 2.x, aligning with the official documentation's requirements.--- +++ @@ -13,10 +13,11 @@ }; if(this.context.version == 2) { - // For InfluxDB version 2.x - axiosOptions.auth = { - username: this.context.username, - password: this.context.password, + // Setting Authorization header for API token-based authentication + if(this.context.apiToken) { + axiosOptions.headers = { + Authorization: `Token ${this.context.apiToken}`, + }; } } @@ -29,14 +30,19 @@ _buildInfluxDBUrl(path='write') { const url = `http://${this.context.server}:${this.context.port}/${path}`; - const params = { - db: this.context.name, - u: this.context.username, - p: this.context.password, - }; - + let params = {}; + if(this.context.version == 1 && this.context.username && this.context.password) { + params = { + db: this.context.name, + u: this.context.username, + p: this.context.password, + }; + } else if(this.context.version == 2) { + params = { + db: this.context.name + }; + } const paramsQuerystring = querystring.stringify(params); - const connectionUrl = `${url}?${paramsQuerystring}`; return connectionUrl; } @@ -79,6 +85,11 @@ u: this.context.username, p: this.context.password, }; + } else if (this.context.version == 2) { + const params = { + bucket: this.context.name, + org: this.context.org, + }; const paramsQuerystring = querystring.stringify(params); url = `/write?${paramsQuerystring}`; } else {
- Running GitHub Actions for
src/http.service.js
✓ Edit
Check src/http.service.js with contents:Ran GitHub Actions for a3dc92862ae95509c6538b0c7897d0aec7692971:
Step 3: 🔁 Code Review
I have finished reviewing the code for completeness. I did not find errors for sweep/connection_with_influxdb_needs_authoriza
.
🎉 Latest improvements to Sweep:
- New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
- Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
- Use the GitHub issues extension for creating Sweep issues directly from your editor.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.
This is an automated message generated by Sweep AI.