parent
bb7818e77d
commit
89fa65261c
@ -0,0 +1,46 @@ |
||||
import click |
||||
from zope import component |
||||
|
||||
from ceo_common.interfaces import IConfig |
||||
|
||||
from ..utils import http_post |
||||
from .utils import handle_sync_response |
||||
|
||||
|
||||
@click.group(short_help='Perform operations on the CSC cloud') |
||||
def cloud(): |
||||
pass |
||||
|
||||
|
||||
@cloud.group(short_help='Manage your cloud account') |
||||
def account(): |
||||
pass |
||||
|
||||
|
||||
@account.command(short_help='Activate your cloud account') |
||||
def activate(): |
||||
cfg = component.getUtility(IConfig) |
||||
base_domain = cfg.get('base_domain') |
||||
|
||||
resp = http_post('/api/cloud/accounts/create') |
||||
handle_sync_response(resp) |
||||
lines = [ |
||||
'Congratulations! Your cloud account has been activated.', |
||||
f'You may now login into https://cloud.{base_domain} with your CSC credentials.', |
||||
"Make sure to enter 'Members' for the domain (no quotes).", |
||||
] |
||||
for line in lines: |
||||
click.echo(line) |
||||
|
||||
|
||||
@cloud.group(short_help='Manage cloud accounts') |
||||
def accounts(): |
||||
pass |
||||
|
||||
|
||||
@accounts.command(short_help='Purge expired cloud accounts') |
||||
def purge(): |
||||
resp = http_post('/api/cloud/accounts/purge') |
||||
result = handle_sync_response(resp) |
||||
click.echo('Accounts to be deleted: ' + ','.join(result['accounts_to_be_deleted'])) |
||||
click.echo('Accounts which were deleted: ' + ','.join(result['accounts_deleted'])) |
@ -0,0 +1,29 @@ |
||||
from click.testing import CliRunner |
||||
import requests |
||||
|
||||
from ...utils import gssapi_token_ctx |
||||
from ceo.cli import cli |
||||
|
||||
|
||||
def test_cloud_account_activate(cli_setup, mock_cloud_server, new_user, cfg): |
||||
base_domain = cfg.get('base_domain') |
||||
requests.post('http://localhost:8080/reset') |
||||
|
||||
runner = CliRunner() |
||||
with gssapi_token_ctx(new_user.uid): |
||||
result = runner.invoke(cli, ['cloud', 'account', 'activate']) |
||||
expected = ( |
||||
'Congratulations! Your cloud account has been activated.\n' |
||||
f'You may now login into https://cloud.{base_domain} with your CSC credentials.\n' |
||||
"Make sure to enter 'Members' for the domain (no quotes).\n" |
||||
) |
||||
assert result.exit_code == 0 |
||||
assert result.output == expected |
||||
|
||||
|
||||
def test_cloud_accounts_purge(cli_setup, mock_cloud_server): |
||||
requests.post('http://localhost:8080/reset') |
||||
|
||||
runner = CliRunner() |
||||
result = runner.invoke(cli, ['cloud', 'accounts', 'purge']) |
||||
assert result.exit_code == 0 |
Loading…
Reference in new issue