-
Notifications
You must be signed in to change notification settings - Fork 0
Add basic auth client setup #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| version: 2 | ||
| updates: | ||
|
|
||
| # Docker | ||
| - package-ecosystem: docker | ||
| directory: "/" | ||
| schedule: | ||
| interval: "monthly" | ||
| open-pull-requests-limit: 25 | ||
|
|
||
| # Python | ||
| - package-ecosystem: "pip" # See documentation for possible values | ||
| directory: "/" # Location of package manifests | ||
| schedule: | ||
| interval: "monthly" | ||
| open-pull-requests-limit: 25 | ||
|
|
||
| # GitHub Actions | ||
| - package-ecosystem: "github-actions" | ||
| directory: ".github/workflows" | ||
| schedule: | ||
| interval: "monthly" | ||
| open-pull-requests-limit: 25 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: "CodeQL" | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| - ready_for_review | ||
| push: | ||
| # run workflow when merging to main or develop | ||
| branches: | ||
| - main | ||
| - master | ||
| - develop | ||
|
|
||
| jobs: | ||
| CodeQL-Build: | ||
| # CodeQL runs on ubuntu-latest, windows-latest, and macos-latest | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| # required for all workflows | ||
| security-events: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| # Initializes the CodeQL tools for scanning. | ||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@v3 | ||
| # Override language selection by uncommenting this and choosing your languages | ||
| with: | ||
| languages: python | ||
|
|
||
| - name: Perform CodeQL Analysis | ||
| uses: github/codeql-action/analyze@v3 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| name: KBase Auth Client Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| - ready_for_review | ||
| push: | ||
| # run workflow when merging to main or develop | ||
| branches: | ||
| - main | ||
| - develop | ||
|
|
||
| jobs: | ||
|
|
||
| auth_client_tests: | ||
| runs-on: ubuntu-22.04 | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - python-version: "3.12" | ||
|
|
||
| steps: | ||
|
|
||
| - name: Repo checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v6 | ||
|
|
||
| - name: Install dependencies | ||
| shell: bash | ||
| run: | | ||
| export UV_PROJECT_ENVIRONMENT="${pythonLocation}" | ||
| uv sync --locked | ||
|
Comment on lines
+41
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uv can also manage your python installation if you have committed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but the current way means we can matrix test multiple versions of python if we want to, which I'm guessing we'll probably want to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May want to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how that file interacts with the |
||
| - name: Run tests | ||
| shell: bash | ||
| run: PYTHONPATH=src pytest --cov=src --cov-report=xml test | ||
|
|
||
| - name: Upload coverage to Codecov | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| fail_ci_if_error: true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ########################################## | ||
| # READ BEFORE ALTERING THIS FILE | ||
| # | ||
| # Only files specific to this repo or that will be generated as part of using this repo should | ||
| # be ignored here. Files that are specific to particular development environments or users | ||
| # should be ignored in the global gitignore to ignore for all repos, or in .git/info/exclude | ||
| # to ignore for just this repo. | ||
| # | ||
| # Examples of appropriate files for each location: | ||
| # This file: | ||
| # python pyc files | ||
| # python cache files | ||
| # test configuration and output, including coverage data | ||
| # | ||
| # Global gitignore | ||
| # Eclipse .settings, .project, and .pyproject files | ||
| # Mac .DS_store files | ||
| # VSCode .vscode directory | ||
| # | ||
| # .git/info/exclude | ||
| # Temporary code / notes while exploring new repo features | ||
| # Personal data used for manual testing | ||
| # | ||
| ########################################## | ||
|
|
||
| /.pytest_cache/ | ||
| __pycache__ | ||
| /.venv/ | ||
|
Comment on lines
+26
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you need to add in the directories that get created when you run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't built a package with uv yet so I didn't know about the gubbins, but when I do I'll update the ignore |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3.12 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2025-present KBase Software | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Auth2 client for Python | ||
|
|
||
| This repo contains a minimal client for the [KBase Auth2 server](https://github.com/kbase/auth2), | ||
| covering only the most common operations - e.g. validating tokens and user names | ||
| and getting user roles. | ||
|
|
||
| Most other uses are easily done with any http/REST client like `requests` or `httpx`. | ||
|
|
||
| ## Installation | ||
|
|
||
| TODO INSTALL setup a KBase pypi org and publish there | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please announce when you do this as there are a few other packages that it'd be great to put up there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the plan |
||
|
|
||
| ## Usage | ||
|
|
||
| TODO USAGE | ||
|
|
||
| ## Development | ||
|
|
||
| ### Creating the synchronous client | ||
|
|
||
| The synchronous client is generated from the asynchronous client code - do not make any changes in | ||
| the `_sync` directory as they will be overwritten. | ||
|
|
||
| To update the synchronous code after modifying the asynchronous code run | ||
|
|
||
| ``` | ||
| uv sync --dev # only required on first run or when the uv.lock file changes | ||
| uv run scripts/process_unasync.py | ||
| ``` | ||
|
|
||
| ### Adding and releasing code | ||
|
|
||
| * Adding code | ||
| * All code additions and updates must be made as pull requests directed at the develop branch. | ||
| * All tests must pass and all new code must be covered by tests. | ||
| * All new code must be documented appropriately | ||
| * Pydocs | ||
| * General documentation if appropriate | ||
| * Release notes | ||
| * Releases | ||
| * The main branch is the stable branch. Releases are made from the develop branch to the main | ||
| branch. | ||
| * Tag the version in git and github. | ||
| * Create a github release. | ||
|
|
||
| ### Testing | ||
|
|
||
| ``` | ||
| uv sync --dev # only required on first run or when the uv.lock file changes | ||
| PYTHONPATH=src uv run pytest test | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| services: | ||
|
|
||
| auth: | ||
| image: ghcr.io/kbase/auth2:0.7.1 | ||
| platform: linux/amd64 | ||
| ports: | ||
| - 50001:8080 | ||
| environment: | ||
| mongo_host: "mongodb:27017" | ||
| test_mode_enabled: "true" | ||
| identity_providers: "" | ||
| command: | ||
| - "-template" | ||
| - "/kb/deployment/conf/.templates/deployment.cfg.templ:/kb/deployment/conf/deployment.cfg" | ||
| - "/kb/deployment/bin/start_auth2.sh" | ||
| depends_on: | ||
| - mongodb | ||
| healthcheck: | ||
| test: ["CMD", "curl", "-f", "http://localhost:8080/"] | ||
| interval: 1s | ||
| # https://github.com/kbase/auth2/issues/443 | ||
| retries: 30 | ||
|
|
||
| mongodb: | ||
| image: mongo:7.0.14 | ||
| ports: | ||
| - 27017:27017 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| [project] | ||
| name = "kbase-auth" | ||
| version = "0.1.0" | ||
| description = "Client for the KBase Authentication Service" | ||
| readme = "README.md" | ||
| authors = [{ name = "KBase Development Team" }] | ||
| requires-python = ">=3.12" | ||
| license = { text = "MIT" } | ||
| classifiers = [ | ||
| "Programming Language :: Python :: 3", | ||
| "License :: OSI Approved :: MIT License", | ||
| "Operating System :: OS Independent", | ||
| ] | ||
| dependencies = [ | ||
| "httpx==0.28.1", | ||
| ] | ||
|
|
||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" | ||
|
|
||
| [tool.hatch.build.targets.wheel] | ||
| packages = ["src/kbase"] | ||
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| "ipython==9.5.0", | ||
| "pytest==8.4.2", | ||
| "pytest-asyncio==1.2.0", | ||
| "pytest-cov==7.0.0", | ||
| "requests==2.32.5", | ||
| "unasync==0.6.0", | ||
| ] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would encourage good practices by adding in a code formatting/linting section with a ruff config here. Just makes life easier not to have to worry about code format and dumb errors that can be caught by tools. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a big fan linters at this point, they're too opinionated and catch mostlyi trivial stuff There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I much prefer using a code formatter wherever possible -- if everyone's code is laid out the same, it's much quicker to read, review, and understand. Linters catch all kinds of useful errors, especially if you have devs with different levels of experience working on a project. You or I might have the ability to produce perfect code every time, but that isn't true for everyone. As for being opinionated, what's that expression about the pot and the kettle...? 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm definitely opinionated, but when it comes to code style I think I keep my opinions in check these days. As long as it's readable I don't care too much. If we start having junior devs work on this repo I'm willing to revisit adding a code formatter, but right now the ROI just isn't there. I've spent too much time setting up, configuring, and integrating code formatters only to have them waste my time catching trailing whitespace (cough codacy cough). Right now there's little to no benefit IMO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is extremely quick and easy to set up ruff to format your code -- it even looks as though PyDev has ruff as one of the formatters. I believe ruff catches trailing whitespace, and any decent IDE should also have a setting for it. You can also add a standard We have already spent more time debating this than it would have taken to add a section to the pyproject.toml file with the setup for formatting and linting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But not more time than it will take in the future having test runs fail due to trivial issues, fixing said trivial issues that don't need to be fixed, and tweaking the config until everyone's equally annoyed with it. I've been through this cycle several times before with many different linters; it's not necessary and not worth the effort There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have had the opposite experience. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it seems we're at an impasse - can you agree to leave things as they are for now and add a linter when / if it becomes an issue? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """ | ||
| Convert the async client to a sync client. | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
| import unasync | ||
|
|
||
|
|
||
| def main(): | ||
| additional_replacements = { | ||
| "AsyncClient": "Client", | ||
| "aclose": "close", | ||
| } | ||
|
|
||
|
|
||
| rules = [ | ||
| unasync.Rule( | ||
| fromdir="/src/kbase/auth/_async/", | ||
| todir="/src/kbase/auth/_sync/", | ||
| additional_replacements=additional_replacements, | ||
| ), | ||
| ] | ||
|
|
||
| filepaths = [ | ||
| str(Path(__file__).parent.parent / "src" / "kbase" / "auth" / "_async" / "client.py") | ||
| ] | ||
|
|
||
| unasync.unasync_files(filepaths, rules) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can now use
"uv"as the value for python repos with uv dependency managementhttps://docs.astral.sh/uv/guides/integration/dependency-bots/#dependabot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the issue linked in those docs says it doesn't update the pyproject.toml file yet, sounds like it's not quite ready for prime time