Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'demisto:master' into cyblethreatintel-updates
- Loading branch information
Showing
22 changed files
with
548 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Packs/CommonScripts/Scripts/GenerateRandomString/GenerateRandomString.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
53 changes: 53 additions & 0 deletions
53
Packs/CommonScripts/Scripts/GenerateRandomString/GenerateRandomString.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 0 additions & 128 deletions
128
Packs/CommonScripts/Scripts/script-GenerateRandomString.yml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.