Skip to content

Commit

Permalink
CASMCMS-8790: Update CFS module for the addition of sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Bak committed Oct 17, 2023
1 parent 7cab083 commit df93828
Show file tree
Hide file tree
Showing 2 changed files with 1,989 additions and 152 deletions.
27 changes: 26 additions & 1 deletion cray/modules/cfs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# pylint: disable=too-many-arguments
import json
import click
import urllib.parse

from cray.constants import FROM_FILE_TAG
from cray.core import option
Expand Down Expand Up @@ -69,6 +70,7 @@ def setup(cfs_cli):
setup_sessions_create(cfs_cli, "v3")
remove_sessions_update(cfs_cli, "v3")
setup_components_update(cfs_cli, "v3")
setup_sources(cfs_cli)


# CONFIGURATIONS #
Expand Down Expand Up @@ -268,7 +270,7 @@ def setup_sessions_create(cfs_cli, version):

# COMPONENTS #
def create_components_update_shim(func):
""" Callback function to custom create our own payload """
""" Callback function to custombuild create our own payload """

def _decorator(component_id, state, tags, **kwargs):
payload = {v['name']: v['value'] for _, v in kwargs.items() if
Expand Down Expand Up @@ -314,4 +316,27 @@ def setup_components_update(cfs_cli, version):
command.callback = create_components_update_shim(command.callback)


# SOURCES #
def _encode_source_name(source_name):
# Quote twice. One level of decoding is automatically done the API framework, so one level of encoding
# produces the same problems as not encoding at all.
source_name = urllib.parse.quote(source_name, safe='')
source_name = urllib.parse.quote(source_name, safe='')
return source_name

def create_sources_shim(func):
""" Callback function to custom create our own payload """
def _decorator(source_id, **kwargs):
source_id = {"name": source_id["name"], "value": _encode_source_name(source_id["value"])}
return func(source_id=source_id, **kwargs)
return _decorator


def setup_sources(cfs_cli):
""" Adds the --state and --tags parameters for component updates """
for command_type in ["update", "delete", "describe"]:
command = cfs_cli.commands["v3"].commands['sources'].commands[command_type]
command.callback = create_sources_shim(command.callback)


setup(cli)
Loading

0 comments on commit df93828

Please sign in to comment.