ok

Mini Shell

Direktori : /opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/cli_versions/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/cli_versions/admin_api.py

# -*- 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.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('--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-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()

Zerion Mini Shell 1.0