tenable / integration-jira-cloud

69 stars 51 forks source link

Trying to run the tenable-jira integration script as an Azure Function App #46

Closed dil-ddsouza closed 4 years ago

dil-ddsouza commented 4 years ago

Hey Steve,

We are trying to create an Azure function app in order to run the integration script. This will save us from having a whole machine/instance running the integration.

So wanted to know what happens when the following is called upon: tenable-jira config.yaml

As in what script does it call upon? Since function app won't allow us to execute the above command at the OS level. So for example I can't do this: os.system('tenable-jira config.yaml')

Instead maybe we could directly run what the command 'tenable-jira config.yaml' calls upon.

If you have a better way of doing it or any advise, that would be extremely helpful.

SteveMcGrath commented 4 years ago

the tenable-jira commandline calls tenable_jira.cli:cli. Please let us know what you did if you get it running successfully so we can document it for others.

dil-ddsouza commented 4 years ago

Thanks Steve,

Can you please guide me as to how to run that directly? As in run the cli directly please? sorry if this is a stupid question to ask, I am only an amateur when it comes to programming.

SteveMcGrath commented 4 years ago

The function in question is here: https://github.com/tenable/integration-jira-cloud/blob/master/tenable_jira/cli.py#L59

To run it, you would need to do something like this:

from tenable_jira.cli import cli
import arrow

since = arrow.now().shift(days=-1).timestamp

with open('config.yaml') as config:
    cli(config, since)

The configfile param expects the file-like object of the configfile. The observiced_since param expects the unix timestamp (epoch) as an integer.

dil-ddsouza commented 4 years ago

Thanks Steve,

I tried doing that, but received the following errors: [14/05/2020 17:22:00] Usage: worker.py [OPTIONS] [CONFIGFILE] [14/05/2020 17:22:00] Try 'worker.py --help' for help. [14/05/2020 17:22:00] Error: Invalid value for '[CONFIGFILE]': Could not open file: tenable: [14/05/2020 17:22:00] : No such file or directory

Where would I need to place the config.yaml file? Do you reckon I should have it in the same directory as the script or within the tenable-jira module directory please?

SteveMcGrath commented 4 years ago

you'd likely have to have the config in the same path as the script you write.

dil-ddsouza commented 4 years ago

I tried that too but to no avail.

Also, when I use the the since as you directed me, it throws up an int object error:

Traceback (most recent call last): File "init.py", line 18, in cli(config, since) File "/home/ddsouza/Scripts/env/lib64/python3.6/site-packages/click/core.py", line 829, in call return self.main(*args, **kwargs) File "/home/ddsouza/Scripts/env/lib64/python3.6/site-packages/click/core.py", line 777, in main _bashcomplete(self, prog_name, complete_var) File "/home/ddsouza/Scripts/env/lib64/python3.6/site-packages/click/core.py", line 65, in _bashcomplete completevar = "{}_COMPLETE".format(progname.replace("-", "").upper()) AttributeError: 'int' object has no attribute 'replace'

dil-ddsouza commented 4 years ago

Here is the code too, i had to remove 'Since' so that I could test just running with config: import datetime import logging import os import requests from requests.auth import HTTPBasicAuth import json import objectpath from tenable.io import TenableIO from tenable_jira.cli import cli import arrow

since = arrow.now().shift(days=-1).timestamp print(since) with open('config.yaml') as config: cli(config)

and the error that it throws up is the same, even tho the config file is in the same dir: Usage: init.py [OPTIONS] [CONFIGFILE] Try 'init.py --help' for help.

Error: Invalid value for '[CONFIGFILE]': Could not open file: tenable: : No such file or directory

SteveMcGrath commented 4 years ago

seems like its a click thing. it wasn't intended to be run this way.

SteveMcGrath commented 4 years ago

You may want to look into the CliRunner in click...

https://click.palletsprojects.com/en/7.x/testing/#input-streams

dil-ddsouza commented 4 years ago

Thanks Steve, I'll read up on it

SteveMcGrath commented 4 years ago

I'll keep this issue open. If your successful, please report back what you did. We're working on building up the wiki with step-by-step guides.