Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion st2client/st2client/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import abc
import six
import logging

from st2client.utils.color import DisplayColors
from st2client.formatters import doc


Expand Down Expand Up @@ -94,3 +94,12 @@ def print_output(self, subject, formatter, *args, **kwargs):
print(output)
else:
print("No matching items found")

def print_pack_enforcement_active_output(self, subject):
if isinstance(subject, list):
for sub in subject:
self.print_pack_enforcement_active_output(sub)
elif "Active" in subject.pack_enforcement:
print(DisplayColors.colorize('Could not register content such as actions, rules, sensors etc '
'for the "%s" pack due to license provision, please upgrade license '
'to use this pack '%(subject.name), DisplayColors.RED))
15 changes: 11 additions & 4 deletions st2client/st2client/commands/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def run_and_print(self, args, **kwargs):


class PackListCommand(resource.ResourceListCommand):
display_attributes = ["ref", "name", "description", "version", "author"]
attribute_display_order = ["ref", "name", "description", "version", "author"]
display_attributes = ["ref", "name", "description", "version", "author", "pack_enforcement"]
attribute_display_order = ["ref", "name", "description", "version", "author", "pack_enforcement"]


class PackGetCommand(resource.ResourceGetCommand):
Expand All @@ -206,6 +206,7 @@ class PackGetCommand(resource.ResourceGetCommand):
"email",
"keywords",
"description",
"pack_enforcement",
]
attribute_display_order = [
"name",
Expand All @@ -214,6 +215,7 @@ class PackGetCommand(resource.ResourceGetCommand):
"email",
"keywords",
"description",
"pack_enforcement",
]
help_string = "Get information about an installed pack."

Expand All @@ -238,6 +240,8 @@ def run(self, args, **kwargs):


class PackInstallCommand(PackAsyncCommand):
display_attributes = ["ref", "name", "description", "version", "author", "pack_enforcement"]
attribute_display_order = [ "ref", "name", "description", "version", "author", "pack_enforcement"]
def __init__(self, resource, *args, **kwargs):
super(PackInstallCommand, self).__init__(
resource,
Expand Down Expand Up @@ -352,11 +356,12 @@ def run_and_print(self, args, **kwargs):
self.print_output(
pack_instance,
table.PropertyValueTable,
attributes=args.attr,
attributes=self.display_attributes,
json=args.json,
yaml=args.yaml,
attribute_display_order=self.attribute_display_order,
)
self.print_pack_enforcement_active_output(pack_instance)
else:
all_pack_instances = self.app.client.managers["Pack"].get_all(**kwargs)
pack_instances = []
Expand All @@ -368,11 +373,13 @@ def run_and_print(self, args, **kwargs):
self.print_output(
pack_instances,
table.MultiColumnTable,
attributes=args.attr,
attributes=self.display_attributes,
widths=args.width,
json=args.json,
yaml=args.yaml,
attribute_display_order=self.attribute_display_order,
)
self.print_pack_enforcement_active_output(pack_instances)

warnings = instance.result["output"]["warning_list"]
for warning in warnings:
Expand Down
2 changes: 1 addition & 1 deletion st2client/st2client/models/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ class Pack(core.Resource):
_plural = "Packs"
_plural_display_name = "Packs"
_url_path = "packs"
_repr_attributes = ["name", "description", "version", "author"]
_repr_attributes = ["name", "description", "version", "author", "status"]
18 changes: 18 additions & 0 deletions st2common/st2common/bootstrap/actionsregistrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import st2common.content.utils as content_utils
import st2common.util.action_db as action_utils
import st2common.validators.api.action as action_validator
from st2common.services import packs as packs_service

__all__ = ["ActionsRegistrar", "register_actions"]

Expand Down Expand Up @@ -60,6 +61,14 @@ def register_from_packs(self, base_dirs):
LOG.debug("Pack %s does not contain actions.", pack)
continue
try:
# Check if pack has enforcement active then do not register actions
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Actions for the pack "%s" could not be registered due to license provision'
', please upgrade license to register actions for the pack',
pack,
)
continue
LOG.debug(
"Registering actions from pack %s:, dir: %s", pack, actions_dir
)
Expand Down Expand Up @@ -100,6 +109,15 @@ def register_from_pack(self, pack_dir):
if not actions_dir:
return registered_count

# Check if pack has enforcement active then do not register actions
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Actions for the pack "%s" could not be registered due to license provision'
', please upgrade license to register actions for the pack',
pack,
)
return registered_count

LOG.debug("Registering actions from pack %s:, dir: %s", pack, actions_dir)

