diff --git a/CHANGELOG.md b/CHANGELOG.md index 82e73b9..ff71d79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ * New commands `okdata -e` and `okdata -v` for printing the current environment and the current version of okdata-cli, respectively. +* The default choice for dataset visibility is now non-public (red). Also warn + when a dataset is about to be registered as public (green). ## 4.1.0 - 2024-04-22 diff --git a/okdata/cli/command.py b/okdata/cli/command.py index 4bd8389..0083bca 100644 --- a/okdata/cli/command.py +++ b/okdata/cli/command.py @@ -91,16 +91,6 @@ def print(self, str, payload=None): else: print(payload) - def confirm_to_continue(self, message): - """Ask the user for confirmation before continuing. - - Any answer other than "y" will exit the program. - """ - self.print(message) - if input("Continue? [y/N]: ") != "y": - self.print("Abort.") - sys.exit() - def login(self): self.sdk.login() @@ -148,6 +138,17 @@ def print_error_response(self, response_body): print(response_body) +def confirm_to_continue(message): + """Ask the user for confirmation before continuing. + + Any answer other than "y" will exit the program. + """ + print(message) + if input("Continue? [y/N]: ") != "y": + print("Abort.") + sys.exit() + + def _format_error_message(message, errors=None): msg = f"An error occurred: {message}" sep = "\n - " diff --git a/okdata/cli/commands/datasets/questions.py b/okdata/cli/commands/datasets/questions.py index 50c901d..15ce791 100644 --- a/okdata/cli/commands/datasets/questions.py +++ b/okdata/cli/commands/datasets/questions.py @@ -62,9 +62,9 @@ def qs_create(): "name": "accessRights", "message": "Tilgangsnivå", "choices": [ + Choice("Eksplisitt tilgangskontroll", "non-public"), + Choice("Internt til Origo", "restricted"), Choice("Offentlig", "public"), - Choice("Begrenset offentlighet", "restricted"), - Choice("Unntatt offentlighet", "non-public"), ], }, { diff --git a/okdata/cli/commands/datasets/wizards.py b/okdata/cli/commands/datasets/wizards.py index 122d3a7..21f0a97 100644 --- a/okdata/cli/commands/datasets/wizards.py +++ b/okdata/cli/commands/datasets/wizards.py @@ -1,6 +1,7 @@ from okdata.sdk.data.dataset import Dataset from okdata.sdk.pipelines.client import PipelineApiClient +from okdata.cli.command import confirm_to_continue from okdata.cli.commands.datasets.questions import qs_create from okdata.cli.commands.wizard import run_questionnaire @@ -56,6 +57,17 @@ def start(self): env = self.command.opt("env") choices = run_questionnaire(*qs_create()) + confirm_to_continue( + "Will create a new dataset '{}'.{}".format( + choices["title"], + ( + "\n\nData uploaded to the dataset will be PUBLICLY AVAILABLE ON THE INTERNET.\n" + if choices["accessRights"] == "public" + else "" + ), + ) + ) + self.command.print("Creating dataset...") dataset_client = Dataset(env=env) dataset_config = self.dataset_config(choices) diff --git a/okdata/cli/commands/pubs/pubs.py b/okdata/cli/commands/pubs/pubs.py index 1db4615..fc723c2 100644 --- a/okdata/cli/commands/pubs/pubs.py +++ b/okdata/cli/commands/pubs/pubs.py @@ -5,7 +5,7 @@ from okdata.sdk.team.client import TeamClient from okdata.cli import MAINTAINER -from okdata.cli.command import BASE_COMMAND_OPTIONS, BaseCommand +from okdata.cli.command import BASE_COMMAND_OPTIONS, BaseCommand, confirm_to_continue from okdata.cli.commands.pubs.client import PubsClient from okdata.cli.commands.pubs.questions import ( NoClientsError, @@ -88,7 +88,7 @@ def create_client(self): scopes = config["scopes"] env = config["env"] - self.confirm_to_continue( + confirm_to_continue( "Will create a new {} client{} in {}{}.".format( client_types[client_type_id], f" for {providers[provider_id]}" if provider_id else "", @@ -138,7 +138,7 @@ def delete_client(self): aws_account = choices["aws_account"] aws_region = choices["aws_region"] - self.confirm_to_continue( + confirm_to_continue( "Will delete client '{}' [{}]{}.".format( client_name, env, @@ -241,7 +241,7 @@ def create_client_key(self): aws_region = config["aws_region"] enable_auto_rotate = config["enable_auto_rotate"] - self.confirm_to_continue( + confirm_to_continue( "\n\n".join( [ "Will create a new key for client '{}' in {} and {}.".format( @@ -327,9 +327,7 @@ def delete_client_key(self): client_name = choices["client_name"] key_id = choices["key_id"] - self.confirm_to_continue( - f"Will delete key '{key_id}' from '{client_name}' [{env}]." - ) + confirm_to_continue(f"Will delete key '{key_id}' from '{client_name}' [{env}].") self.print(f"Deleting key '{key_id}' from '{client_name}' [{env}]...") self.pubs_client.delete_key(env, client_id, key_id) diff --git a/okdata/cli/commands/teams/teams.py b/okdata/cli/commands/teams/teams.py index b9e3810..974fcc6 100644 --- a/okdata/cli/commands/teams/teams.py +++ b/okdata/cli/commands/teams/teams.py @@ -3,7 +3,7 @@ from okdata.sdk.team.client import TeamClient from okdata.cli import MAINTAINER -from okdata.cli.command import BASE_COMMAND_OPTIONS, BaseCommand +from okdata.cli.command import BASE_COMMAND_OPTIONS, BaseCommand, confirm_to_continue from okdata.cli.commands.teams.questions import NoTeamError from okdata.cli.commands.teams.util import ( member_representation, @@ -122,9 +122,7 @@ def add_member(self): ) return - self.confirm_to_continue( - "Add {} to the team?".format(member_representation(user)) - ) + confirm_to_continue("Add {} to the team?".format(member_representation(user))) self.client.update_team_members( config["team_id"], team_members + [user["username"]] @@ -150,13 +148,13 @@ def remove_member(self): members_to_keep.append(member) if len(members_to_keep) == 0: - self.confirm_to_continue( + confirm_to_continue( "You are about to delete all members from the team, including " "yourself. It will not be possible to edit this team any " "further without being re-added by a systems administrator." ) else: - self.confirm_to_continue( + confirm_to_continue( "Remove the following member{} from the team?\n - {}".format( "s" if len(members_to_remove) > 1 else "", "\n - ".join( diff --git a/tests/origocli/commands/teams_test.py b/tests/origocli/commands/teams_test.py index bf57228..7b44573 100644 --- a/tests/origocli/commands/teams_test.py +++ b/tests/origocli/commands/teams_test.py @@ -1,4 +1,4 @@ -from unittest.mock import ANY, MagicMock +from unittest.mock import ANY, MagicMock, patch import pytest from requests import HTTPError @@ -35,7 +35,6 @@ def make_cmd(mocker, *args): set_argv("teams", *args) cmd = teams.TeamsCommand() mocker.patch.object(cmd, "client") - mocker.patch.object(cmd, "confirm_to_continue") mocker.patch.object(teams, "list_members_wizard") mocker.patch.object(teams, "add_member_wizard") mocker.patch.object(teams, "remove_member_wizard") @@ -88,7 +87,8 @@ def test_add_team_member(mocker, mock_print): config = {"team_id": "team1", "username": "misty"} teams.add_member_wizard.return_value = config - cmd.handler() + with patch("okdata.cli.commands.teams.teams.confirm_to_continue"): + cmd.handler() teams.add_member_wizard.assert_called_once() target_members = [u["username"] for u in mock_members] @@ -149,7 +149,8 @@ def test_remove_team_member(mocker, mock_print): config = {"team_id": team_id, "usernames": ["homersimpson"]} teams.remove_member_wizard.return_value = config - cmd.handler() + with patch("okdata.cli.commands.teams.teams.confirm_to_continue"): + cmd.handler() teams.remove_member_wizard.assert_called_once() cmd.client.update_team_members.assert_called_once_with( @@ -158,7 +159,8 @@ def test_remove_team_member(mocker, mock_print): assert mock_print.mock_calls[0][1][0] == "Done!" -def test_remove_all_team_members(mocker, mock_print): +@patch("okdata.cli.commands.teams.teams.confirm_to_continue") +def test_remove_all_team_members(confirm_to_continue, mocker, mock_print): cmd = make_cmd(mocker, "remove-member") team_id = "team1" config = {"team_id": team_id, "usernames": ["homersimpson", "misty", "janedoe"]} @@ -167,6 +169,6 @@ def test_remove_all_team_members(mocker, mock_print): cmd.handler() teams.remove_member_wizard.assert_called_once() - cmd.confirm_to_continue.assert_called_once() + confirm_to_continue.assert_called_once() cmd.client.update_team_members.assert_called_once_with(config["team_id"], []) assert mock_print.mock_calls[0][1][0] == "Done!"