Skip to content

Commit

Permalink
Merge branch 'demisto:master' into cyblethreatintel-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cyble-dev committed Jul 1, 2022
2 parents 0677330 + 1ef46e3 commit 4c9e289
Show file tree
Hide file tree
Showing 22 changed files with 548 additions and 490 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/create-internal-pr-from-external.yml
Expand Up @@ -5,9 +5,6 @@ on:
branches:
- contrib/**

permissions:
contents: read

jobs:
create_internal_pr:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitlab/ci/on-push.yml
Expand Up @@ -50,6 +50,8 @@ run-validations:

# runs in gitlab for the on-push flow, on every new commit pushed to the branch.
validate-content-conf:
tags:
- gke
stage: unittests-and-validations
needs: []
extends:
Expand Down
5 changes: 5 additions & 0 deletions Packs/CommonScripts/ReleaseNotes/1_7_10.md
@@ -0,0 +1,5 @@

#### Scripts
##### GenerateRandomString
- Improved implementation with limiting the maximum length of the generated string to be 10,000.
- Updated the Docker image to `3.10.4.30607`.
2 changes: 1 addition & 1 deletion Packs/CommonScripts/ReleaseNotes/1_7_7.md
Expand Up @@ -2,4 +2,4 @@
#### Scripts
##### HttpV2
- Updated the Docker image to: *demisto/python3:3.10.4.30607*.
- Added support for passing the *headers* parameter as string.
- Added support for passing the *headers* parameter as string.
@@ -0,0 +1,59 @@
import random
import string

import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401

MAX_LENGTH = 10000


def set_length(length):
if length <= 0:
return_error("Length must be greater than 0. Maximum value is {}.".format(MAX_LENGTH))

return min(length, MAX_LENGTH)


def set_characters(characters: str, digits: bool, lowercase: bool, punctuation: bool, uppercase: bool):
if not any([uppercase, lowercase, digits, punctuation]):
return_error("Punctuation, Digits, Uppercase or Lowercase must be True.")

characters += string.ascii_lowercase if lowercase else ''
characters += string.ascii_uppercase if uppercase else ''
characters += string.digits if digits else ''
characters += string.punctuation if punctuation else ''
return characters


def create_password(characters, length):
password = ""
for x in range(0, length):
password += random.SystemRandom(random.seed(time.time())).choice(characters) # type: ignore

entry_context = {'RandomString': password}
raw = json.loads(json.dumps(entry_context))
results = CommandResults(content_format=EntryFormat.JSON,
entry_type=EntryType.NOTE,
outputs=entry_context,
readable_output=tableToMarkdown('RandomString Generated.', raw) if raw else 'No result were found',
raw_response=raw)
return results


def main():
args = demisto.args()

punctuation = argToBoolean(args["Punctuation"])
lowercase = argToBoolean(args["Lowercase"])
uppercase = argToBoolean(args["Uppercase"])
digits = argToBoolean(args["Digits"])
length = set_length(arg_to_number(args["Length"], required=True))

characters = set_characters("", digits, lowercase, punctuation, uppercase)

results = create_password(characters, length)
return_results(results)


if __name__ == "__builtin__" or __name__ == "builtins":
main()
@@ -0,0 +1,53 @@
commonfields:
id: GenerateRandomString
version: -1
name: GenerateRandomString
comment: |-
Generates random string
script: ''
type: python
subtype: python3
tags: []
enabled: true
args:
- name: Length
required: true
description: Length of the string. Maximum is 10,000.
- name: Punctuation
required: true
auto: PREDEFINED
predefined:
- 'True'
- 'False'
description: If the string will include punctuation.
- name: Lowercase
required: true
auto: PREDEFINED
predefined:
- 'True'
- 'False'
description: If the string will include letters.
- name: Uppercase
description: if uppercase should be included
required: true
auto: PREDEFINED
predefined:
- 'True'
- 'False'
- name: Digits
required: true
description: If digits should be included
auto: PREDEFINED
predefined:
- 'True'
- 'False'
outputs:
- contextPath: RandomString
description: The generated string.
type: string
scripttarget: 0
runonce: false
tests:
- RandomStringGenerateTest
fromversion: 6.2.0
dockerimage: demisto/python3:3.10.4.30607
Expand Up @@ -14,7 +14,7 @@ Generates a random string.

| **Argument Name** | **Description** |
| --- | --- |
| Length | The length of the string |
| Length | The length of the string. Maximum is 10,000. |
| Punctuation | Whether the string will include punctuation. |
| Lowercase | Whether the string will include letters. |
| Uppercase | Whether uppercase should be included. |
Expand Down
128 changes: 0 additions & 128 deletions Packs/CommonScripts/Scripts/script-GenerateRandomString.yml

This file was deleted.

0 comments on commit 4c9e289

Please sign in to comment.