try:
Expand Down
18 changes: 18 additions & 0 deletions st2common/st2common/bootstrap/aliasesregistrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from st2common.persistence.action import Action
from st2common.persistence.actionalias import ActionAlias
from st2common.exceptions.db import StackStormDBObjectNotFoundError
from st2common.services import packs as packs_service

__all__ = ["AliasesRegistrar", "register_aliases"]

Expand Down Expand Up @@ -57,6 +58,14 @@ def register_from_packs(self, base_dirs):
LOG.debug("Pack %s does not contain aliases.", pack)
continue
try:
# Check if pack has enforcement active then do not register aliases
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Aliases for the pack "%s" could not be registered due to license provision'
', please upgrade license to register aliases for the pack',
pack,
)
continue
LOG.debug(
"Registering aliases from pack %s:, dir: %s", pack, aliases_dir
)
Expand Down Expand Up @@ -97,6 +106,15 @@ def register_from_pack(self, pack_dir):
if not aliases_dir:
return registered_count, overridden_count

# Check if pack has enforcement active then do not register aliases
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Aliases for the pack "%s" could not be registered due to license provision'
', please upgrade license to register aliases for the pack',
pack,
)
return registered_count

LOG.debug("Registering aliases from pack %s:, dir: %s", pack, aliases_dir)

try:
Expand Down
3 changes: 2 additions & 1 deletion st2common/st2common/bootstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from st2common.util.file_system import get_file_list
from st2common.util.pack import get_pack_metadata
from st2common.util.pack import get_pack_ref_from_metadata
from st2common.util.pack_management import check_license_and_get_pack_enforcement_status
from st2common.exceptions.db import StackStormDBObjectNotFoundError

__all__ = ["ResourceRegistrar"]
Expand Down Expand Up @@ -189,7 +190,7 @@ def _register_pack_db(self, pack_name, pack_dir):
)
content["files"] = pack_file_list
content["path"] = pack_dir

content["pack_enforcement"] = check_license_and_get_pack_enforcement_status(pack_name)
pack_api = PackAPI(**content)
pack_api.validate()
pack_db = PackAPI.to_model(pack_api)
Expand Down
20 changes: 20 additions & 0 deletions st2common/st2common/bootstrap/configsregistrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from st2common.models.api.pack import ConfigAPI
from st2common.persistence.pack import Config
from st2common.exceptions.db import StackStormDBObjectNotFoundError
from st2common.services import packs as packs_service

__all__ = ["ConfigsRegistrar"]

Expand Down Expand Up @@ -81,6 +82,14 @@ def register_from_packs(self, base_dirs):
continue

try:
# Check if pack has enforcement active then do not register configs
if packs_service.is_pack_enforcement_active(pack_name):
LOG.error(
'Configs for the pack "%s" could not be registered due to license provision'
', please upgrade license to register configs for the pack',
pack_name,
)
continue
self._register_config_for_pack(pack=pack_name, config_path=config_path)
except Exception as e:
if self._fail_on_failure:
Expand Down Expand Up @@ -115,6 +124,17 @@ def register_from_pack(self, pack_dir):
if not os.path.isfile(config_path):
return 0

# Check if pack has enforcement active then do not register configs
if packs_service.is_pack_enforcement_active(pack_name):
LOG.error(
'Configs for the pack "%s" could not be registered due to license provision'
', please upgrade license to register configs for the pack',
pack_name,
)
return 0

LOG.debug("Registering configs from pack %s, dir: %s", pack_name, config_path)

self._register_config_for_pack(pack=pack_name, config_path=config_path)
return 1

Expand Down
18 changes: 18 additions & 0 deletions st2common/st2common/bootstrap/policiesregistrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from st2common.persistence.policy import PolicyType, Policy
from st2common.exceptions.db import StackStormDBObjectNotFoundError
from st2common.util import loader
from st2common.services import packs as packs_service


__all__ = ["PolicyRegistrar", "register_policy_types", "register_policies"]
Expand Down Expand Up @@ -60,6 +61,14 @@ def register_from_packs(self, base_dirs):
LOG.debug("Pack %s does not contain policies.", pack)
continue
try:
# Check if pack has enforcement active then do not register policies
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Policies for the pack "%s" could not be registered due to license provision'
', please upgrade license to register policies for the pack',
pack,
)
continue
LOG.debug(
"Registering policies from pack %s:, dir: %s", pack, policies_dir
)
Expand Down Expand Up @@ -97,6 +106,15 @@ def register_from_pack(self, pack_dir):
if not policies_dir:
return registered_count

