pubint 0.20.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. integrations/__init__.py +21 -0
  2. integrations/__main__.py +5 -0
  3. integrations/avrofile.py +268 -0
  4. integrations/calls.py +612 -0
  5. integrations/ci_usage/__init__.py +22 -0
  6. integrations/ci_usage/cluster.py +202 -0
  7. integrations/ci_usage/jobs.py +255 -0
  8. integrations/ci_usage/main.py +60 -0
  9. integrations/classes.json +6 -0
  10. integrations/cli.py +226 -0
  11. integrations/clients/__init__.py +2 -0
  12. integrations/clients/cloudflare_dns.py +36 -0
  13. integrations/clients/gh.py +80 -0
  14. integrations/clients/github_app_token.py +82 -0
  15. integrations/clients/github_edit_pr.py +257 -0
  16. integrations/clients/github_test_org.py +261 -0
  17. integrations/clients/linear.py +73 -0
  18. integrations/clients/slack.py +161 -0
  19. integrations/clients/storage.py +219 -0
  20. integrations/clients/storage_routes.py +31 -0
  21. integrations/consumer.py +256 -0
  22. integrations/heartbeat.py +148 -0
  23. integrations/ingest/__init__.py +7 -0
  24. integrations/ingest/app.py +53 -0
  25. integrations/ingest/bigquery.py +112 -0
  26. integrations/ingest/google_token.py +127 -0
  27. integrations/ingest/inbox.py +469 -0
  28. integrations/ingest/main.py +189 -0
  29. integrations/ingest/notify.py +90 -0
  30. integrations/not-providers.json +7 -0
  31. integrations/plugins/_github.json +58 -0
  32. integrations/plugins/anthropic.api.json +27 -0
  33. integrations/plugins/bitwarden.secrets.json +83 -0
  34. integrations/plugins/calcom.booking.json +27 -0
  35. integrations/plugins/cloudflare.dns.json +42 -0
  36. integrations/plugins/cloudflare.pages.json +29 -0
  37. integrations/plugins/cloudflare.r2.json +24 -0
  38. integrations/plugins/cloudflare.workers.json +28 -0
  39. integrations/plugins/crates-io.publish.json +30 -0
  40. integrations/plugins/crossref.lookup.json +18 -0
  41. integrations/plugins/desec.dns.json +27 -0
  42. integrations/plugins/dns.lookup.json +41 -0
  43. integrations/plugins/eudi.wallet.json +25 -0
  44. integrations/plugins/finto.terms.json +21 -0
  45. integrations/plugins/github.actions-oidc.json +27 -0
  46. integrations/plugins/github.app-token.json +60 -0
  47. integrations/plugins/github.board-read.json +29 -0
  48. integrations/plugins/github.edit-pr.json +72 -0
  49. integrations/plugins/github.ghcr.json +28 -0
  50. integrations/plugins/github.repo-ops.json +122 -0
  51. integrations/plugins/google.bigquery.json +29 -0
  52. integrations/plugins/google.calendar.json +24 -0
  53. integrations/plugins/google.cloud.json +110 -0
  54. integrations/plugins/google.firestore.json +29 -0
  55. integrations/plugins/google.monitoring.json +24 -0
  56. integrations/plugins/ilert.alert.json +25 -0
  57. integrations/plugins/inwx.registrar.json +16 -0
  58. integrations/plugins/jsdelivr.purge.json +19 -0
  59. integrations/plugins/k8s.cluster.json +163 -0
  60. integrations/plugins/letsencrypt.certs.json +24 -0
  61. integrations/plugins/linear.sync.json +51 -0
  62. integrations/plugins/local.tools.json +290 -0
  63. integrations/plugins/mailbox.smtp.json +29 -0
  64. integrations/plugins/netdata.monitor.json +24 -0
  65. integrations/plugins/npm.publish.json +30 -0
  66. integrations/plugins/openssf.scorecard.json +18 -0
  67. integrations/plugins/osv.audit.json +21 -0
  68. integrations/plugins/pypi.publish.json +30 -0
  69. integrations/plugins/slack.channel-heal.json +56 -0
  70. integrations/plugins/slack.post.json +48 -0
  71. integrations/plugins/sonarcloud.read.json +23 -0
  72. integrations/plugins/sonarcloud.scan.json +28 -0
  73. integrations/plugins/storage.api.json +39 -0
  74. integrations/plugins/tailscale.tailnet.json +37 -0
  75. integrations/plugins/terraform.cloudflare.json +20 -0
  76. integrations/plugins/terraform.desec.json +20 -0
  77. integrations/plugins/terraform.google.json +21 -0
  78. integrations/plugins/terraform.hetzner.json +28 -0
  79. integrations/plugins/terraform.tailscale.json +20 -0
  80. integrations/plugins/uptime-kuma.monitor.json +23 -0
  81. integrations/program-exceptions.json +5 -0
  82. integrations/program_runs.py +139 -0
  83. integrations/registry.py +227 -0
  84. integrations/scan.py +318 -0
  85. integrations/schemas/call-record.schema.json +24 -0
  86. integrations/schemas/consumer.schema.json +94 -0
  87. integrations/schemas/plugin.schema.json +146 -0
  88. integrations/service/__init__.py +2 -0
  89. integrations/service/app.py +245 -0
  90. integrations/service/main.py +42 -0
  91. integrations/service/settings.py +32 -0
  92. integrations/service/spec.py +20 -0
  93. integrations/shim.py +72 -0
  94. integrations/storage_sink.py +276 -0
  95. integrations/testing/__init__.py +15 -0
  96. integrations/testing/github.py +341 -0
  97. integrations/testing/plugin.py +21 -0
  98. integrations/transports.py +1752 -0
  99. pubint-0.20.0.dist-info/METADATA +905 -0
  100. pubint-0.20.0.dist-info/RECORD +104 -0
  101. pubint-0.20.0.dist-info/WHEEL +5 -0
  102. pubint-0.20.0.dist-info/entry_points.txt +6 -0
  103. pubint-0.20.0.dist-info/licenses/LICENSE +202 -0
  104. pubint-0.20.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ """The registry of every outside service our code calls, and the check that
2
+ keeps it true."""
3
+
4
+ import re as _re
5
+ from importlib import metadata as _metadata
6
+ from pathlib import Path as _Path
7
+
8
+
9
+ def _version() -> str:
10
+ """pyproject.toml's version, the one place pubrel sets it: read from the
11
+ file in a source checkout (tests run from src/), else from the installed
12
+ package's metadata."""
13
+ source = _Path(__file__).resolve().parents[2] / "pyproject.toml"
14
+ if source.is_file():
15
+ text = source.read_text(encoding="utf-8")
16
+ if _re.search(r'^name = "pubint"$', text, _re.M):
17
+ return _re.search(r'^version = "([^"]+)"$', text, _re.M)[1]
18
+ return _metadata.version("pubint")
19
+
20
+
21
+ __version__ = _version()
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())
@@ -0,0 +1,268 @@
1
+ """Call records as an Avro file. The same records always give the same bytes, so
2
+ storing or loading a file twice is harmless. A sender's report for the cycle travels in
3
+ the file's metadata, and becomes a row of the status table."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import hashlib
8
+ import io
9
+ import json
10
+ import re
11
+ from datetime import datetime, timezone
12
+
13
+ import fastavro
14
+
15
+ SCHEMA = fastavro.parse_schema({
16
+ "type": "record", "name": "call", "fields": [
17
+ {"name": "at", "type": {"type": "long", "logicalType": "timestamp-micros"}},
18
+ {"name": "repo", "type": "string"},
19
+ {"name": "app", "type": "string"},
20
+ {"name": "plugin", "type": "string"},
21
+ {"name": "operation", "type": "string"},
22
+ {"name": "request_id", "type": "string"},
23
+ {"name": "latency_ms", "type": "long"},
24
+ {"name": "status", "type": ["null", "long"]},
25
+ {"name": "outcome", "type": "string"},
26
+ {"name": "retries", "type": "long"},
27
+ {"name": "bytes_in", "type": "long"},
28
+ {"name": "bytes_out", "type": "long"},
29
+ {"name": "mode", "type": "string"},
30
+ {"name": "route", "type": "string"},
31
+ ]})
32
+
33
+
34
+ _FORMAT = "%Y-%m-%dT%H:%M:%SZ"
35
+ _STATUS_KEY = "integrations.status"
36
+ _TIME = {"type": "long", "logicalType": "timestamp-micros"}
37
+
38
+
39
+ def _optional(name: str, kind: str) -> dict:
40
+ return {"name": name, "type": ["null", kind], "default": None}
41
+
42
+
43
+ STATUS_SCHEMA = fastavro.parse_schema({
44
+ "type": "record", "name": "status", "fields": [
45
+ {"name": "at", "type": _TIME},
46
+ {"name": "kind", "type": "string"},
47
+ {"name": "sender", "type": "string"},
48
+ {"name": "version", "type": "string"},
49
+ {"name": "cycle_start", "type": _TIME},
50
+ {"name": "cycle_end", "type": _TIME},
51
+ *[_optional(name, "long") for name in (
52
+ "calls", "drops", "buffer_size", "storage_failures", "loaded_files", "rejected_now", "inbox_files",
53
+ "inbox_bytes", "inbox_oldest_seconds", "rejected_files", "rejected_oldest_seconds", "jobs_today",
54
+ "status_jobs_today", "page_count", "page_ms_low", "page_ms_median", "page_ms_high")],
55
+ *[_optional(name, "boolean") for name in ("storage_ok", "inbox_more", "rejected_more", "cold_start")],
56
+ _optional("problems", "string"),
57
+ ]})
58
+
59
+
60
+ def timestamp(seconds: float) -> str:
61
+ return datetime.fromtimestamp(seconds, timezone.utc).strftime(_FORMAT)
62
+
63
+
64
+ def _time(text: str) -> datetime:
65
+ return datetime.strptime(text, _FORMAT).replace(tzinfo=timezone.utc)
66
+
67
+
68
+ def _row(record: dict) -> dict:
69
+ return {**record, "at": _time(record["at"])}
70
+
71
+
72
+ def file_name(seconds: float, sender: str, data: bytes) -> str:
73
+ """Where a file goes in a buffer: named for when, who, and what is in it."""
74
+ moment = datetime.fromtimestamp(seconds, timezone.utc)
75
+ who = re.sub(r"[^A-Za-z0-9.-]", "-", sender)
76
+ return (f"inbox/calls/{moment:%Y-%m-%d}/{moment:%H%M%S}-{who}-"
77
+ f"{hashlib.sha256(data).hexdigest()[:16]}.avro")
78
+
79
+
80
+ def encode(records: list[dict], status: dict | None = None) -> bytes:
81
+ out = io.BytesIO()
82
+ marker = hashlib.sha256(repr(sorted(map(repr, records))).encode()).digest()[:16]
83
+ fastavro.writer(out, SCHEMA, [_row(r) for r in records], codec="deflate", sync_marker=marker,
84
+ metadata={"integrations.schema": "call-record",
85
+ **({_STATUS_KEY: json.dumps(status, sort_keys=True)} if status else {})})
86
+ return out.getvalue()
87
+
88
+
89
+ def encode_status(rows: list[dict]) -> bytes:
90
+ out = io.BytesIO()
91
+ marker = hashlib.sha256(repr(sorted(map(repr, rows))).encode()).digest()[:16]
92
+ fastavro.writer(out, STATUS_SCHEMA, [
93
+ {**row, "at": _time(row["at"]), "cycle_start": _time(row["cycle_start"]), "cycle_end": _time(row["cycle_end"])}
94
+ for row in rows], codec="deflate", sync_marker=marker)
95
+ return out.getvalue()
96
+
97
+
98
+ def file_status(data: bytes) -> dict | None:
99
+ """The sender's report in a file, if it has one."""
100
+ text = fastavro.reader(io.BytesIO(data)).metadata.get(_STATUS_KEY)
101
+ return json.loads(text) if text else None
102
+
103
+
104
+ def decode(data: bytes) -> list[dict]:
105
+ rows = []
106
+ for row in fastavro.reader(io.BytesIO(data)):
107
+ rows.append({**row, "at": row["at"].astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")})
108
+ return rows
109
+
110
+
111
+ # Observability's signals, as its evaluator writes them to the signals tenant: the
112
+ # columns of observability.signals, evidence a string BigQuery loads as JSON.
113
+ SIGNAL_SCHEMA = fastavro.parse_schema({
114
+ "type": "record", "name": "signal", "fields": [
115
+ {"name": "rule_id", "type": "string"},
116
+ {"name": "rule_version", "type": "string"},
117
+ {"name": "subject", "type": "string"},
118
+ {"name": "severity", "type": "string"},
119
+ {"name": "started_at", "type": _TIME},
120
+ {"name": "ended_at", "type": ["null", _TIME], "default": None},
121
+ {"name": "evidence", "type": {"type": "string", "sqlType": "JSON"}},
122
+ {"name": "emitted_at", "type": _TIME},
123
+ ]})
124
+
125
+
126
+ def encode_signals(rows: list[dict]) -> bytes:
127
+ """Signals as one file to load; the same signals always give the same bytes."""
128
+ out = io.BytesIO()
129
+ marker = hashlib.sha256(repr(sorted(map(repr, rows))).encode()).digest()[:16]
130
+ fastavro.writer(out, SIGNAL_SCHEMA, rows, codec="deflate", sync_marker=marker)
131
+ return out.getvalue()
132
+
133
+
134
+ def decode_signals(data: bytes) -> list[dict]:
135
+ return list(fastavro.reader(io.BytesIO(data)))
136
+
137
+
138
+ # The convergence engine's facts, as it writes them to the need-states tenant: one row per
139
+ # need per walk, the columns of convergence.need_states, for observability's need_drift rule.
140
+ NEED_STATE_SCHEMA = fastavro.parse_schema({
141
+ "type": "record", "name": "need_state", "fields": [
142
+ {"name": "observed_at", "type": _TIME},
143
+ {"name": "repository", "type": "string"},
144
+ {"name": "unit", "type": "string"},
145
+ {"name": "need", "type": "string"},
146
+ {"name": "type", "type": "string"},
147
+ {"name": "name", "type": "string"},
148
+ {"name": "grade", "type": "string"},
149
+ {"name": "state", "type": "string"},
150
+ {"name": "walked_from", "type": "string"},
151
+ {"name": "walk_started_at", "type": _TIME},
152
+ ]})
153
+
154
+
155
+ def encode_need_states(rows: list[dict]) -> bytes:
156
+ """Need states as one file to load; the same rows always give the same bytes."""
157
+ out = io.BytesIO()
158
+ marker = hashlib.sha256(repr(sorted(map(repr, rows))).encode()).digest()[:16]
159
+ fastavro.writer(out, NEED_STATE_SCHEMA, rows, codec="deflate", sync_marker=marker)
160
+ return out.getvalue()
161
+
162
+
163
+ def decode_need_states(data: bytes) -> list[dict]:
164
+ return list(fastavro.reader(io.BytesIO(data), NEED_STATE_SCHEMA))
165
+
166
+
167
+ # The platform's checks of each repository against pubrules, as release-controlplane's nightly
168
+ # writes them to the pubrules-checks tenant: one row per repository per check per night,
169
+ # passes as well as failures, the columns of platform.pubrules_checks, for observability's
170
+ # pubrules_drift rule and for audits.
171
+ PUBRULES_CHECK_SCHEMA = fastavro.parse_schema({
172
+ "type": "record", "name": "pubrules_check", "fields": [
173
+ {"name": "observed_at", "type": _TIME},
174
+ {"name": "repository", "type": "string"},
175
+ {"name": "check", "type": "string"},
176
+ {"name": "status", "type": "string"},
177
+ {"name": "pinned", "type": "string"},
178
+ {"name": "latest", "type": "string"},
179
+ {"name": "main_commit", "type": "string"},
180
+ {"name": "run_url", "type": "string"},
181
+ {"name": "fix", "type": "string"},
182
+ {"name": "run_started_at", "type": _TIME},
183
+ ]})
184
+
185
+
186
+ def encode_pubrules_checks(rows: list[dict]) -> bytes:
187
+ """pubrules checks as one file to load; the same rows always give the same bytes."""
188
+ out = io.BytesIO()
189
+ marker = hashlib.sha256(repr(sorted(map(repr, rows))).encode()).digest()[:16]
190
+ fastavro.writer(out, PUBRULES_CHECK_SCHEMA, rows, codec="deflate", sync_marker=marker)
191
+ return out.getvalue()
192
+
193
+
194
+ def decode_pubrules_checks(data: bytes) -> list[dict]:
195
+ return list(fastavro.reader(io.BytesIO(data), PUBRULES_CHECK_SCHEMA))
196
+
197
+
198
+ def _nullable(avro_type) -> list:
199
+ return ["null", avro_type]
200
+
201
+
202
+ # CI's finished jobs, as the ci-jobs poller writes them to the ci-usage tenant: one row
203
+ # per GitHub Actions job of each repository on the board, once it has completed, the
204
+ # columns of platform.ci_jobs.
205
+ CI_JOB_SCHEMA = fastavro.parse_schema({
206
+ "type": "record", "name": "ci_job", "fields": [
207
+ {"name": "observed_at", "type": _TIME},
208
+ {"name": "job_id", "type": "long"},
209
+ {"name": "run_id", "type": "long"},
210
+ {"name": "run_attempt", "type": "long"},
211
+ {"name": "repository", "type": "string"},
212
+ {"name": "workflow", "type": "string"},
213
+ {"name": "job_name", "type": "string"},
214
+ {"name": "event", "type": "string"},
215
+ {"name": "head_branch", "type": _nullable("string"), "default": None},
216
+ {"name": "labels", "type": {"type": "array", "items": "string"}},
217
+ {"name": "runner_name", "type": _nullable("string"), "default": None},
218
+ {"name": "runner_group", "type": _nullable("string"), "default": None},
219
+ {"name": "created_at", "type": _TIME},
220
+ {"name": "started_at", "type": _nullable(_TIME), "default": None},
221
+ {"name": "completed_at", "type": _TIME},
222
+ {"name": "wait_seconds", "type": _nullable("long"), "default": None},
223
+ {"name": "run_seconds", "type": _nullable("long"), "default": None},
224
+ {"name": "conclusion", "type": _nullable("string"), "default": None},
225
+ ]})
226
+
227
+ _USAGE_NUMBERS = ("cpu_millicores", "memory_bytes", "cpu_capacity_millicores", "memory_capacity_bytes",
228
+ "cpu_requests_millicores", "memory_requests_bytes", "quota_cpu_used", "quota_cpu_hard",
229
+ "quota_memory_used", "quota_memory_hard", "runners_running", "runners_pending", "runners_max",
230
+ "runner_memory_peak_bytes", "dind_memory_peak_bytes")
231
+
232
+ # The k3s server's usage, as the sampler beside the runners writes it to the ci-usage
233
+ # tenant every two minutes: node, namespace, ci and runner rows, the columns of
234
+ # platform.cluster_usage.
235
+ CLUSTER_USAGE_SCHEMA = fastavro.parse_schema({
236
+ "type": "record", "name": "cluster_usage", "fields": [
237
+ {"name": "observed_at", "type": _TIME},
238
+ {"name": "kind", "type": "string"},
239
+ {"name": "node", "type": _nullable("string"), "default": None},
240
+ {"name": "namespace", "type": _nullable("string"), "default": None},
241
+ {"name": "runner_name", "type": _nullable("string"), "default": None},
242
+ *({"name": name, "type": _nullable("long"), "default": None} for name in _USAGE_NUMBERS),
243
+ ]})
244
+
245
+
246
+ def _encode(schema, rows: list[dict]) -> bytes:
247
+ out = io.BytesIO()
248
+ marker = hashlib.sha256(repr(sorted(map(repr, rows))).encode()).digest()[:16]
249
+ fastavro.writer(out, schema, rows, codec="deflate", sync_marker=marker)
250
+ return out.getvalue()
251
+
252
+
253
+ def encode_ci_jobs(rows: list[dict]) -> bytes:
254
+ """Finished jobs as one file to load; the same rows always give the same bytes."""
255
+ return _encode(CI_JOB_SCHEMA, rows)
256
+
257
+
258
+ def decode_ci_jobs(data: bytes) -> list[dict]:
259
+ return list(fastavro.reader(io.BytesIO(data), CI_JOB_SCHEMA))
260
+
261
+
262
+ def encode_cluster_usage(rows: list[dict]) -> bytes:
263
+ """One sample as one file to load; the same rows always give the same bytes."""
264
+ return _encode(CLUSTER_USAGE_SCHEMA, rows)
265
+
266
+
267
+ def decode_cluster_usage(data: bytes) -> list[dict]:
268
+ return list(fastavro.reader(io.BytesIO(data), CLUSTER_USAGE_SCHEMA))