From f89b06294ae15ebd7a6afee388efe7f7f8eee5b1 Mon Sep 17 00:00:00 2001 From: stopal Date: Fri, 26 May 2017 16:48:28 +0100 Subject: [PATCH] LOG-9309 removed deprecated commands and related code --- CHANGES.txt | 11 +- lecli/cli.py | 21 --- lecli/deprecated_commands.py | 227 ------------------------------ tests/test_deprecated_commands.py | 206 --------------------------- 4 files changed, 10 insertions(+), 455 deletions(-) delete mode 100644 lecli/deprecated_commands.py delete mode 100644 tests/test_deprecated_commands.py diff --git a/CHANGES.txt b/CHANGES.txt index 0711315..8f102f3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -10,4 +10,13 @@ v0.5, 10/11/2016 -- Account usage management support. v0.6, 13/12/2016 -- Saved query management support. v0.7 01/02/2017 -- Log management support. Commands now follow pattern. - Deprecated old commands. \ No newline at end of file + Deprecated old commands. +v1.0 29/05/2017 -- Logset management support. + Live tail support. + Api key management support. + Bug fixes/enhancements around configuration file and api url(s). + Breaking change: Removed deprecated commands: addusertoteam, adduser, + createsavedquery, createteam, deletesavedquery, deleteteam, deleteuser, + deleteuserfromteam, events, getowner, getsavedqueries, getsavedquery, + getteams, getteam, listusers, recentevents, renameteam, updatesavedquery, + usage \ No newline at end of file diff --git a/lecli/cli.py b/lecli/cli.py index 8466d23..bcbc993 100644 --- a/lecli/cli.py +++ b/lecli/cli.py @@ -13,7 +13,6 @@ from lecli.log import commands as log_commands from lecli.logset import commands as logset_commands from lecli.api_key import commands as api_key_commands -from lecli import deprecated_commands @click.group() @@ -114,23 +113,3 @@ def tail(): delete.add_command(api_key_commands.delete_api_key, "apikey") tail.add_command(query_commands.tail_events, "events") - -cli.add_command(deprecated_commands.addusertoteam) -cli.add_command(deprecated_commands.adduser) -cli.add_command(deprecated_commands.createsavedquery) -cli.add_command(deprecated_commands.createteam) -cli.add_command(deprecated_commands.deletesavedquery) -cli.add_command(deprecated_commands.deleteteam) -cli.add_command(deprecated_commands.deleteuser) -cli.add_command(deprecated_commands.deleteuserfromteam) -cli.add_command(deprecated_commands.events) -cli.add_command(deprecated_commands.getowner) -cli.add_command(deprecated_commands.getsavedqueries) -cli.add_command(deprecated_commands.getsavedquery) -cli.add_command(deprecated_commands.getteams) -cli.add_command(deprecated_commands.getteam) -cli.add_command(deprecated_commands.listusers) -cli.add_command(deprecated_commands.recentevents) -cli.add_command(deprecated_commands.renameteam) -cli.add_command(deprecated_commands.updatesavedquery) -cli.add_command(deprecated_commands.usage) diff --git a/lecli/deprecated_commands.py b/lecli/deprecated_commands.py deleted file mode 100644 index 8d3c6ce..0000000 --- a/lecli/deprecated_commands.py +++ /dev/null @@ -1,227 +0,0 @@ -"""Deprecated commands""" -# pylint: skip-file - -import click -from lecli.query import commands as query_commands -from lecli.saved_query import commands as saved_query_commands -from lecli.team import commands as team_commands -from lecli.usage import commands as usage_commands -from lecli.user import commands as user_commands - -@click.command() -@click.pass_context -def getsavedqueries(ctx): - """Deprecated method to get a list of saved queries""" - click.echo("""This method is deprecated, please use: \n\t lecli get savedqueries""") - ctx.forward(saved_query_commands.get_saved_queries) - - -@click.command() -@click.argument('query_id', type=click.STRING) -@click.pass_context -def getsavedquery(ctx, query_id): - """Deprecated command to get the saved query with the given ID""" - click.echo("""This method is deprecated, please use: \n\t lecli get savedquery""") - ctx.forward(saved_query_commands.get_saved_query) - - -@click.command() -@click.argument('name', type=click.STRING) -@click.argument('statement', type=click.STRING) -@click.option('-f', '--timefrom', help='Time to query from (unix epoch)', type=int) -@click.option('-t', '--timeto', help='Time to query to (unix epoch)', type=int) -@click.option('-r', '--relative_range', help='Relative time range (ex: last x :timeunit)', - type=click.STRING) -@click.option('-l', '--logs', help='Logs(colon delimited if multiple)', type=click.STRING) -@click.pass_context -def createsavedquery(ctx, name, statement, timefrom, timeto, relative_range, logs): - """Deprecated method to create a saved query with the given arguments""" - click.echo("""This method is deprecated, please use: \n\t lecli create savedquery""") - ctx.forward(saved_query_commands.create_saved_query, name, statement, timefrom, timeto, relative_range, logs) - - -@click.command() -@click.argument('query_id', type=click.STRING) -@click.option('-n', '--name', help='Name of the saved query', type=click.STRING) -@click.option('-s', '--statement', help='LEQL statement', type=click.STRING) -@click.option('-f', '--timefrom', help='Time to query from (unix epoch)', type=int) -@click.option('-t', '--timeto', help='Time to query to (unix epoch)', type=int) -@click.option('-r', '--relative_range', help='Relative time range (ex: last x :timeunit)', - type=click.STRING) -@click.option('-l', '--logs', help='Logs(colon delimited if multiple)', type=click.STRING) -@click.pass_context -def updatesavedquery(ctx, query_id, name, statement, timefrom, timeto, relative_range, logs): - """Deprecated method to update the saved query with the given arguments""" - click.echo("""This method is deprecated, please use: \n\t lecli update savedquery""") - ctx.forward(saved_query_commands.update_saved_query) - - -@click.command() -@click.argument('query_id', type=click.STRING) -@click.pass_context -def deletesavedquery(ctx, query_id): - """Deprecated method to delete the saved query with given ID""" - click.echo("""This method is deprecated, please use: \n\t lecli delete savedquery""") - ctx.forward(saved_query_commands.delete_saved_query) - - -@click.command() -@click.option('-s', '--start', type=click.STRING, default=None) -@click.option('-e', '--end', type=click.STRING, default=None) -@click.pass_context -def usage(ctx, start, end): - """Deprecated method to get account's usage information""" - click.echo("""This method is deprecated, please use: \n\t lecli get usage""") - ctx.forward(usage_commands.get_usage) - - -@click.command() -@click.pass_context -def getteams(ctx): - """Deprecated method to get teams that are associated with this account""" - click.echo("""This method is deprecated, please use: \n\t lecli get teams""") - ctx.forward(team_commands.get_teams) - - -@click.command() -@click.argument('teamid', type=click.STRING, default=None) -@click.pass_context -def getteam(ctx, teamid): - """Deprecated method to get team with the provided id""" - click.echo("""This method is deprecated, please use: \n\t lecli get team""") - ctx.forward(team_commands.get_team) - - -@click.command() -@click.argument('name', type=click.STRING, default=None) -@click.pass_context -def createteam(ctx, name): - """Deprecated method to create a team with the provided name""" - click.echo("""This method is deprecated, please use: \n\t lecli create team""") - ctx.forward(team_commands.create_team) - - -@click.command() -@click.argument('teamid', type=click.STRING, default=None) -@click.pass_context -def deleteteam(ctx, teamid): - """Deprecated method to delete a team with the provided ID""" - click.echo("""This method is deprecated, please use: \n\t lecli delete team""") - ctx.forward(team_commands.delete_team) - - -@click.command() -@click.argument('teamid', type=click.STRING, default=None) -@click.argument('name', type=click.STRING, default=None) -@click.pass_context -def renameteam(ctx, teamid, name): - """Deprecated method to update the team with the provided id with name and user.""" - click.echo("""This method is deprecated, please use: \n\t lecli rename team""") - ctx.forward(team_commands.rename_team) - - -@click.command() -@click.argument('teamid', type=click.STRING, default=None) -@click.argument('userkey', type=click.STRING, default=None) -@click.pass_context -def addusertoteam(ctx, teamid, userkey): - """Deprecated method to update the team with the provided id with name and user.""" - click.echo("""This method is deprecated, please use: \n\t lecli update team add_user""") - ctx.forward(team_commands.addusertoteam) - - -@click.command() -@click.argument('teamid', type=click.STRING, default=None) -@click.argument('userkey', type=click.STRING, default=None) -@click.pass_context -def deleteuserfromteam(ctx, teamid, userkey): - """Deprecated method to update the team with the provided id with name and user.""" - click.echo("""This method is deprecated, please use: \n\t lecli delete user_from_team""") - ctx.forward(team_commands.deleteuserfromteam) - - -@click.command() -@click.argument('logkeys', type=click.STRING, nargs=-1) -@click.option('-n', '--lognick', default=None, - help='Nickname of log in config file') -@click.option('-g', '--loggroup', default=None, - help='Name of log group defined in config file') -@click.option('-f', '--timefrom', - help='Time to get events from (unix epoch)', type=int) -@click.option('-t', '--timeto', - help='Time to get events to (unix epoch)', type=int) -@click.option('--datefrom', - help='Date/Time to get events from (ISO-8601 datetime)') -@click.option('--dateto', - help='Date/Time to get events to (ISO-8601 datetime)') -@click.option('-r', '--relative_range', - help='Relative range to query until now (Examples: today, yesterday, ' - 'last x timeunit: last 2 hours, last 6 weeks etc.') -@click.pass_context -def events(ctx, logkeys, lognick, loggroup, timefrom, timeto, datefrom, dateto, relative_range): - """Deprecated method to get log events""" - click.echo("""This method is deprecated, please use: \n\t lecli get events""") - ctx.forward(query_commands.get_events) - - -@click.command() -@click.argument('logkeys', type=click.STRING, nargs=-1) -@click.option('-n', '--lognick', default=None, - help='Nickname of log in config file') -@click.option('-g', '--loggroup', default=None, - help='Name of log group defined in config file') -@click.option('-l', '--last', default=1200, - help='Time window from now to now-X in seconds over which events will be returned ' - '(Defaults to 20 mins)') -@click.option('-r', '--relative_range', - help='Relative range to query until now (Examples: today, yesterday, ' - 'last x timeunit: last 2 hours, last 6 weeks etc.') -@click.pass_context -def recentevents(ctx, logkeys, lognick, loggroup, last, relative_range): - """Deprecated method to get recent log events""" - click.echo("""This method is deprecated, please use: \n\t lecli get recentevents""") - ctx.forward(query_commands.get_recent_events) - - -@click.command() -@click.pass_context -def listusers(ctx): - """Deprecated method to get list of users in account""" - click.echo("""This method is deprecated, please use: \n\t lecli get users""") - ctx.forward(user_commands.get_users) - - -@click.command() -@click.option('-f', '--first', type=click.STRING, - help='First name of user to be added') -@click.option('-l', '--last', type=click.STRING, - help='Last name of user to be added') -@click.option('-e', '--email', type=click.STRING, - help='Email address of user to be added') -@click.option('-u', '--userkey', type=click.STRING, - help='User Key of user to be added') -@click.option('--force', is_flag=True, - help='Force adding user with confirmation prompt') -@click.pass_context -def adduser(ctx, first, last, email, userkey, force): - """Deprecated method to add a user to account""" - click.echo("""This method is deprecated, please use: \n\t lecli create user""") - ctx.forward(user_commands.create_user) - - -@click.command() -@click.option('-u', '--userkey', type=click.STRING, - help='User Key of user to be deleted') -@click.pass_context -def deleteuser(ctx, userkey): - """Deprecated method to delete a user from account""" - click.echo("""This method is deprecated, please use: \n\t lecli delete user""") - ctx.forward(user_commands.delete_user) - - -@click.command() -@click.pass_context -def getowner(ctx): - """Deprecated method to get account owner details""" - click.echo("""This method is deprecated, please use: \n\t lecli get owner""") - ctx.forward(user_commands.get_owner) diff --git a/tests/test_deprecated_commands.py b/tests/test_deprecated_commands.py deleted file mode 100644 index e9c8bee..0000000 --- a/tests/test_deprecated_commands.py +++ /dev/null @@ -1,206 +0,0 @@ -import uuid - -import time -from click.testing import CliRunner -from mock import patch - -from lecli import deprecated_commands - - -@patch('lecli.user.api.get_owner') -def test_get_owner(mocked_get_owner): - runner = CliRunner() - result = runner.invoke(deprecated_commands.getowner) - - assert "This method is deprecated" in result.output - mocked_get_owner.assert_called_once_with() - - -@patch('lecli.user.api.delete_user') -def test_userdel(mocked_delete_user): - runner = CliRunner() - result = runner.invoke(deprecated_commands.deleteuser, input=None) - - assert "This method is deprecated" in result.output - assert "Example usage: lecli delete user -u 12345678-aaaa-bbbb-1234-1234cb123456" in result.output - - runner.invoke(deprecated_commands.deleteuser, ['-u', str(uuid.uuid4())]) - assert mocked_delete_user.called - - -@patch('lecli.user.api.add_new_user') -def test_useradd(mocked_add_new_user): - first = "first" - last = "last" - email = "email" - - runner = CliRunner() - result = runner.invoke(deprecated_commands.adduser, ['-f', first, '-l', last, '-e', email], input='y') - - assert "This method is deprecated" in result.output - mocked_add_new_user.assert_called_once_with(first, last, email) - - -@patch('lecli.user.api.list_users') -def test_userlist(mocked_list_users): - runner = CliRunner() - result = runner.invoke(deprecated_commands.listusers) - - assert "This method is deprecated" in result.output - mocked_list_users.assert_called_once_with() - - -@patch('lecli.query.api.get_recent_events') -def test_recentevents(mocked_recent_events): - runner = CliRunner() - result = runner.invoke(deprecated_commands.recentevents, ['']) - - assert "This method is deprecated" in result.output - assert mocked_recent_events.called - - -@patch('lecli.query.api.get_recent_events') -def test_recentevents_with_relative_range(mocked_recent_events): - runner = CliRunner() - result = runner.invoke(deprecated_commands.recentevents, ['', '-r', 'last 3 min']) - - assert "This method is deprecated" in result.output - assert mocked_recent_events.called - - -@patch('lecli.query.api.get_events') -def test_events(mocked_get_events): - runner = CliRunner() - result = runner.invoke(deprecated_commands.events, ['', '-f', int(time.time()), '-t', - int(time.time())]) - - assert "This method is deprecated" in result.output - assert mocked_get_events.called - - -@patch('lecli.query.api.get_events') -def test_events_with_relative_range(mocked_get_events): - runner = CliRunner() - result = runner.invoke(deprecated_commands.events, ['', '-r', 'last 3 min']) - - assert "This method is deprecated" in result.output - assert mocked_get_events.called - - -@patch('lecli.team.api.get_teams') -def test_get_teams(mocked_get_teams): - runner = CliRunner() - result = runner.invoke(deprecated_commands.getteams) - - assert "This method is deprecated" in result.output - assert mocked_get_teams.called - - -@patch('lecli.team.api.get_team') -def test_get_team(mocked_get_team): - runner = CliRunner() - result = runner.invoke(deprecated_commands.getteam, [str(uuid.uuid4())]) - - assert "This method is deprecated" in result.output - assert mocked_get_team.called - - -@patch('lecli.team.api.create_team') -def test_create_team(mocked_create_team): - runner = CliRunner() - result = runner.invoke(deprecated_commands.createteam, ["test_team_name"]) - - assert "This method is deprecated" in result.output - assert mocked_create_team.called - - -@patch('lecli.team.api.delete_team') -def test_delete_team(mocked_delete_team): - runner = CliRunner() - result = runner.invoke(deprecated_commands.deleteteam, [str(uuid.uuid4())]) - - assert "This method is deprecated" in result.output - assert mocked_delete_team.called - - -@patch('lecli.team.api.rename_team') -def test_rename_team(mocked_rename_team): - runner = CliRunner() - result = runner.invoke(deprecated_commands.renameteam, [str(uuid.uuid4()), "new_name"]) - - assert "This method is deprecated" in result.output - assert mocked_rename_team.called - - -@patch('lecli.team.api.add_user_to_team') -def test_add_user_to_team(mocked_add_user): - runner = CliRunner() - result = runner.invoke(deprecated_commands.addusertoteam, [str(uuid.uuid4()), "test_user_name"]) - - assert "This method is deprecated" in result.output - assert mocked_add_user.called - - -@patch('lecli.usage.api.get_usage') -def test_add_user_to_team(mocked_get_usage): - runner = CliRunner() - result = runner.invoke(deprecated_commands.usage, ['-s', 'start', '-e', 'end']) - - assert "This method is deprecated" in result.output - assert mocked_get_usage.called - - -@patch('lecli.saved_query.api.create_saved_query') -def test_create_saved_query(mocked_create_saved_query): - runner = CliRunner() - result = runner.invoke(deprecated_commands.createsavedquery, ['new_saved_query', - 'where(/*/)', '-f', 10, '-t', 1000]) - - assert "This method is deprecated" in result.output - assert mocked_create_saved_query.called - - -@patch('lecli.saved_query.api.update_saved_query') -def test_update_saved_query(mocked_update_saved_query): - runner = CliRunner() - result = runner.invoke(deprecated_commands.updatesavedquery, [str(uuid.uuid4()), '-f', 10, - '-t', 1000]) - - assert "This method is deprecated" in result.output - assert mocked_update_saved_query.called - - -@patch('lecli.saved_query.api.get_saved_query') -def test_get_saved_query(mocked_get_saved_query): - runner = CliRunner() - result = runner.invoke(deprecated_commands.getsavedquery, [str(uuid.uuid4())]) - - assert "This method is deprecated" in result.output - assert mocked_get_saved_query.called - - -@patch('lecli.saved_query.api.get_saved_query') -def test_get_saved_queries(mocked_get_saved_queries): - runner = CliRunner() - result = runner.invoke(deprecated_commands.getsavedqueries) - - assert "This method is deprecated" in result.output - assert mocked_get_saved_queries.called - - -@patch('lecli.saved_query.api.get_saved_query') -def test_get_saved_query(mocked_get_saved_query): - runner = CliRunner() - result = runner.invoke(deprecated_commands.getsavedquery, ['12341234']) - - assert "This method is deprecated" in result.output - assert mocked_get_saved_query.called - - -@patch('lecli.saved_query.api.delete_saved_query') -def test_delete_saved_query(mocked_delete_saved_query): - runner = CliRunner() - result = runner.invoke(deprecated_commands.deletesavedquery, ['123456789012345678901234567890123456']) - - assert "This method is deprecated" in result.output - assert mocked_delete_saved_query.called