Mini Shell
# -*- coding: utf-8 -*-
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
# keeps different API_VERSIONS of cloudlinux-awp-admin utility
from __future__ import absolute_import
import sys
import json
import datetime
from copy import deepcopy
from clwpos import gettext as _
from clwpos.wpos_admin import CloudlinuxWposAdmin, parser
from clwpos.constants import ON_OFF_IDENTIFIERS
from clwpos.feature_suites import ALL_SUITES
from clwpos.feature_suites.configurations import StatusSource
from clwpos.cli_versions.registry import admin_cli_version_registry
versioned_parser = deepcopy(parser)
@admin_cli_version_registry.register('1')
@admin_cli_version_registry.latest()
class CloudlinuxWposAdminV1(CloudlinuxWposAdmin):
"""
We announced those commands in public doc as api-version=1,
it means that we make any changes to CLI cautiously:
- if you are making change which could break backward compatibility (e.g - rename parameter) ->
you should create new class e.g CloudlinuxWposAdminV2 and override needed methods
"""
def _parse_args(self, argv):
return versioned_parser.parse_args(argv)
@versioned_parser.mutual_exclusive_group(
[
(["--disable"],
{"help": _("Hide Object Cache PRO banners"), "action": "store_true",
"default": False}),
(["--enable"],
{"help": _("Show Object Cache PRO banners"), "action": "store_true",
"default": False}),
],
required=True,
)
@versioned_parser.mutual_exclusive_group(
[
(["--all"], {"help": _("Argument for all users in the panel"), "action": "store_true"}),
(["--users"], {"help": _("Argument for user or list of comma separated users"), "type": str}),
],
required=True,
)
@versioned_parser.command(help=_("Manage visibility of Resid Object Cache PRO banners in plugin for websites"))
def object_cache_banner(self):
self._object_cache_banner()
return {}
@versioned_parser.argument("--users", help=_("User or list of comma separated users"), type=str,
required=("--all" not in sys.argv
and '--status' not in sys.argv))
@versioned_parser.argument("--all", help=_("Enable for all users"), action='store_true',
required=("--users" not in sys.argv
and '--status' not in sys.argv))
@versioned_parser.argument("--status", help=_("Get status of enabling"), action='store_true')
@versioned_parser.argument(
"--ignore-errors",
help=_("ignore ALL site check results after plugin install and enable"),
action="store_true",
)
@versioned_parser.argument(
'--skip-dns-check',
help=_('ignores ONLY website resolving check after plugin install and enable'),
action='store_true'
)
@versioned_parser.command(help=_('Enable optimization feature for specific user or all users'))
def enable_feature(self):
return self._enable_feature()
@versioned_parser.command(
help=_("Get current statistics of AccelerateWP enabled sites and allowed user's features"))
def get_stat(self) -> dict:
return self._get_stat()
@versioned_parser.mutual_exclusive_group(
[
(["--all"], {"help": _("Argument for all users in the panel"), "action": "store_true"}),
(["--status"], {"help": _("Show scan status"), "action": "store_true"}),
],
required=True,
)
@versioned_parser.command(help=_("Create the report about allowed and restricted user's features"))
def generate_report(self) -> dict:
return self._generate_report()
@versioned_parser.mutual_exclusive_group(
[
(["--all"], {"help": _("Argument for all users in the panel"), "action": "store_true"}),
(["--users"], {"help": _("Argument for user or list of comma separated users"), "type": str}),
],
required=True,
)
@versioned_parser.command(help=_("Return the report about allowed and restricted user's features"))
def get_report(self) -> dict:
return self._get_report()
@versioned_parser.command(help=_("Return public options"))
def get_options(self):
return self._get_options()
@versioned_parser.argument('--smart-advice-reminders',
help=_('Specify the SmartAdvice reminders activity setting'),
required=False,
default=None,
choices=ON_OFF_IDENTIFIERS)
@versioned_parser.argument('--smart-advice-notifications',
help=_('Specify the SmartAdvice notifications activity setting'),
required=False,
default=None,
choices=ON_OFF_IDENTIFIERS)
@versioned_parser.argument('--smart-advice-wordpress-plugin',
help=_('Automatic installation of WordPress SmartAdvice plugin'),
required=False,
default=None,
choices=ON_OFF_IDENTIFIERS)
@versioned_parser.argument('--object-cache-banner-visible',
help=_('Specify visibility of Redis Object Cache Pro banner'),
required=False,
default=None,
choices=ON_OFF_IDENTIFIERS)
@versioned_parser.argument('--icon-visible',
help=_('Specify visibility of AccelerateWP icon to end-users'),
default=None,
choices=ON_OFF_IDENTIFIERS)
@versioned_parser.argument('--feature-visible',
help=_('Specify visibility of AccelerateWP feature(s) to end-users'),
default=None,
choices=ON_OFF_IDENTIFIERS)
@versioned_parser.argument('--features',
default=None,
help=_('Specify features to be visible or invisible (comma separated)'))
@versioned_parser.argument('--upgrade-url', help=_('An url to be shown when user need to update plan. '
'Set option to empty string to disable.'),
default=None)
@versioned_parser.argument('--suite', default='accelerate_wp_premium',
help=_('Specify for which suite "upgrade-url" must be set'),
choices=[suite for suite in ALL_SUITES.keys()])
@versioned_parser.command(help=_("Manage global options"))
def set_options(self) -> dict:
return self._set_options()
@versioned_parser.argument(
"--suites",
help=_("Argument for suite of list of comma separated suites"),
type=str,
required=True
)
@versioned_parser.mutual_exclusive_group(
[
(["--allowed"], {"help": _("Allow suites for users"), "action": "store_true"}),
(["--default"], {"help": _("Set default suite status for user"), "action": "store_true"}),
(["--disallowed"], {"help": _("Disallow suites for users"), "action": "store_true"}),
(["--visible"], {"help": _("Make suites visible for users"), "action": "store_true"}),
(["--visible-for-all"], {"help": _("Allow suites for all users"), "action": "store_true"}),
(["--allowed-for-all"], {"help": _("Allow suites for all users"), "action": "store_true"}),
(["--disallowed-for-all"],
{"help": _("Disallow suites for all users"), "action": "store_true"}),
],
required=True,
)
@versioned_parser.argument("--users", help=_("User or list of comma separated users"), type=str,
required=(not (
"--allowed-for-all" in sys.argv
or "--disallowed-for-all" in sys.argv
or "--visible-for-all" in sys.argv
)))
@versioned_parser.argument("--source", help=_("Override the source of config change"),
choices=[key.name for key in StatusSource])
@versioned_parser.argument("--attrs", help=_("Set additional suite configuration options as json string, example: "
"--attrs='{\"tariff_limit\": \"100 GB\"}'"),
type=json.loads)
@versioned_parser.argument("--purchase-date", help=_("Date when user payed for the service last time"),
default=datetime.date.today(),
type=lambda s: datetime.datetime.strptime(s, '%Y-%m-%d').date())
@versioned_parser.argument("--preserve-user-settings", help=_("Keep per-user settings without change"), default=False,
action='store_true')
@versioned_parser.command(help=_("Managing list of allowed suites for users"))
def set_suite(self) -> dict:
return self._set_suite()