Skip to content

Commit

Permalink
format support for pwsh version
Browse files Browse the repository at this point in the history
  • Loading branch information
glicht committed Apr 2, 2020
1 parent 470b31e commit 101586e
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 2 deletions.
24 changes: 23 additions & 1 deletion demisto_sdk/commands/format/tests/test_formatting_yml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from demisto_sdk.tests.constants_test import SOURCE_FORMAT_INTEGRATION_COPY, DESTINATION_FORMAT_INTEGRATION_COPY, \
SOURCE_FORMAT_SCRIPT_COPY, DESTINATION_FORMAT_SCRIPT_COPY, SOURCE_FORMAT_PLAYBOOK_COPY, \
DESTINATION_FORMAT_PLAYBOOK_COPY, EQUAL_VAL_FORMAT_PLAYBOOK_SOURCE, EQUAL_VAL_FORMAT_PLAYBOOK_DESTINATION,\
EQUAL_VAL_PATH
EQUAL_VAL_PATH, GIT_ROOT

import yaml

from demisto_sdk.commands.format.update_script import ScriptYMLFormat
from demisto_sdk.commands.format.update_playbook import PlaybookYMLFormat
Expand Down Expand Up @@ -140,3 +142,23 @@ def test_eqaul_value_in_file(input, output, path):
os.rmdir(path)
assert check
assert not format


@pytest.mark.parametrize('yml_file, yml_type', [
('format_pwsh_script.yml', 'script'),
('format_pwsh_integration.yml', 'integration')
])
def test_pwsh_format(tmpdir, yml_file, yml_type):
schema_path = os.path.normpath(
os.path.join(__file__, "..", "..", "..", "common", "schemas", '{}.yml'.format(yml_type)))
dest = str(tmpdir.join('pwsh_format_res.yml'))
src_file = f'{GIT_ROOT}/demisto_sdk/tests/test_files/{yml_file}'
if yml_type == 'script':
format_obj = ScriptYMLFormat(src_file, output=dest, path=schema_path)
else:
format_obj = IntegrationYMLFormat(src_file, output=dest, path=schema_path)
assert format_obj.run_format() == 0
with open(dest) as f:
data = yaml.safe_load(f)
assert data['fromversion'] == '5.5.0'
assert data['commonfields']['version'] == -1
4 changes: 3 additions & 1 deletion demisto_sdk/commands/format/update_integration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List, Tuple
from demisto_sdk.commands.common.constants import BANG_COMMAND_NAMES
from demisto_sdk.commands.common.constants import BANG_COMMAND_NAMES, TYPE_PWSH
from demisto_sdk.commands.format.format_constants import SKIP_RETURN_CODE, ERROR_RETURN_CODE, SUCCESS_RETURN_CODE
from demisto_sdk.commands.format.update_generic_yml import BaseUpdateYML
from demisto_sdk.commands.common.hook_validations.integration import IntegrationValidator
Expand All @@ -20,6 +20,8 @@ class IntegrationYMLFormat(BaseUpdateYML):

def __init__(self, input: str = '', output: str = '', path: str = '', from_version: str = '', no_validate: bool = False):
super().__init__(input, output, path, from_version, no_validate)
if not from_version and self.data.get("script", {}).get("type") == TYPE_PWSH:
self.from_version = '5.5.0'

def update_proxy_insecure_param_to_default(self):
"""Updates important integration arguments names and description."""
Expand Down
3 changes: 3 additions & 0 deletions demisto_sdk/commands/format/update_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from demisto_sdk.commands.format.format_constants import SKIP_RETURN_CODE, ERROR_RETURN_CODE, SUCCESS_RETURN_CODE
from demisto_sdk.commands.format.update_generic_yml import BaseUpdateYML
from demisto_sdk.commands.common.hook_validations.script import ScriptValidator
from demisto_sdk.commands.common.constants import TYPE_PWSH


class ScriptYMLFormat(BaseUpdateYML):
Expand All @@ -15,6 +16,8 @@ class ScriptYMLFormat(BaseUpdateYML):

def __init__(self, input: str = '', output: str = '', path: str = '', from_version: str = '', no_validate: bool = False):
super().__init__(input, output, path, from_version, no_validate)
if not from_version and self.data.get("type") == TYPE_PWSH:
self.from_version = '5.5.0'

def run_format(self) -> int:
try:
Expand Down
50 changes: 50 additions & 0 deletions demisto_sdk/tests/test_files/format_pwsh_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
commonfields:
id: PowerShell Remoting
version: 11
name: PowerShell Remoting
display: PowerShell Remoting
category: Utilities
description: |-
Use this integration in order to remote into another machine (windows/linux) using SSH, requires PowerShell core on both ends.
Installation steps needed on target machine can be found in Microsoft's official documentation:
https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/ssh-remoting-in-powershell-core?view=powershell-6
configuration:
- display: Domain/IP
name: hostname
defaultvalue: subdomain.example.com
type: 0
required: true
additionalinfo: Domain or IP of target machine
- display: Username
name: credentials
defaultvalue: ""
type: 9
required: true
additionalinfo: User name in target machine
script:
script: ''
type: powershell
commands:
- name: pwsh-remoting-query
arguments:
- name: command
required: true
description: PowerShell command (can be single or multiple in order of execution)
to run on the target machine
isArray: true
outputs:
- contextPath: PowerShellSSH.Query
description: Object that contains data about the response of a command run in
target machine
type: unknown
- contextPath: PowerShellSSH.Query.Result
description: The result of the command run from target machine
type: string
- contextPath: PowerShellSSH.Query.Command
description: The command sent to target machine, used as ID of that query
type: string
description: Remote to target machine which has powershell core installed on it
and is set up for remoting
execution: true
dockerimage: demisto/powershell:6.2.3.5563
runonce: false
31 changes: 31 additions & 0 deletions demisto_sdk/tests/test_files/format_pwsh_script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
args:
- default: false
description: JSON string to verfiy.
isArray: false
name: json
required: true
secret: false
- default: false
description: Optional schema against which to validate the JSON input.
isArray: false
name: schema
required: false
secret: false
comment: Verifies if the supplied JSON string is valid and optionally verifies against
a provided schema. The script utilizes Powershell's Test-JSON cmdlet.
commonfields:
id: VerifyJSON
version: 10
enabled: false
name: VerifyJSON
script: '-'
system: false
outputs:
- contextPath: VerifyJSON.Result
description: Whether the passed JSON was verified.
type: boolean
tags:
- JSON
- Utility
type: powershell
dockerimage: demisto/powershell:6.2.4.6166

0 comments on commit 101586e

Please sign in to comment.