Skip to content

Commit e228641

Browse files
authored
[example] Use environment variable for example to run (#981)
1 parent ef0ac82 commit e228641

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+186
-124
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ Integration testing
8989
$ pytest ./tests/02-integration/
9090
```
9191

92+
Example testing:
93+
94+
> OpenCTI must be running
95+
96+
```bash
97+
cd examples
98+
# Configure with you local instance of OpenCTI
99+
export OPENCTI_API_URL="http://localhost:4000"
100+
export OPENCTI_API_TOKEN="xxxxxxxxxxxxxxxxxxxxxx"
101+
102+
#Run one example file
103+
python get_indicators_of_malware.py
104+
```
105+
92106
## About
93107

94108
OpenCTI is a product designed and developed by the company [Filigran](https://filigran.io).

examples/add_external_reference_to_report.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# coding: utf-8
2+
import os
23

34
from dateutil.parser import parse
45

56
from pycti import OpenCTIApiClient
67

78
# Variables
8-
api_url = "http://opencti:4000"
9-
api_token = "bfa014e0-e02e-4aa6-a42b-603b19dcf159"
9+
api_url = os.getenv("OPENCTI_API_URL", "http://opencti:4000")
10+
api_token = os.getenv("OPENCTI_API_TOKEN", "bfa014e0-e02e-4aa6-a42b-603b19dcf159")
1011

1112
# OpenCTI initialization
1213
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/add_label_to_malware.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# coding: utf-8
2+
import os
23

34
from pycti import OpenCTIApiClient
45

56
# Variables
6-
api_url = "http://opencti:4000"
7-
api_token = "bfa014e0-e02e-4aa6-a42b-603b19dcf159"
7+
api_url = os.getenv("OPENCTI_API_URL", "http://opencti:4000")
8+
api_token = os.getenv("OPENCTI_API_TOKEN", "bfa014e0-e02e-4aa6-a42b-603b19dcf159")
89

910
# OpenCTI initialization
1011
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/add_label_to_observable.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# coding: utf-8
2+
import os
23

34
from pycti import OpenCTIApiClient
45

56
# Variables
6-
api_url = "http://opencti:4000"
7-
api_token = "bfa014e0-e02e-4aa6-a42b-603b19dcf159"
7+
api_url = os.getenv("OPENCTI_API_URL", "http://opencti:4000")
8+
api_token = os.getenv("OPENCTI_API_TOKEN", "bfa014e0-e02e-4aa6-a42b-603b19dcf159")
89

910
# OpenCTI initialization
1011
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/add_organization_to_sector.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# coding: utf-8
2+
import os
23

34
from pycti import OpenCTIApiClient
45

56
# Variables
6-
api_url = "http://opencti:4000"
7-
api_token = "bfa014e0-e02e-4aa6-a42b-603b19dcf159"
7+
api_url = os.getenv("OPENCTI_API_URL", "http://opencti:4000")
8+
api_token = os.getenv("OPENCTI_API_TOKEN", "bfa014e0-e02e-4aa6-a42b-603b19dcf159")
89

910
# OpenCTI initialization
1011
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/add_tool_usage_to_intrusion-set.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# coding: utf-8
2+
import os
23

34
from pycti import OpenCTIApiClient
45

56
# Variables
6-
api_url = "http://opencti:4000"
7-
api_token = "bfa014e0-e02e-4aa6-a42b-603b19dcf159"
7+
api_url = os.getenv("OPENCTI_API_URL", "http://opencti:4000")
8+
api_token = os.getenv("OPENCTI_API_TOKEN", "bfa014e0-e02e-4aa6-a42b-603b19dcf159")
89

910
# OpenCTI initialization
1011
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/ask_enrichment_of_observable.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# coding: utf-8
2+
import os
3+
24
from pycti import OpenCTIApiClient
35

46
# Variables
5-
api_url = "http://opencti:4000"
6-
api_token = "bfa014e0-e02e-4aa6-a42b-603b19dcf159"
7+
api_url = os.getenv("OPENCTI_API_URL", "http://opencti:4000")
8+
api_token = os.getenv("OPENCTI_API_TOKEN", "bfa014e0-e02e-4aa6-a42b-603b19dcf159")
79
# Define name of INTERNAL_ENRICHMENT Connector which can enrich IPv4 addresses
810
connector_name = "AbuseIPDB"
911

examples/cmd_line_tag_latest_indicators_of_threat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# coding: utf-8
22
import argparse
3+
import os
34

45
from dateutil.parser import parse
56

67
from pycti import OpenCTIApiClient
78

89
# Variables
9-
api_url = "http://opencti:4000"
10-
api_token = "bfa014e0-e02e-4aa6-a42b-603b19dcf159"
10+
api_url = os.getenv("OPENCTI_API_URL", "http://opencti:4000")
11+
api_token = os.getenv("OPENCTI_API_TOKEN", "bfa014e0-e02e-4aa6-a42b-603b19dcf159")
1112

1213
# OpenCTI initialization
1314
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/create_campaign_attributed-to_intrusion_set.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# coding: utf-8
2+
import os
23

34
from dateutil.parser import parse
45

56
from pycti import OpenCTIApiClient
67

78
# Variables
8-
api_url = "http://opencti:4000"
9-
api_token = "bfa014e0-e02e-4aa6-a42b-603b19dcf159"
9+
api_url = os.getenv("OPENCTI_API_URL", "http://opencti:4000")
10+
api_token = os.getenv("OPENCTI_API_TOKEN", "bfa014e0-e02e-4aa6-a42b-603b19dcf159")
1011

1112
# OpenCTI initialization
1213
opencti_api_client = OpenCTIApiClient(api_url, api_token)

examples/create_file_with_hashes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# coding: utf-8
2+
import os
23

34
from pycti import OpenCTIApiClient
45

56
# Variables
6-
api_url = "http://opencti:4000"
7-
api_token = "bfa014e0-e02e-4aa6-a42b-603b19dcf159"
7+
api_url = os.getenv("OPENCTI_API_URL", "http://opencti:4000")
8+
api_token = os.getenv("OPENCTI_API_TOKEN", "bfa014e0-e02e-4aa6-a42b-603b19dcf159")
89

910
# OpenCTI initialization
1011
opencti_api_client = OpenCTIApiClient(api_url, api_token)

0 commit comments

Comments
 (0)