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

feat: config option to allow basic auth #263

Merged
merged 7 commits into from
May 28, 2021

Conversation

reinhard-brandstaedter
Copy link
Contributor

@reinhard-brandstaedter reinhard-brandstaedter commented May 26, 2021

feat: add option for basic auth when using influxdb 1.8 compatibility API

Closes #262

Proposed Changes

Add an additional option auth_basic: True|False for the InfluxDBClient, which allows to use the client in cases where reverse proxies are being used for authentication instead of InfluxDBs own authentication (applies only for InfluxDB 1.8 forward compatibility API).
Using reverse proxies is quite a common setup, so this makes it easier to integrate in such scenarios.

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • pytest tests completes successfully
  • Commit messages are in semantic format
  • Sign CLA (if not already signed)

This can be useful for setups of InfluxDB 1.8 without authentication when authentication is handled by a proxy instead.
@codecov-commenter
Copy link

codecov-commenter commented May 26, 2021

Codecov Report

Merging #263 (cd3278c) into master (a421a6f) will decrease coverage by 0.01%.
The diff coverage is 90.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #263      +/-   ##
==========================================
- Coverage   91.93%   91.91%   -0.02%     
==========================================
  Files          25       25              
  Lines        2033     2042       +9     
==========================================
+ Hits         1869     1877       +8     
- Misses        164      165       +1     
Impacted Files Coverage Δ
influxdb_client/client/influxdb_client.py 98.65% <88.88%> (-0.64%) ⬇️
influxdb_client/configuration.py 84.61% <100.00%> (+0.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a421a6f...cd3278c. Read the comment docs.

Copy link
Contributor

@bednar bednar 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 your PR 👍

There is a few requirements that should be satisfy before we accept the PR:

  1. Please add documentation of auth_basic option to:
    :key str ssl_ca_cert: Set this to customize the certificate file to verify the peer.
  2. Add support for configuration by config_file:
    def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gzip=False):
  3. Add support for configuration by env_properties:
    def from_env_properties(cls, debug=None, enable_gzip=False):
  4. Add new configuration option to README.rst:
    image
  5. Add tests:

Regards

@reinhard-brandstaedter
Copy link
Contributor Author

Thanks @bednar will do!

I was just wondering, since this option would only apply when using the client in combination with the 1.8 compatibility API (AFAIK disabling auth for InfluxDB 2.0 is not an option?) if this configuration option should go into the [influx2] config section or if it makes sense to introduce a [influx1] compatibility section to make it more clear that this can/should only be used in combination with 1.8.
At the time of creating the influxdb_client one can only tell that the end-user is intending to connect to a InfluxDB 1.8 by looking at the org parameter and check if its value is "-". (would that be a correct assumption?).
So maybe I should also add a safety there to avoid that someone sets the auth_basic when intending to use it against InfluxDB 2.0.

kr

@bednar
Copy link
Contributor

bednar commented May 27, 2021

I was just wondering, since this option would only apply when using the client in combination with the 1.8 compatibility API (AFAIK disabling auth for InfluxDB 2.0 is not an option?) if this configuration option should go into the [influx2] config section or if it makes sense to introduce a [influx1] compatibility section to make it more clear that this can/should only be used in combination with 1.8.

Good point 👍 I think we can use influx2 section with note that the option is suitable only for InfluxDB 1.8+.

At the time of creating the influxdb_client one can only tell that the end-user is intending to connect to a InfluxDB 1.8 by looking at the org parameter and check if its value is "-". (would that be a correct assumption?).

I don't think so. It is too tricky.

So maybe I should also add a safety there to avoid that someone sets the auth_basic when intending to use it against InfluxDB 2.0.

I think that a note in documentation that the option is suitable only for InfluxDB 1.8+ will be pretty enough.

@reinhard-brandstaedter
Copy link
Contributor Author

I was just wondering, since this option would only apply when using the client in combination with the 1.8 compatibility API (AFAIK disabling auth for InfluxDB 2.0 is not an option?) if this configuration option should go into the [influx2] config section or if it makes sense to introduce a [influx1] compatibility section to make it more clear that this can/should only be used in combination with 1.8.

Good point 👍 I think we can use influx2 section with note that the option is suitable only for InfluxDB 1.8+.

Done

At the time of creating the influxdb_client one can only tell that the end-user is intending to connect to a InfluxDB 1.8 by looking at the org parameter and check if its value is "-". (would that be a correct assumption?).

I don't think so. It is too tricky.

I see, took a look and seems one can also use "-" as an org name in InfluxDB2. Indeed tricky. I'll leave it up to the user to read documentation and not use the option with 2.x

So maybe I should also add a safety there to avoid that someone sets the auth_basic when intending to use it against InfluxDB 2.0.

I think that a note in documentation that the option is suitable only for InfluxDB 1.8+ will be pretty enough.

Done

@reinhard-brandstaedter reinhard-brandstaedter changed the title feat: optionally allow basic auth feat: config option to allow basic auth May 27, 2021
Copy link
Contributor

@bednar bednar left a comment

Choose a reason for hiding this comment

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

@reinhard-brandstaedter, thanks again for your PR 👍

Please update CHANGELOG.md and we will be ready to merge PR into master.

Copy link
Contributor

@bednar bednar left a comment

Choose a reason for hiding this comment

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

LGTM 🥇

@bednar bednar merged commit 30b75c9 into influxdata:master May 28, 2021
@bednar bednar added this to the 1.18.0 milestone May 28, 2021
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.

Adding options for basic auth to API calls
3 participants