Skip to content

Commit

Permalink
Update build.sh
Browse files Browse the repository at this point in the history
abuseipdb + version enhancements

ci debug
  • Loading branch information
adonm committed Mar 23, 2024
1 parent 0b0b5dc commit 48fab6c
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 4,816 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"features": {
"ghcr.io/devcontainers/features/python:1": {"version": "3.11"}
},
"onCreateCommand": "bash -i install.sh"
"onCreateCommand": "python install.py"
}
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to GitHub Pages and build js release
name: Deploy to GitHub Pages and build release if tagged

permissions:
contents: write
Expand All @@ -13,10 +13,10 @@ jobs:
uses: fastai/workflows/quarto-ghp@master
with:
version: '3.11'
- name: npm build
run: npm install && npm run build
- name: npm release upload
- name: build
run: ./build.sh
- name: release upload
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: atlaskit-transformer.bundle.js
files: dist/*
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ include settings.ini
include LICENSE
include CONTRIBUTING.md
include README.md
include squ/atlaskit-transformer.bundle.js
include nbdev_squ/atlaskit-transformer.bundle.js
recursive-exclude * __pycache__
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Below is how to install in a plain python 3.11+ environment

``` sh
pip install https://github.com/wagov/nbdev-squ/archive/refs/tags/v1.3.1.tar.gz
https://github.com/wagov/nbdev-squ/releases/download/v1.3.2/nbdev_squ-1.3.2-py3-none-any.whl
```

The installation can also be run in a notebook (we tend to use
Expand All @@ -18,7 +18,7 @@ should load the json secret *squconfig-`my_keyvault_tenantid`* from the
`my_kevault_name` keyvault.

``` python
%pip install https://github.com/wagov/nbdev-squ/archive/refs/tags/v1.3.1.tar.gz
%pip install https://github.com/wagov/nbdev-squ/releases/download/v1.3.2/nbdev_squ-1.3.2-py3-none-any.whl
import os; os.environ["SQU_CONFIG"] = "{{ my_keyvault_name }}/{{ my_keyvault_tenantid }}"

from nbdev_squ import api
Expand Down
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# Just used during CI to build static assets and add to release
npm install
npm run build
pip install build
python -m build
26 changes: 26 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# This is meant to be run to setup and prep for committing a release
# use nbdev_bump_version to increment the version itself then rerun this to update README.md _docs etc
from subprocess import run
import configparser, re

run(["pip", "install", "nbdev"])
run(["pip", "install", "-e", "."]) # get current project in dev mode
run("quarto --version || nbdev_install", shell=True)
run(["npx", "npm-check-updates", "-u"]) # convenient way to freshen package.json on each release
run(["npm", "install"])
run(["npm", "run", "build"])
run(["nbdev_clean"])
run(["nbdev_export"])

config = configparser.ConfigParser()
config.read('settings.ini')
version = config.get("DEFAULT", "version")
git_url = config.get("DEFAULT", "git_url")
latest_download = f"{git_url}/releases/download/v{version}/nbdev_squ-{version}-py3-none-any.whl"
index_text = open("nbs/index.ipynb").read()
with open("nbs/index.ipynb", "w") as index_nb:
index_nb.write(re.sub(f"{git_url}.*?-any.whl", latest_download, index_text))

run(["nbdev_readme"])
run(["nbdev_docs"])
10 changes: 0 additions & 10 deletions install.sh

This file was deleted.

2 changes: 1 addition & 1 deletion nbdev_squ/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.3.1"
__version__ = "1.3.2"
18 changes: 9 additions & 9 deletions nbdev_squ/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
'atlaskit_transformer', 'security_incidents', 'security_alerts']

# %% ../nbs/01_api.ipynb 3
import pandas, json, logging, time, requests, httpx_cache, io
import pandas, json, logging, time, requests, io, pkgutil
from .core import *
from diskcache import memoize_stampede
from importlib.metadata import version
from subprocess import run, CalledProcessError
from azure.monitor.query import LogsQueryClient, LogsBatchQuery, LogsQueryStatus
from azure.identity import AzureCliCredential
from benedict import benedict
from functools import cached_property
from abuseipdb_wrapper import AbuseIPDB
from atlassian import Jira
from tenable.io import TenableIO

# %% ../nbs/01_api.ipynb 5
logger = logging.getLogger(__name__)
Expand All @@ -36,27 +34,31 @@ def runzero(self):
"""
Returns a runzero client
"""
import httpx_cache
return httpx_cache.Client(base_url="https://console.rumble.run/api/v1.0", headers={"Authorization": f"Bearer {self.config.runzero_apitoken}"})

@cached_property
def abuseipdb(self):
"""
Returns an abuseipdb client
"""
return AbuseIPDB(API_KEY=self.config.abuseipdb_api_key)
from abuseipdb_wrapper import AbuseIPDB
return AbuseIPDB(api_key=self.config.abuseipdb_api_key)

@cached_property
def jira(self):
"""
Returns a jira client
"""
from atlassian import Jira
return Jira(url=self.config.jira_url, username=self.config.jira_username, password=self.config.jira_password)

@cached_property
def tio(self):
"""
Returns a TenableIO client
"""
from tenable.io import TenableIO
return TenableIO(self.config.tenable_access_key, self.config.tenable_secret_key)


Expand Down Expand Up @@ -237,11 +239,9 @@ def hunt(indicators, expression="has", columns=columns, workspaces=None, timespa

# %% ../nbs/01_api.ipynb 22
def atlaskit_transformer(inputtext, inputfmt="md", outputfmt="wiki", runtime="node"):
import nbdev_squ
transformer = dirs.user_cache_path / f"atlaskit-transformer.bundle_v{nbdev_squ.__version__}.js"
transformer = dirs.user_cache_path / f"atlaskit-transformer.bundle_v{version('nbdev_squ')}.js"
if not transformer.exists():
transformer_url = f'https://github.com/wagov/nbdev-squ/releases/download/v{nbdev_squ.__version__}/atlaskit-transformer.bundle.js'
transformer.write_bytes(requests.get(transformer_url).content)
transformer.write_bytes(pkgutil.get_data("nbdev_squ", "atlaskit-transformer.bundle.js"))
cmd = [runtime, str(transformer), inputfmt, outputfmt]
logger.debug(" ".join(cmd))
try:
Expand Down
20 changes: 10 additions & 10 deletions nbs/01_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@
"outputs": [],
"source": [
"#| export\n",
"import pandas, json, logging, time, requests, httpx_cache, io\n",
"import pandas, json, logging, time, requests, io, pkgutil\n",
"from nbdev_squ.core import *\n",
"from diskcache import memoize_stampede\n",
"from importlib.metadata import version\n",
"from subprocess import run, CalledProcessError\n",
"from azure.monitor.query import LogsQueryClient, LogsBatchQuery, LogsQueryStatus\n",
"from azure.identity import AzureCliCredential\n",
"from benedict import benedict\n",
"from functools import cached_property\n",
"from abuseipdb_wrapper import AbuseIPDB\n",
"from atlassian import Jira\n",
"from tenable.io import TenableIO"
"from functools import cached_property"
]
},
{
Expand Down Expand Up @@ -97,27 +95,31 @@
" \"\"\"\n",
" Returns a runzero client\n",
" \"\"\"\n",
" import httpx_cache\n",
" return httpx_cache.Client(base_url=\"https://console.rumble.run/api/v1.0\", headers={\"Authorization\": f\"Bearer {self.config.runzero_apitoken}\"})\n",
"\n",
" @cached_property\n",
" def abuseipdb(self):\n",
" \"\"\"\n",
" Returns an abuseipdb client\n",
" \"\"\"\n",
" return AbuseIPDB(API_KEY=self.config.abuseipdb_api_key)\n",
" from abuseipdb_wrapper import AbuseIPDB\n",
" return AbuseIPDB(api_key=self.config.abuseipdb_api_key)\n",
"\n",
" @cached_property\n",
" def jira(self):\n",
" \"\"\"\n",
" Returns a jira client\n",
" \"\"\"\n",
" from atlassian import Jira\n",
" return Jira(url=self.config.jira_url, username=self.config.jira_username, password=self.config.jira_password)\n",
"\n",
" @cached_property\n",
" def tio(self):\n",
" \"\"\"\n",
" Returns a TenableIO client\n",
" \"\"\"\n",
" from tenable.io import TenableIO\n",
" return TenableIO(self.config.tenable_access_key, self.config.tenable_secret_key)\n",
"\n",
"\n",
Expand Down Expand Up @@ -428,11 +430,9 @@
"source": [
"#| exports\n",
"def atlaskit_transformer(inputtext, inputfmt=\"md\", outputfmt=\"wiki\", runtime=\"node\"):\n",
" import nbdev_squ\n",
" transformer = dirs.user_cache_path / f\"atlaskit-transformer.bundle_v{nbdev_squ.__version__}.js\"\n",
" transformer = dirs.user_cache_path / f\"atlaskit-transformer.bundle_v{version('nbdev_squ')}.js\"\n",
" if not transformer.exists():\n",
" transformer_url = f'https://github.com/wagov/nbdev-squ/releases/download/v{nbdev_squ.__version__}/atlaskit-transformer.bundle.js'\n",
" transformer.write_bytes(requests.get(transformer_url).content)\n",
" transformer.write_bytes(pkgutil.get_data(\"nbdev_squ\", \"atlaskit-transformer.bundle.js\"))\n",
" cmd = [runtime, str(transformer), inputfmt, outputfmt]\n",
" logger.debug(\" \".join(cmd))\n",
" try:\n",
Expand Down
4 changes: 2 additions & 2 deletions nbs/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"Below is how to install in a plain python 3.11+ environment\n",
"\n",
"```sh\n",
"pip install https://github.com/wagov/nbdev-squ/archive/refs/tags/v1.3.1.tar.gz\n",
"https://github.com/wagov/nbdev-squ/releases/download/v1.3.2/nbdev_squ-1.3.2-py3-none-any.whl\n",
"```\n",
"\n",
"The installation can also be run in a notebook (we tend to use [JupyterLab Desktop](https://github.com/jupyterlab/jupyterlab-desktop) for local dev). The `SQU_CONFIG` env var indicates to nbdev_squ it should load the json secret *squconfig-`my_keyvault_tenantid`* from the `my_kevault_name` keyvault.\n",
"\n",
"```python\n",
"%pip install https://github.com/wagov/nbdev-squ/archive/refs/tags/v1.3.1.tar.gz\n",
"%pip install https://github.com/wagov/nbdev-squ/releases/download/v1.3.2/nbdev_squ-1.3.2-py3-none-any.whl\n",
"import os; os.environ[\"SQU_CONFIG\"] = \"{{ my_keyvault_name }}/{{ my_keyvault_tenantid }}\" \n",
"\n",
"from nbdev_squ import api\n",
Expand Down
2 changes: 1 addition & 1 deletion nbs/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ website:
contents:
- index.ipynb
- 00_core.ipynb
- 01_api.ipynb
- 01_api.ipynb
Loading

0 comments on commit 48fab6c

Please sign in to comment.