feat(confluence): new Confluence runbook/knowledge integration

Confluence REST API, 6 commands: CQL search, get page, create/update page,
list spaces. Basic (email + API token) auth, stdlib-only.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Guillaume BOURGEOIS
2026-07-12 15:23:56 +02:00
parent 6d38896892
commit 54b077bfc9
7 changed files with 468 additions and 0 deletions
+86
View File
@@ -0,0 +1,86 @@
id: confluence
name: Confluence
version: 1.0.0
description: "Atlassian Confluence (REST API) — runbook and knowledge handling: search content (CQL), read a page, create and update pages, and list spaces. Basic (email + API token) authentication; stdlib-only, no extra Python dependencies."
changelog: "1.0.0 — Initial release: search content, get page, create/update page, list spaces."
category: productivity
# Per-instance configuration. HTTP Basic auth with an email + API token (Cloud)
# or username + password (Server/DC).
config_schema:
properties:
base_url:
type: string
description: "Confluence base URL (e.g. https://your.atlassian.net/wiki)"
email:
type: string
description: "Account email (Cloud) or username (Server)"
api_token:
type: string
description: "API token (Cloud) or password (Server)"
x-soar-sensitive: true
required:
- base_url
- email
- api_token
commands:
- id: search
name: confluence-search
description: "Search content using CQL."
risk: read
inputs_schema:
properties:
cql: { type: string, description: "CQL query (e.g. text ~ \"phishing runbook\")" }
limit: { type: number, description: "Max results (default 25)" }
required: [cql]
outputs_schema: { properties: {} }
- id: get_page
name: confluence-get-page
description: "Get a page by ID (with body)."
risk: read
inputs_schema:
properties:
page_id: { type: string, description: "Page (content) ID" }
required: [page_id]
outputs_schema: { properties: {} }
- id: create_page
name: confluence-create-page
description: "Create a page in a space."
inputs_schema:
properties:
space_key: { type: string, description: "Space key" }
title: { type: string, description: "Page title" }
body: { type: string, description: "Page body (storage/HTML format)" }
parent_id: { type: string, description: "Optional parent page ID" }
required: [space_key, title, body]
outputs_schema: { properties: {} }
- id: update_page
name: confluence-update-page
description: "Update a page's title/body (increments the version)."
inputs_schema:
properties:
page_id: { type: string, description: "Page ID" }
title: { type: string, description: "New title" }
body: { type: string, description: "New body (storage/HTML)" }
version: { type: number, description: "New version number (current version + 1)" }
required: [page_id, title, body, version]
outputs_schema: { properties: {} }
- id: list_spaces
name: confluence-list-spaces
description: "List spaces."
risk: read
inputs_schema:
properties:
limit: { type: number, description: "Max spaces (default 25)" }
required: []
outputs_schema: { properties: {} }
- id: test_connection
name: confluence-test-connection
description: "Verify connectivity and credentials (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,75 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return str(cfg.get("base_url", "")).rstrip("/") + "/rest/api"
def _auth(cfg):
raw = str(cfg.get("email", "")) + ":" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
space_key = inputs.get("space_key")
if not space_key:
raise Exception("space_key is required")
title = inputs.get("title")
if not title:
raise Exception("title is required")
body = inputs.get("body")
if not body:
raise Exception("body is required")
parent_id = inputs.get("parent_id")
page = {
"type": "page",
"title": title,
"space": {"key": space_key},
"body": {"storage": {"value": body, "representation": "storage"}},
}
if parent_id not in (None, ""):
page["ancestors"] = [{"id": parent_id}]
return request("POST", "/content", cfg, body=page)
_run(main)
@@ -0,0 +1,58 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return str(cfg.get("base_url", "")).rstrip("/") + "/rest/api"
def _auth(cfg):
raw = str(cfg.get("email", "")) + ":" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
page_id = inputs.get("page_id")
if not page_id:
raise Exception("page_id is required")
return request("GET", "/content/" + q(page_id), cfg, params={"expand": "body.storage,version,space"})
_run(main)
@@ -0,0 +1,56 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return str(cfg.get("base_url", "")).rstrip("/") + "/rest/api"
def _auth(cfg):
raw = str(cfg.get("email", "")) + ":" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
limit = inputs.get("limit")
return request("GET", "/space", cfg, params={"limit": int(limit or 25)})
_run(main)
+59
View File
@@ -0,0 +1,59 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return str(cfg.get("base_url", "")).rstrip("/") + "/rest/api"
def _auth(cfg):
raw = str(cfg.get("email", "")) + ":" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
cql = inputs.get("cql")
if not cql:
raise Exception("cql is required")
limit = inputs.get("limit")
return request("GET", "/content/search", cfg, params={"cql": cql, "limit": int(limit or 25)})
_run(main)
@@ -0,0 +1,56 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return str(cfg.get("base_url", "")).rstrip("/") + "/rest/api"
def _auth(cfg):
raw = str(cfg.get("email", "")) + ":" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
request("GET", "/space", cfg, params={"limit": 1})
return {"ok": True}
_run(main)
@@ -0,0 +1,78 @@
import json, os, sys, base64, urllib.parse, urllib.request, urllib.error
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return str(cfg.get("base_url", "")).rstrip("/") + "/rest/api"
def _auth(cfg):
raw = str(cfg.get("email", "")) + ":" + str(cfg.get("api_token", ""))
return "Basic " + base64.b64encode(raw.encode("utf-8")).decode("utf-8")
def request(method, path, cfg, body=None, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
data = json.dumps(body).encode("utf-8") if body is not None else None
headers = {"Authorization": _auth(cfg), "Accept": "application/json"}
if data is not None:
headers["Content-Type"] = "application/json"
req = urllib.request.Request(url, data=data, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=60) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
q = lambda v: urllib.parse.quote(str(v), safe="")
def main(cfg, inputs):
page_id = inputs.get("page_id")
if not page_id:
raise Exception("page_id is required")
title = inputs.get("title")
if not title:
raise Exception("title is required")
body = inputs.get("body")
if not body:
raise Exception("body is required")
version = inputs.get("version")
if version in (None, ""):
raise Exception("version is required")
return request(
"PUT",
"/content/" + q(page_id),
cfg,
body={
"type": "page",
"title": title,
"version": {"number": int(version)},
"body": {"storage": {"value": body, "representation": "storage"}},
},
)
_run(main)