<commit_before>"""

	Invoke a vRO workflow via the REST API. Added capability to specify arguments at the command line.

	If you omit the username and password arguments it will prompt for them. The password will be masked.

"""

# TODO needs testing by someone other than me.
# TODO build a script to retrieve a list of available workflows


import argparse
import requests
import json
import getpass

def getargs():
    parser = argparse.ArgumentParser()
    parser.add_argument('-s', '--server',
                        required=True,
                        action='store',
                        help='vRealize Orchestrator server')
    parser.add_argument('-u', '--username',
                        required=False,
                        action='store',
                        help='Username to access vRealize Orchestrator')
    parser.add_argument('-p', '--password',
                        required=False,
                        action='store',
                        help='The password used to access vRealize Orchestrator')
    parser.add_argument('-w', '--workflow',
                        required=True,
                        action='store',
                        help='Workflow ID')
    parser.add_argument('-j', '--json',
                        required=False,
                        action='store',
                        dest='input_json',
                        help='Path to JSON post body')
    parser.add_argument('--nosslverify',
    					required=False,
    					action='store_true',
    					help='Stop SSL certificate validation')
    args = parser.parse_args()
    return args

def run_workflow(server, username, password, workflow, input_json, nosslverify):
    try:
        if nosslverify:
            ssl_verify = False

        with open(input_json, 'r') as f:
            postdata = json.dumps(f)

        r = requests.post(url='https://' + server + 'vco/api/workflows/' + workflow + '/executions',
                          verify=ssl_verify,
                          auth=(username, password),
                          headers= {'Content-Type': 'application/json',
                                    'Accept': 'application/json'},
                          data=postdata)

        print r.status_code

    except requests.RequestException as e:
        print e


def main():
    args = getargs()
    server = args.server
    username = args.username
    password = args.password
    workflow = args.workflow
    input_json = args.input_json
    nosslverify = args.nosslverify

    if not username:
        username = raw_input("target host username:")

    if not password:
        password_request = "Target host '%s' Password: " % username
        password = getpass.getpass(password_request)

    run_workflow(server, username, password, workflow, input_json, nosslverify)
<commit_msg>Variable scope was broken with SSL verification. Should be working now<commit_after>"""

	Invoke a vRO workflow via the REST API. Added capability to specify arguments at the command line.

	If you omit the username and password arguments it will prompt for them. The password will be masked.

"""

# TODO needs testing by someone other than me.
# TODO build a script to retrieve a list of available workflows


import argparse
import requests
import json
import getpass

def getargs():
    parser = argparse.ArgumentParser()
    parser.add_argument('-s', '--server',
                        required=True,
                        action='store',
                        help='vRealize Orchestrator server')
    parser.add_argument('-u', '--username',
                        required=False,
                        action='store',
                        help='Username to access vRealize Orchestrator')
    parser.add_argument('-p', '--password',
                        required=False,
                        action='store',
                        help='The password used to access vRealize Orchestrator')
    parser.add_argument('-w', '--workflow',
                        required=True,
                        action='store',
                        help='Workflow ID')
    parser.add_argument('-j', '--json',
                        required=False,
                        action='store',
                        dest='input_json',
                        help='Path to JSON post body')
    parser.add_argument('--nosslverify',
    					required=False,
    					action='store_true',
    					help='Stop SSL certificate validation')
    args = parser.parse_args()
    return args

def run_workflow(server, username, password, workflow, input_json, ssl_verify):
    try:

        with open(input_json, 'r') as f:
            postdata = json.dumps(f)

        r = requests.post(url='https://' + server + 'vco/api/workflows/' + workflow + '/executions',
                          verify=ssl_verify,
                          auth=(username, password),
                          headers= {'Content-Type': 'application/json',
                                    'Accept': 'application/json'},
                          data=postdata)

        print r.status_code

    except requests.RequestException as e:
        print e


def main():
    args = getargs()
    server = args.server
    username = args.username
    password = args.password
    workflow = args.workflow
    input_json = args.input_json
    nosslverify = args.nosslverify

    if not username:
        username = raw_input("target host username:")

    if not password:
        password_request = "Target host '%s' Password: " % username
        password = <PASSWORD>(password_request)

    if nosslverify:
        ssl_verify = False
        run_workflow(server, username, password, workflow, input_json, ssl_verify)
    else:
        run_workflow(server, username, password, workflow, input_json, ssl_verify=True)

{'fraction_non_alphanumeric': 0.09495192307692307, 'fraction_numerical': 0.0, 'mean_word_length': 1.8221899224806202, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1014641', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1435, 'n_words': 423}