diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index fd42a3e81..a160390cd 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -49,4 +49,15 @@ jobs: shell: bash run: | poetry run pytest + env: + KITTYCAD_API_TOKEN: ${{secrets.KITTYCAD_API_TOKEN}} + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: true + flags: unittests + files: ${{ github.workspace }}/coverage.txt + verbose: true diff --git a/kittycad/client.py b/kittycad/client.py index 3a7e3bd28..f2f0a20eb 100644 --- a/kittycad/client.py +++ b/kittycad/client.py @@ -46,3 +46,13 @@ class AuthenticatedClient(Client): def get_headers(self) -> Dict[str, str]: """Get headers to be used in authenticated endpoints""" return {"Authorization": f"Bearer {self.token}", **self.headers} + +@attr.s(auto_attribs=True) +class AuthenticatedClientFromEnv(Client): + """A Client which has been authenticated for use on secured endpoints that uses the KITTYCAD_API_TOKEN environment variable for the authentication token.""" + + token: str = attr.ib(default=os.getenv('KITTYCAD_API_TOKEN')) + + def get_headers(self) -> Dict[str, str]: + """Get headers to be used in authenticated endpoints""" + return {"Authorization": f"Bearer {self.token}", **self.headers}