Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitlab v2.2.22 - Argument Description Change #33855

Merged
merged 17 commits into from Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Packs/GitLab/CONTRIBUTORS.json
@@ -0,0 +1,3 @@
[
"Martin Ohl"
]
Expand Up @@ -72,7 +72,7 @@ script:
required: true
description: Manual command to fetch events and display them.
name: gitlab-get-events
dockerimage: demisto/fastapi:1.0.0.79757
dockerimage: demisto/fastapi:1.0.0.91458
isfetchevents: true
subtype: python3
marketplaces:
Expand Down
30 changes: 30 additions & 0 deletions Packs/GitLab/Integrations/GitLabv2/GitLabv2.py
Expand Up @@ -345,6 +345,32 @@ def gitlab_cancel_pipeline(self, project_id: str, pipeline_id: str) -> dict:
''' HELPER FUNCTIONS '''


def encode_file_path_if_needed(file_path: str) -> str:
"""Encode the file path if not already encoded.

Args:
file_path (str): The file path, can be URL encoded or not.

Returns:
str: Return the file path as is if already URL encoded, else, returns the encoding it.
"""
file_path_suffix = './' if file_path.startswith('./') else ''
anas-yousef marked this conversation as resolved.
Show resolved Hide resolved
# If starts with ./, then we don't want to encode the suffix, only the rest
file_path_to_encode = file_path[2:] if file_path.startswith('./') else file_path
anas-yousef marked this conversation as resolved.
Show resolved Hide resolved
encoded_file_path = ''

# To decode file_path_to_encode
decoded_file_path = urllib.parse.unquote(file_path_to_encode)

if decoded_file_path == file_path_to_encode:
anas-yousef marked this conversation as resolved.
Show resolved Hide resolved
# file_path_to_encode is not encoded, we can go ahead and encode it
encoded_file_path = urllib.parse.quote(file_path_to_encode, safe='')
else:
# file_path_to_encode is already encoded, no need to encode it
encoded_file_path = file_path_to_encode
return f"{file_path_suffix}{encoded_file_path}"


def check_args_for_update(args: dict, optional_params: list) -> dict:
'''
This function checks that at least one argument from optional params is in args.
Expand Down Expand Up @@ -801,6 +827,8 @@ def get_raw_file_command(client: Client, args: dict[str, Any]) -> list:
ref = args.get('ref', 'main')
file_path = args.get('file_path', '')
headers = ['path', 'reference', 'content']
if file_path:
file_path = encode_file_path_if_needed(file_path)
response = client.get_raw_file_request(file_path, ref)
outputs = {'path': file_path, 'content': response, 'ref': ref}
human_readable = tableToMarkdown('Raw file', outputs, headers=headers)
Expand Down Expand Up @@ -902,6 +930,8 @@ def file_get_command(client: Client, args: dict[str, Any]) -> CommandResults:
branch = args.get('ref', 'master')
file_path = args.get('file_path', '')
headers = ['FileName', 'FilePath', 'Ref', 'ContentSha', 'CommitId', 'LastCommitId', 'Size']
if file_path:
file_path = encode_file_path_if_needed(file_path)
response = client.file_get_request(file_path, branch)
human_readable_dict = {'FileName': response.get('file_name', ''),
'FilePath': response.get('file_path', ''),
Expand Down
2 changes: 1 addition & 1 deletion Packs/GitLab/Integrations/GitLabv2/GitLabv2.yml
Expand Up @@ -3391,7 +3391,7 @@ script:
script: '-'
type: python
subtype: python3
dockerimage: demisto/python3:3.10.13.74666
dockerimage: demisto/python3:3.10.14.91134
fromversion: 6.5.0
tests:
- Test-GitLab-v2
25 changes: 25 additions & 0 deletions Packs/GitLab/Integrations/GitLabv2/GitLabv2_test.py
Expand Up @@ -8,6 +8,31 @@ def util_load_json(path):
return json.loads(f.read())


@pytest.mark.parametrize(
"file_path, expected_encoded_file_path",
(
pytest.param("./CheckFileCommand", "./CheckFileCommand"),
pytest.param("test/test_file.py", "test%2Ftest_file.py"),
pytest.param("./test/test_file.py", "./test%2Ftest_file.py"),
pytest.param("./test%2Ftest_file.py", "./test%2Ftest_file.py"),
pytest.param("test%2Ftest_file.py", "test%2Ftest_file.py"),
),
)
def test_encode_file_path_if_needed(file_path, expected_encoded_file_path):
"""
Given:
- A file path
When:
- Running the helper method encode_file_path_if_needed, which dictates if a file path
should be encoded or not.
Then:
- Check if the returned file path was indeed encoded, or did not need encoding.
"""
from GitLabv2 import encode_file_path_if_needed
encoded_file_path = encode_file_path_if_needed(file_path)
assert encoded_file_path == expected_encoded_file_path


ARGS_CASES = [
(2, -1, False, # The page_size value must be equal to 1 or bigger.
{'error': 'limit and page arguments must be positive'} # expected
Expand Down
8 changes: 4 additions & 4 deletions Packs/GitLab/Integrations/GitLabv2/README.md
Expand Up @@ -1595,19 +1595,18 @@ Get the list of projects of a given group.

### gitlab-raw-file-get
***
Get file the file in a raw format.

Get the file in a raw format.

#### Base Command

`gitlab-raw-file-get`

#### Input

| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |
| file_path | The file path. | Required |
| ref | The branch to retrieve the file from, default is master. | Optional |

| ref | The branch to retrieve the file from. Default is master. | Optional |

#### Context Output

Expand All @@ -1617,6 +1616,7 @@ Get file the file in a raw format.
| GitLab.File.path | String | The file path. |
| GitLab.File.content | String | The file content. |


#### Command Example

```!gitlab-raw-file-get file_path=./gitlabca ref=main```
Expand Down
11 changes: 11 additions & 0 deletions Packs/GitLab/ReleaseNotes/2_2_22.md
@@ -0,0 +1,11 @@

#### Integrations

##### GitLab Event Collector

- Updated the Docker image to: *demisto/fastapi:1.0.0.91458*.

##### GitLab v2

- Fixed an issue for the commands *gitlab-file-get*, and *gitlab-raw-file-get*, where the argument *file_path* was not URL encoded.
- Updated the Docker image to: *demisto/python3:3.10.14.91134*.
2 changes: 1 addition & 1 deletion Packs/GitLab/pack_metadata.json
Expand Up @@ -2,7 +2,7 @@
"name": "GitLab",
"description": "Pack for handling gitlab operations",
"support": "xsoar",
"currentVersion": "2.2.21",
"currentVersion": "2.2.22",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down