# Check if pack has enforcement active then do not register policies
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Policies for the pack "%s" could not be registered due to license provision'
', please upgrade license to register policies for the pack',
pack,
)
return registered_count

LOG.debug("Registering policies from pack %s, dir: %s", pack, policies_dir)

try:
Expand Down
18 changes: 18 additions & 0 deletions st2common/st2common/bootstrap/rulesregistrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
)
from st2common.exceptions.db import StackStormDBObjectNotFoundError
import st2common.content.utils as content_utils
from st2common.services import packs as packs_service

__all__ = ["RulesRegistrar", "register_rules"]

Expand Down Expand Up @@ -58,6 +59,14 @@ def register_from_packs(self, base_dirs):
LOG.debug("Pack %s does not contain rules.", pack)
continue
try:
# Check if pack has enforcement active then do not register rules
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Rules for the pack "%s" could not be registered due to license provision'
', please upgrade license to register rules for the pack',
pack,
)
continue
LOG.debug("Registering rules from pack: %s", pack)
rules = self._get_rules_from_pack(rules_dir)
count, override = self._register_rules_from_pack(pack, rules)
Expand Down Expand Up @@ -92,6 +101,15 @@ def register_from_pack(self, pack_dir):
if not rules_dir:
return registered_count, overridden_count

# Check if pack has enforcement active then do not register rules
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Rules for the pack "%s" could not be registered due to license provision'
', please upgrade license to register rules for the pack',
pack,
)
return registered_count

LOG.debug("Registering rules from pack %s:, dir: %s", pack, rules_dir)

try:
Expand Down
18 changes: 18 additions & 0 deletions st2common/st2common/bootstrap/sensorsregistrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import st2common.content.utils as content_utils
from st2common.models.api.sensor import SensorTypeAPI
from st2common.persistence.sensor import SensorType
from st2common.services import packs as packs_service

__all__ = ["SensorsRegistrar", "register_sensors"]

Expand Down Expand Up @@ -58,6 +59,14 @@ def register_from_packs(self, base_dirs):
LOG.debug("Pack %s does not contain sensors.", pack)
continue
try:
# Check if pack has enforcement active then do not register sensors
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Sensors for the pack "%s" could not be registered due to license provision'
', please upgrade license to register sensors for the pack',
pack,
)
continue
LOG.debug(
"Registering sensors from pack %s:, dir: %s", pack, sensors_dir
)
Expand Down Expand Up @@ -100,6 +109,15 @@ def register_from_pack(self, pack_dir):
if not sensors_dir:
return registered_count, overridden_count

# Check if pack has enforcement active then do not register sensors
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Sensors for the pack "%s" could not be registered due to license provision'
', please upgrade license to register sensors for the pack',
pack,
)
return registered_count

LOG.debug("Registering sensors from pack %s:, dir: %s", pack, sensors_dir)

try:
Expand Down
18 changes: 18 additions & 0 deletions st2common/st2common/bootstrap/triggersregistrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from st2common.bootstrap.base import ResourceRegistrar
import st2common.content.utils as content_utils
from st2common.models.utils import sensor_type_utils
from st2common.services import packs as packs_service

__all__ = ["TriggersRegistrar", "register_triggers"]

Expand Down Expand Up @@ -53,6 +54,14 @@ def register_from_packs(self, base_dirs):
LOG.debug("Pack %s does not contain triggers.", pack)
continue
try:
# Check if pack has enforcement active then do not register triggers
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Triggers for the pack "%s" could not be registered due to license provision'
', please upgrade license to register triggers for the pack',
pack,
)
continue
LOG.debug(
"Registering triggers from pack %s:, dir: %s", pack, triggers_dir
)
Expand Down Expand Up @@ -91,6 +100,15 @@ def register_from_pack(self, pack_dir):
if not triggers_dir:
return registered_count

# Check if pack has enforcement active then do not register triggers
if packs_service.is_pack_enforcement_active(pack):
LOG.error(
'Triggers for the pack "%s" could not be registered due to license provision'
', please upgrade license to register triggers for the pack',
pack,
)
return registered_count

LOG.debug("Registering triggers from pack %s:, dir: %s", pack, triggers_dir)

try:
Expand Down
1 change: 1 addition & 0 deletions st2common/st2common/constants/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
SYSTEM_PACK_NAME,
PACKS_PACK_NAME,
LINUX_PACK_NAME,
DEFAULT_PACK_NAME,
]

# A list of pack names which can't be used by user-supplied packs
Expand Down
Loading
Loading