Skip to content

docs: add an example how to check connection credentials #269

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

Merged
merged 4 commits into from
Aug 10, 2022

Conversation

bednar
Copy link
Contributor

@bednar bednar commented Jun 15, 2021

Closes #131

Proposed Changes

Added an example how to check if the credentials has sufficient permission to query/write.

Checklist

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

@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2021

Codecov Report

Merging #269 (d56fb02) into master (12ab822) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #269   +/-   ##
=======================================
  Coverage   90.52%   90.52%           
=======================================
  Files          39       39           
  Lines        3355     3355           
=======================================
  Hits         3037     3037           
  Misses        318      318           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bednar bednar marked this pull request as ready for review June 15, 2021 05:19
@bednar bednar requested a review from rhajek June 15, 2021 05:19
Copy link
Contributor

@rhajek rhajek left a comment

Choose a reason for hiding this comment

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

In the current InfluxDB API is no possibility to ask for write / read rights for a given bucket… Workaround with an empty lineprotocol and empty query can be a temporary solution. InfluxDB API should be improved.

@powersj
Copy link
Contributor

powersj commented Jul 20, 2022

In the current InfluxDB API is no possibility to ask for write / read rights for a given bucket… Workaround with an empty lineprotocol and empty query can be a temporary solution. InfluxDB API should be improved.

Agreed that this should be given at the API level. However, having an example seems like a good workaround for now. Was there a bug report against influxdb make the API changes or an official response regarding adding this feature?

@bednar
Copy link
Contributor Author

bednar commented Jul 21, 2022

@powersj We have discussed this issue with Ryan but with no clear outcome https://influxdata.slack.com/archives/C5BSZ026L/p1594730843212900.

@powersj
Copy link
Contributor

powersj commented Aug 5, 2022

It looks like the Authorizaitons API pointed about in the slack comment only works when the user has at least read access to the authorizations service, which I expect most users will not have. In fact, in most cases, I would expect a user to have a read or read-write token specifically for a bucket only, so this will not work.

@rhajek, was there a concern with the include the example for now?

@bednar bednar force-pushed the docs/connection-check branch from 0568e2e to da70429 Compare August 9, 2022 06:27
"""Check that the credentials has permission to write into the Bucket"""
print("> Checking credentials for write ...", end=" ")
try:
client.write_api(write_options=SYNCHRONOUS).write(bucket, org, b"")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this tested on both OSS and Cloud2 ? I can imagine that the can be different order of 400 and 404 checks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tested the latest version of InfluxDB v2.3.0+SNAPSHOT.090f681737 and InfluxDB Cloud 2. There is little inconsistency between query check that always fail with 404 (could not find bucket) but the write can fail with 403 or 404.

403 - bucket exists but you don't have a write permission

Reason: Forbidden
HTTP response body: {"code":"forbidden","message":"insufficient permissions for write"}

404 - bucket does not exists

Reason: Not Found
HTTP response body: {"code":"not found","message":"bucket "xxx" not found"}

@bednar bednar force-pushed the docs/connection-check branch from da70429 to 5bbe48b Compare August 10, 2022 05:24
@powersj powersj merged commit da78936 into master Aug 10, 2022
@powersj powersj deleted the docs/connection-check branch August 10, 2022 13:54
@bednar bednar added this to the 1.32.0 milestone Aug 10, 2022
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.

Simple way to test connection and auth info
4 participants