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: add version check support #299

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

feat: add version check support #299

wants to merge 3 commits into from

Conversation

tdstein
Copy link
Collaborator

@tdstein tdstein commented Sep 26, 2024

Adds a new decorator, @context.requires, which asserts version compatibility when the server version is known. The check is skipped if the server version is unknown (e.g., the Connect configuration disables version information).

Also marks the OAuth API with a '2024.08.0' requirement.

Closes #272

Copy link

github-actions bot commented Sep 26, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1144 1098 96% 0% 🟢

New Files

File Coverage Status
src/posit/connect/context.py 100% 🟢
TOTAL 100% 🟢

Modified Files

File Coverage Status
src/posit/connect/client.py 99% 🟢
TOTAL 99% 🟢

updated for commit: 3eeccd4 by action🐍

src/posit/connect/context.py Outdated Show resolved Hide resolved
@@ -48,6 +48,7 @@ def test_posit_credentials_provider(self):
register_mocks()

client = Client(api_key="12345", url="https://connect.example/")
client.ctx.version = None
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are setting the version to None to avoid mocking the API request to /server_settings.

@tdstein tdstein marked this pull request as ready for review September 27, 2024 13:14
@tdstein
Copy link
Collaborator Author

tdstein commented Sep 27, 2024

After a few iterations, I landed on the decorator approach. This seems idiomatic and self-documenting. I tried a few declarative approaches (i.e., checking the version inline), but that felt brittle.

con = Client(api_key="12345", url="https://connect.example/")
assert con.oauth.get_credentials("cit")["access_token"] == "viewer-token"
c = Client(api_key="12345", url="https://connect.example/")
c.ctx.version = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we test here that the oauth client resource respects the server's version constraint?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good call. I'll add it.

Copy link
Collaborator

@dbkegley dbkegley left a comment

Choose a reason for hiding this comment

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

Looks great! I like the annotation approach, that feels very idiomatic

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.

Add the Connect version as a resource attribute.
2 participants