-
Notifications
You must be signed in to change notification settings - Fork 347
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 login
command
#3600
Merged
Merged
feat: add login
command
#3600
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4c7ac65
feat: add `login` function
gabrielmbmb 1bca7f4
feat: add `workspace` argument
gabrielmbmb ea36612
feat: use `ArgillaCredentials` in `Argilla`
gabrielmbmb fcb027f
feat: add `login` tests
gabrielmbmb bd4a03c
fix: add `extra_headers` to `init` call
gabrielmbmb 41115fe
feat: add `login` unit tests
gabrielmbmb 82ad0d3
feat: add `ArgillaCredentials.load` raise error unit test
gabrielmbmb 03ea530
fix: loading credentials
gabrielmbmb 909becd
fix: `test_init_with_stored_credentials` file not found
gabrielmbmb 29f65e8
feat: check and set defaults if no value
gabrielmbmb 1bef88f
feat: add `remove` method
gabrielmbmb 3d39dc1
feat: add `login` command
gabrielmbmb d0c90ac
feat: change `api_url` argument to `typer.Option`
gabrielmbmb dfea31b
feat: add `init_callback` function for `typer` callback
gabrielmbmb df24980
feat: add `extra_headers` option
gabrielmbmb c095c7d
feat: add `login` command unit tests
gabrielmbmb da1ce52
Merge branch 'develop' into feature/login-command
gabrielmbmb 4ed3743
docs: update changelog
gabrielmbmb 7e66336
feat: add `exists` class method
gabrielmbmb ff7ee11
feat: update descriptions
gabrielmbmb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2021-present, the Recognai S.L. team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import typer | ||
|
||
from argilla.client.api import init | ||
from argilla.client.login import ArgillaCredentials | ||
|
||
|
||
def init_callback() -> None: | ||
if not ArgillaCredentials.exists(): | ||
typer.echo("You are not logged in. Please run `argilla login` to login to an Argilla server.") | ||
raise typer.Exit(code=1) | ||
|
||
init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2021-present, the Recognai S.L. team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from .__main__ import app | ||
|
||
if __name__ == "__main__": | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,55 @@ | ||||||||||||||||||||||||||||||
# Copyright 2021-present, the Recognai S.L. team. | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||||||
# you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||||||
# You may obtain a copy of the License at | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||
# | ||||||||||||||||||||||||||||||
# Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||||||
# distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||||||
# See the License for the specific language governing permissions and | ||||||||||||||||||||||||||||||
# limitations under the License. | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
from typing import Optional | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import typer | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
app = typer.Typer(invoke_without_command=True) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@app.callback(help="Login to an Argilla server") | ||||||||||||||||||||||||||||||
def login( | ||||||||||||||||||||||||||||||
api_url: str = typer.Option(..., help="The URL of the Argilla server to login"), | ||||||||||||||||||||||||||||||
api_key: str = typer.Option(..., help="The API key to use to login to the Argilla server", prompt="API Key"), | ||||||||||||||||||||||||||||||
workspace: Optional[str] = typer.Option( | ||||||||||||||||||||||||||||||
None, help="The default workspace over which the operations will be performed" | ||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||
extra_headers: Optional[str] = typer.Option( | ||||||||||||||||||||||||||||||
None, help="A JSON string with extra headers to be sent in the requests to the Argilla server" | ||||||||||||||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||
import json | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
from argilla.client.login import login as login_func | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||
if extra_headers: | ||||||||||||||||||||||||||||||
headers = json.loads(extra_headers) | ||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||
headers = {} | ||||||||||||||||||||||||||||||
login_func(api_url=api_url, api_key=api_key, workspace=workspace, extra_headers=headers) | ||||||||||||||||||||||||||||||
typer.echo(f"Logged in successfully to '{api_url}' Argilla server!") | ||||||||||||||||||||||||||||||
except json.JSONDecodeError as e: | ||||||||||||||||||||||||||||||
typer.echo("The provided extra headers are not a valid JSON string.") | ||||||||||||||||||||||||||||||
raise typer.Exit(code=1) from e | ||||||||||||||||||||||||||||||
except ValueError as e: | ||||||||||||||||||||||||||||||
typer.echo( | ||||||||||||||||||||||||||||||
f"Could not login to the '{api_url}' Argilla server. Please check the provided credentials and try again." | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
raise typer.Exit(code=1) from e | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||||||||||||||||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2021-present, the Recognai S.L. team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2021-present, the Recognai S.L. team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from click.testing import CliRunner | ||
from pytest_mock import MockerFixture | ||
from typer import Typer | ||
|
||
|
||
def test_login(cli_runner: "CliRunner", cli: "Typer", mocker: "MockerFixture"): | ||
login_mock = mocker.patch("argilla.client.login.login") | ||
|
||
result = cli_runner.invoke( | ||
cli, | ||
'login --api-url http://localhost:6900 --api-key api.key --workspace my_workspace --extra-headers "{\\"X-Unit-Test\\": \\"true\\"}"', | ||
) | ||
|
||
assert result.exit_code == 0 | ||
login_mock.assert_called_once_with( | ||
api_url="http://localhost:6900", | ||
api_key="api.key", | ||
workspace="my_workspace", | ||
extra_headers={"X-Unit-Test": "true"}, | ||
) | ||
|
||
|
||
def test_login_fails(cli_runner: "CliRunner", cli: "Typer", mocker: "MockerFixture"): | ||
login_mock = mocker.patch("argilla.client.login.login") | ||
login_mock.side_effect = ValueError | ||
|
||
result = cli_runner.invoke( | ||
cli, | ||
'login --api-url http://localhost:6900 --api-key api.key --workspace my_workspace --extra-headers "{\\"X-Unit-Test\\": \\"true\\"}"', | ||
) | ||
|
||
assert result.exit_code == 1 | ||
login_mock.assert_called_once_with( | ||
api_url="http://localhost:6900", | ||
api_key="api.key", | ||
workspace="my_workspace", | ||
extra_headers={"X-Unit-Test": "true"}, | ||
) | ||
|
||
|
||
def test_login_with_invalid_extra_headers(cli_runner: "CliRunner", cli: "Typer"): | ||
result = cli_runner.invoke( | ||
cli, | ||
'login --api-url http://localhost:6900 --api-key api.key --workspace my_workspace --extra-headers "{\\"X-Unit-Test\\": \\"true\\""', | ||
) | ||
|
||
assert result.exit_code == 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.