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 e879aaf
Show file tree
Hide file tree
Showing 3 changed files with 2,007 additions and 151 deletions.
26 changes: 26 additions & 0 deletions cray/modules/cfs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
# pylint: disable=invalid-name
# pylint: disable=too-many-arguments
import json
import urllib.parse

import click

from cray.constants import FROM_FILE_TAG
Expand Down Expand Up @@ -69,6 +71,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 @@ -314,4 +317,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 e879aaf

Please sign in to comment.