Skip to content

Commit

Permalink
cli lab instruction fixes (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
delliott90 authored Aug 15, 2023
1 parent 634f037 commit 1b2a342
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 36 deletions.
49 changes: 14 additions & 35 deletions docs/lab/STIX-shifter CLI Quick Lab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"* Python 3.8 or greater\n",
"* pip\n",
"* git\n",
"* `virtualevn` python library\n",
"* `virtualenv` python library\n",
"* Ability to run bash commands\n",
"\n",
"### Run the following steps in a terminal\n",
Expand Down Expand Up @@ -452,33 +452,12 @@
"This connector relies on running a local or remote MySQL database. The transmission calls interface with the datasource using the source APIs, in this case [mysql.connector](https://github.com/opencybersecurityalliance/stix-shifter/blob/develop/stix_shifter_modules/mysql/stix_transmission/api_client.py#L1). This is different from the STIX bundle connector that searches against a static JSON of data."
]
},
{
"cell_type": "markdown",
"id": "6e8194e1",
"metadata": {},
"source": [
"## Step 1: Install the required MySQL connector libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "718c2997",
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"pip install \\\n",
"stix-shifter-modules-mysql \\\n",
"mysql-connector-python"
]
},
{
"cell_type": "markdown",
"id": "da7fb10e",
"metadata": {},
"source": [
"## Step 2: Set the environment variables to be used in the CLI\n",
"## Step 1: Set the environment variables to be used in the CLI\n",
"\n",
"### Connection details"
]
Expand All @@ -491,12 +470,12 @@
"outputs": [],
"source": [
"sql_database = \"demo_db\"\n",
"sql_password = \"Giv3@m@n@fish\"\n",
"sql_password = \"\"\n",
"sql_host = \"localhost\"\n",
"table = \"demo_table\"\n",
"sql_user = \"root\"\n",
"%env MYSQL_CONNECTION_OBJECT {\"host\":\"localhost\", \"database\":\"demo_db\", \"options\":{\"table\":\"demo_table\"}}\n",
"%env MYSQL_AUTH_OBJECT {\"auth\": {\"username\": \"root\", \"password\": \"Giv3@m@n@fish\"}}\n",
"%env MYSQL_AUTH_OBJECT {\"auth\": {\"username\": \"root\", \"password\": \"\"}}\n",
"%env MYSQL_TABLE_OPTIONS {\"table\":\"demo_table\"}"
]
},
Expand Down Expand Up @@ -532,7 +511,7 @@
"id": "34956c4e",
"metadata": {},
"source": [
"## Step 3: Create the demo database"
"## Step 2: Create the demo database"
]
},
{
Expand Down Expand Up @@ -562,7 +541,7 @@
"id": "08dc6541",
"metadata": {},
"source": [
"## Step 4: Create and populate demo table"
"## Step 3: Create and populate demo table"
]
},
{
Expand Down Expand Up @@ -629,7 +608,7 @@
"id": "eab57f00",
"metadata": {},
"source": [
"## Step 5: Examine the demo table contents\n",
"## Step 4: Examine the demo table contents\n",
"\n",
"This will be the data the MySQL connector will query against."
]
Expand Down Expand Up @@ -693,7 +672,7 @@
"id": "43e69765",
"metadata": {},
"source": [
"## Step 6: Transmit the ping command\n",
"## Step 5: Transmit the ping command\n",
"The `ping` command will check that the connector can talk to the MySQL instance."
]
},
Expand All @@ -713,7 +692,7 @@
"id": "667963a0",
"metadata": {},
"source": [
"## Step 7: Translate a STIX pattern into a native SQL query\n",
"## Step 6: Translate a STIX pattern into a native SQL query\n",
"\n",
"Translation from a STIX pattern to a native query is controlled by a `from_stix.json` mapping file. A snippet of the [MySQL from-STIX mapping file](https://github.com/opencybersecurityalliance/stix-shifter/blob/develop/stix_shifter_modules/mysql/stix_translation/json/from_stix_map.json) shows:\n",
"\n",
Expand Down Expand Up @@ -938,7 +917,7 @@
"id": "16e603af",
"metadata": {},
"source": [
"## Step 8: Transmit the query command\n",
"## Step 7: Transmit the query command\n",
"The `query` command sends the native query to the data source."
]
},
Expand Down Expand Up @@ -966,7 +945,7 @@
"id": "fa444815",
"metadata": {},
"source": [
"## Step 9: Transmit the status command\n",
"## Step 8: Transmit the status command\n",
"\n",
"The `status` command passes in the search ID, in this case the query string, and returns the status of the search."
]
Expand All @@ -987,7 +966,7 @@
"id": "2fd0c37e",
"metadata": {},
"source": [
"## Step 10: Transmit the results command\n",
"## Step 9: Transmit the results command\n",
"\n",
"The `results` command returns the raw query results in JSON format. In addition to the query ID (for MySQL this would be the query string) an offset and length is passed into the CLI command. The example below passes in 1 and 2, this would mean that the results start at the first row, returning two rows in total."
]
Expand Down Expand Up @@ -1016,7 +995,7 @@
"id": "28cd409a",
"metadata": {},
"source": [
"## Step 11: Translate the query results into STIX\n",
"## Step 10: Translate the query results into STIX\n",
"\n",
"Similar to translating STIX patterns to native queries, translating JSON results to STIX is largely driven by the connector's `to_stix_map.json` file. A snippet of the [MySQL to-STIX mapping file](https://github.com/opencybersecurityalliance/stix-shifter/blob/develop/stix_shifter_modules/mysql/stix_translation/json/to_stix_map.json) is shown below:\n",
"\n",
Expand Down Expand Up @@ -1162,7 +1141,7 @@
"id": "693c0773",
"metadata": {},
"source": [
"## Step 12: Run the execute command against the MySQL connector\n",
"## Step 11: Run the execute command against the MySQL connector\n",
"\n",
"We did this before for the bundle connector. The execute command will run through each of the translation and transmission steps covered above and return a bundle of STIX results. The STIX results are based on the pattern that is passed in. The format for calling the execute command is:\n",
"```\n",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
here = os.path.abspath(os.path.dirname(__file__))
SKIP_ME = 'SKIP.ME'

with open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
with open(os.path.join(here, 'docs/README.md'), encoding='utf-8') as f:
long_description = f.read()

TMP_MAPPING_DIR = 'tmp_mapping'
Expand Down

0 comments on commit 1b2a342

Please sign in to comment.