k9o 1.0.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +38 -0
- data/LICENSE +201 -0
- data/NOTICE +4 -0
- data/README.md +67 -0
- data/k9o.gemspec +41 -0
- data/lib/k9o/ai.rb +28 -0
- data/lib/k9o/audit.rb +29 -0
- data/lib/k9o/barbican.rb +239 -0
- data/lib/k9o/client.rb +59 -0
- data/lib/k9o/compute.rb +67 -0
- data/lib/k9o/data.rb +157 -0
- data/lib/k9o/envelope.rb +64 -0
- data/lib/k9o/functions.rb +51 -0
- data/lib/k9o/gate.rb +64 -0
- data/lib/k9o/http_transport.rb +318 -0
- data/lib/k9o/kerror.rb +52 -0
- data/lib/k9o/kibo.rb +114 -0
- data/lib/k9o/me.rb +160 -0
- data/lib/k9o/migrations.rb +244 -0
- data/lib/k9o/multipart.rb +42 -0
- data/lib/k9o/org.rb +213 -0
- data/lib/k9o/orgs.rb +33 -0
- data/lib/k9o/policies.rb +65 -0
- data/lib/k9o/projects.rb +33 -0
- data/lib/k9o/realtime.rb +80 -0
- data/lib/k9o/region.rb +95 -0
- data/lib/k9o/storage.rb +176 -0
- data/lib/k9o/studio.rb +175 -0
- data/lib/k9o/url_grammar.rb +113 -0
- data/lib/k9o/vault.rb +235 -0
- data/lib/k9o/version.rb +5 -0
- data/lib/k9o.rb +54 -0
- data/sig/k9o/ai.rbs +16 -0
- data/sig/k9o/gate.rbs +11 -0
- data/sig/k9o/migrations.rbs +138 -0
- data/sig/k9o/region.rbs +19 -0
- data/sig/k9o/storage.rbs +41 -0
- metadata +98 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7181cb157e2075ffed56c186db0de091dc3bffb8e87ed498451e3b4dc4629e9f
|
|
4
|
+
data.tar.gz: 41415d026e53bea0e505e702b5fefe58200a26092ae3176c684385bd49bad18d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ea526dce965974039710f5ab14776ac274271793e0ea95ac979d46a51bba7ab5b552e418a0401fc8cf138ddaade8e169f13ca96df9b4bac51a3d491e2a0f7acb
|
|
7
|
+
data.tar.gz: bed73f779902b19472006ad86eac056c8a47f89da96c94675a70f201fdfbdd6dd1e5aaf5a2e15e2a59f0bfb4e4b9024b2b61e078696e8dd144e8e36af305af2e
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog — k9o (Ruby)
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- `client.storage` buckets and objects — flat methods `create_bucket(name, ...)` / `get_bucket` / `list_buckets` / `update_bucket(name, patch)` / `delete_bucket(name, empty: false)` against `/@<slug>/storage/buckets[/<bucket>]` (`?empty=true` sent only when `empty: true`), and `storage.from(bucket)` handles with `upload(path, data, content_type:, upsert:, metadata:)` (a real `multipart/form-data` body built with the stdlib; the transport no longer forces a JSON content type for it), `create_signed_url(path, expires_in:, download:)`, `list(prefix:)` and `remove(path)`. `expires_in` is required, an Integer 1..604800, refused client-side with `K9O_INVALID_FIELD_VALUE` before any request; no default. Bucket and path values are always URL-encoded and never rewritten. No signed-PUT upload URL and no copy (no gateway route). Requires a bound `project_slug`. Adds `K9o::Storage` and `K9o::Multipart`; `HttpTransport.request(multipart:)`.
|
|
6
|
+
- `client.gate.hosted` — `GET /@<slug>/gate/hosted`; returns the envelope `{ 'signInUrl', 'rpId' }` for the project's hosted sign-in page. Unauthenticated: no `Authorization` or `Cookie` header is sent even when `api_key` is configured. An unknown org, a deleted project and a non-Gate project all surface the same 404 `K9O_PROJECT_NOT_FOUND`. Requires a bound `project_slug`. Adds `HttpTransport.request(authenticated: false)`.
|
|
7
|
+
- `client.ai.embed(input:, model: nil)` — `POST /@<slug>/ai/embeddings`; `input` is one string or an array of strings, sent exactly as given; `model` is omitted from the body when not given. Requires a bound `project_slug` (`K9O_MISSING_PROJECT_CONTEXT` otherwise). The input text never appears in an SDK-constructed error. Adds `K9o::Ai`.
|
|
8
|
+
|
|
9
|
+
## v0.1.0 — 2026-05-26 (P3 wave 7 — Ruby idiomatic reshape; FINAL P3 WAVE)
|
|
10
|
+
|
|
11
|
+
**Reshape** of `packages/ruby` from prior OpenAPI-generated `k9o-gate@0.3.0` raw client (214-file output; wrong gem name; not idiomatic) to hand-authored idiomatic `k9o` gem.
|
|
12
|
+
|
|
13
|
+
NEW surfaces:
|
|
14
|
+
|
|
15
|
+
- `K9o.create_client(base_url:, api_key:, org_slug:, project_slug:, ...)` factory + baseUrl validation (keyword arguments per Ruby idiom)
|
|
16
|
+
- `K9o::KError < StandardError` — `.code` / `.message` / `.context` (frozen) / `.recommendation` / `.status` / `.request_id` readers; `#message` overridden to return raw text (avoids infinite recursion with `#to_s` override); `with_recommendation` helper
|
|
17
|
+
- `K9o::Envelope` + `K9o::Meta` with 6 typed sub-accessor classes (`MetaCursor` / `MetaSubscription` Struct / `MetaIdempotency` Struct / `MetaWarning` Struct / `MetaTiming` Struct / `MetaContext` Struct); `from_wire` constructs from gateway JSON
|
|
18
|
+
- `K9o::UrlGrammar.{validate_base_url, validate_slug, project_path, org_path, platform_path}` module functions; raises KError on violation
|
|
19
|
+
- Data-plane DSL `client.from('collection')` chainable filter builder (11 ops: eq / neq / gt / gte / lt / lte / like / ilike / is + `in_(col, [...])` / `not_in` + generic `filter`) + `.limit(n)` / `.cursor(s)` / `.count(mode)` + `.execute` terminal; insert/update/delete with `.eq("id", ...)` discipline
|
|
20
|
+
- `client.projects.{list, create(slug:, name:), get(slug), update(slug, name:)}` (keyword args)
|
|
21
|
+
- `client.gate.{sign_up(email:, password:), sign_in(email:, password:), sign_out(refresh_token:), whoami, refresh_token(refresh_token:), verify_session}` (project-scoped; keyword args)
|
|
22
|
+
- HTTP layer: `Net::HTTP` stdlib; KError rehydration on non-2xx; transport failure → K9O_UPSTREAM_UNAVAILABLE; malformed envelope → K9O_INTERNAL_ERROR; injectable `http_client:` for tests
|
|
23
|
+
|
|
24
|
+
**Tests:** 21 pass / 54 assertions / 0 fail (`ruby test/*.rb` against system Ruby 2.6; gem targets 3.2+ per ch13 spec):
|
|
25
|
+
- 5 KErrorTest (construct + raisable + to_s with status + with_recommendation + from_wire rehydration)
|
|
26
|
+
- 8 UrlGrammarTest (accepts/rejects + path builders)
|
|
27
|
+
- 8 ClientTest (construct + normalise + reject + DSL select/update requirements + projects + gate + collection validation)
|
|
28
|
+
|
|
29
|
+
**Dependencies:** Ruby 3.2+ runtime; stdlib only (`Net::HTTP`, `json`, `uri`).
|
|
30
|
+
**Dev:** minitest 5.20.
|
|
31
|
+
|
|
32
|
+
Dropped Ruby from `openapitools.json` + `package.json` `sdks:generate:ruby` — hand-authored against `services/gateway/openapi.json` contract going forward.
|
|
33
|
+
|
|
34
|
+
**P3 7-wave reshape COMPLETE.** All 7 server SDKs (Python + Go + Rust + Java + .NET + PHP + Ruby) shipped as idiomatic per-language reshapes.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
**Prior history**: `k9o-gate@0.3.0` OpenAPI-generator output retired at this version.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/NOTICE
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# k9o — Kilimanjaro platform SDK (Ruby)
|
|
2
|
+
|
|
3
|
+
Idiomatic Ruby SDK. `snake_case` methods; raise `K9o::KError`; keyword arguments; Net::HTTP stdlib transport.
|
|
4
|
+
|
|
5
|
+
## Status
|
|
6
|
+
|
|
7
|
+
v0.1.0 — first-pass idiomatic ship (P3 wave 7; reshape from prior `k9o-gate@0.3.0` OpenAPI codegen).
|
|
8
|
+
|
|
9
|
+
## Install (when published to RubyGems)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
gem install k9o
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'k9o'
|
|
19
|
+
|
|
20
|
+
k9o = K9o.create_client(
|
|
21
|
+
base_url: "https://acme.api.k9o.io",
|
|
22
|
+
api_key: ENV["K9O_API_KEY"],
|
|
23
|
+
org_slug: "acme",
|
|
24
|
+
project_slug: "member-portal"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
begin
|
|
28
|
+
response = k9o.from("posts").select.limit(10).execute
|
|
29
|
+
response.data.each { |row| puts row }
|
|
30
|
+
puts "next cursor: #{response.meta.cursor&.next}"
|
|
31
|
+
|
|
32
|
+
session = k9o.gate.sign_in(email: "u@x.com", password: "...")
|
|
33
|
+
puts "signed in: #{session.data['user']['id']}"
|
|
34
|
+
rescue K9o::KError => e
|
|
35
|
+
warn "[#{e.code}] #{e.message}: #{e.recommendation}"
|
|
36
|
+
raise
|
|
37
|
+
end
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Idiomatic shape (per ch13)
|
|
41
|
+
|
|
42
|
+
| Aspect | This SDK |
|
|
43
|
+
|---|---|
|
|
44
|
+
| Gem name | `k9o` (RubyGems) |
|
|
45
|
+
| Module | `K9o` |
|
|
46
|
+
| Method casing | `snake_case` |
|
|
47
|
+
| Error delivery | `raise K9o::KError < StandardError` |
|
|
48
|
+
| Factory pattern | `K9o.create_client(base_url:, api_key:, org_slug:, project_slug:)` (keyword args) |
|
|
49
|
+
| Data DSL entry | `client.from('collection')` |
|
|
50
|
+
| Filter chain | `.eq(col, val)` / `.gt()` / `.in_(col, [...])` / `.is(col, val)` / `.filter(col, op, val)` |
|
|
51
|
+
| Terminal verb | `.execute` (parameterless method chain — Ruby idiom) |
|
|
52
|
+
| Meta accessor | `response.meta.cursor&.next` (safe-navigation `&.`); `.meta.timing&.total_ms`; `.meta.context&.request_id` |
|
|
53
|
+
| Wire format | Always camelCase JSON; explicit field-name translation in `Envelope.from_wire` |
|
|
54
|
+
| Runtime | Ruby 3.2+ (per ch13 §2.1.8 spec) |
|
|
55
|
+
| HTTP library | `Net::HTTP` (stdlib; no external deps) |
|
|
56
|
+
|
|
57
|
+
## Architectural notes
|
|
58
|
+
|
|
59
|
+
- **Stdlib only**: uses `Net::HTTP` + `json` + `uri`; no Typhoeus or Faraday.
|
|
60
|
+
- **Keyword arguments throughout**: `K9o.create_client(base_url:, api_key:, ...)` and `k9o.gate.sign_in(email:, password:)` per Ruby 3.x idiom.
|
|
61
|
+
- **`&.` safe navigation**: caller pattern `response.meta.cursor&.next` (cursor may be nil if gateway omits the sub-namespace).
|
|
62
|
+
- **`message` override**: `K9o::KError#message` returns the raw text directly to avoid infinite recursion with `to_s` override (Ruby's `Exception#message` calls `to_s` by default).
|
|
63
|
+
- **`.execute` method**: no parens for terminal verb per Ruby convention; chain reads naturally.
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
UNLICENSED — internal to Kilimanjaro.
|
data/k9o.gemspec
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/k9o/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'k9o'
|
|
7
|
+
spec.version = K9o::VERSION
|
|
8
|
+
spec.authors = ['Kilimanjaro']
|
|
9
|
+
spec.email = ['engineering@kilimanjaro.dev']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Kilimanjaro platform SDK for Ruby'
|
|
12
|
+
spec.description = 'Idiomatic Ruby SDK — create_client + data DSL + projects + KError. snake_case + raise K9o::KError.'
|
|
13
|
+
spec.homepage = 'https://kilimanjaro.dev'
|
|
14
|
+
spec.license = 'Apache-2.0'
|
|
15
|
+
|
|
16
|
+
spec.required_ruby_version = '>= 3.2.0'
|
|
17
|
+
|
|
18
|
+
# Platform gems: the publish pipeline sets K9O_GEM_PLATFORM (e.g. arm64-darwin,
|
|
19
|
+
# x86_64-linux) when building a gem that bundles the kibo ZK native lib for that
|
|
20
|
+
# platform. Unset → the pure-Ruby gem (the universal fallback; `k9o.kibo` is
|
|
21
|
+
# simply unavailable where no platform gem matches).
|
|
22
|
+
if (gem_plat = ENV['K9O_GEM_PLATFORM']) && !gem_plat.empty?
|
|
23
|
+
spec.platform = gem_plat
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
spec.metadata = {
|
|
27
|
+
'homepage_uri' => 'https://kilimanjaro.dev',
|
|
28
|
+
'source_code_uri' => 'https://github.com/k9o-dev/sdk-ruby',
|
|
29
|
+
'changelog_uri' => 'https://github.com/k9o-dev/sdk-ruby/blob/main/CHANGELOG.md'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Ruby sources + the CI-injected kibo native lib (one per platform gem; the
|
|
33
|
+
# generated uniffi binding under lib/k9o/_ffi/ is picked up by the .rb glob).
|
|
34
|
+
spec.files = Dir.glob('lib/**/*.rb') +
|
|
35
|
+
Dir.glob('lib/k9o/_ffi/*.{dylib,so,bundle,dll}') +
|
|
36
|
+
Dir.glob('sig/**/*.rbs') +
|
|
37
|
+
%w[README.md CHANGELOG.md LICENSE NOTICE k9o.gemspec]
|
|
38
|
+
spec.require_paths = ['lib']
|
|
39
|
+
|
|
40
|
+
spec.add_development_dependency 'minitest', '~> 5.20'
|
|
41
|
+
end
|
data/lib/k9o/ai.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module K9o
|
|
4
|
+
# AI namespace — platform AI primitives.
|
|
5
|
+
# k9o.ai.embed(...)
|
|
6
|
+
#
|
|
7
|
+
# Wire (project-plane):
|
|
8
|
+
# POST /@<slug>/ai/embeddings body { model?, input: String | [String] }
|
|
9
|
+
# -> { data: { embeddings: [[Float]], model:, dimensions: }, meta }
|
|
10
|
+
#
|
|
11
|
+
# Bounds are enforced by the gateway, not here. The SDK sends `input`
|
|
12
|
+
# exactly as given and never puts it in an error.
|
|
13
|
+
class Ai
|
|
14
|
+
def initialize(config)
|
|
15
|
+
@config = config
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# POST /@<slug>/ai/embeddings — embed one string or an array of strings.
|
|
19
|
+
# `model` is omitted from the body when nil (server default).
|
|
20
|
+
def embed(input:, model: nil)
|
|
21
|
+
slug = Studio.require_project_slug(@config, 'ai')
|
|
22
|
+
body = { 'input' => input }
|
|
23
|
+
body['model'] = model unless model.nil?
|
|
24
|
+
HttpTransport.request(config: @config, method: 'POST',
|
|
25
|
+
path: UrlGrammar.project_path(slug, 'ai/embeddings'), body: body)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/lib/k9o/audit.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module K9o
|
|
4
|
+
# Project-plane audit log namespace — k9o.audit.*.
|
|
5
|
+
# Distinct from k9o.org.audit_log + k9o.me.audit_log.
|
|
6
|
+
class Audit
|
|
7
|
+
def initialize(config)
|
|
8
|
+
@config = config
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Query the audit log (reverse-chronological; filters AND-compose).
|
|
12
|
+
# Accepts keyword filters: since/until/type/actor_id/target_kind/
|
|
13
|
+
# target_id/limit/cursor (wire camelCase mapping applied here).
|
|
14
|
+
def query(since: nil, until_: nil, type: nil, actor_id: nil,
|
|
15
|
+
target_kind: nil, target_id: nil, limit: nil, cursor: nil)
|
|
16
|
+
slug = Studio.require_project_slug(@config, 'audit')
|
|
17
|
+
q = {}
|
|
18
|
+
q['since'] = since if since
|
|
19
|
+
q['until'] = until_ if until_
|
|
20
|
+
q['type'] = type if type
|
|
21
|
+
q['actorId'] = actor_id if actor_id
|
|
22
|
+
q['targetKind'] = target_kind if target_kind
|
|
23
|
+
q['targetId'] = target_id if target_id
|
|
24
|
+
q['limit'] = limit if limit
|
|
25
|
+
q['cursor'] = cursor if cursor
|
|
26
|
+
HttpTransport.request(config: @config, method: 'GET', path: UrlGrammar.project_path(slug, 'audit-log'), query: q)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/k9o/barbican.rb
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'kerror'
|
|
4
|
+
|
|
5
|
+
module K9o
|
|
6
|
+
# Barbican — free, embeddable L2 guardrail. Input normalization -> Aho-Corasick
|
|
7
|
+
# deny-list matching over a signed ruleset -> local verdict, plus a streaming
|
|
8
|
+
# output redactor (buffer-and-scan-before-flush).
|
|
9
|
+
#
|
|
10
|
+
# Thin wrapper over the bound core (`k9o-keep-core`, via uniffi) — mirrors the
|
|
11
|
+
# structural pattern of +K9o::Kibo+ (native-load guard evaluated once at
|
|
12
|
+
# require time; every call forwards typed arguments to the generated binding
|
|
13
|
+
# and maps its error -> +K9o::KError+). ZERO guardrail logic lives here: every
|
|
14
|
+
# normalization pass, deny match, verdict, and redaction decision is the
|
|
15
|
+
# audited native core's.
|
|
16
|
+
#
|
|
17
|
+
# CLAIM BOUNDARY: Barbican is advisory / defense-in-depth (edge filtration).
|
|
18
|
+
# It is never the enforced sandbox boundary.
|
|
19
|
+
#
|
|
20
|
+
# The generated uniffi binding + native lib (+lib/k9o/_ffi/+) are build
|
|
21
|
+
# artifacts (CI-injected per platform; gitignored) — on a platform/Ruby
|
|
22
|
+
# without them, +require+ still succeeds and +Barbican.new+ raises a clear
|
|
23
|
+
# +K9o::KError+, so loading +k9o+ never breaks for the rest of the SDK.
|
|
24
|
+
class Barbican
|
|
25
|
+
# Attempt to load the native binding; never raises at require time.
|
|
26
|
+
NATIVE_AVAILABLE =
|
|
27
|
+
begin
|
|
28
|
+
require_relative '_ffi/k9o_keep_core_ffi_uniffi'
|
|
29
|
+
true
|
|
30
|
+
rescue LoadError
|
|
31
|
+
false
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# +decode_depth+ of 0 uses the core default (3) — a bounded base64/leetspeak
|
|
35
|
+
# de-obfuscation depth (decode-bomb guard).
|
|
36
|
+
def initialize(fail_open: false, leet: true, decode_depth: 0)
|
|
37
|
+
self.class.ensure_native!
|
|
38
|
+
config = K9oKeepCoreFfiUniffi::KeepConfig.new(
|
|
39
|
+
fail_open: fail_open, leet: leet, decode_depth: decode_depth
|
|
40
|
+
)
|
|
41
|
+
@core = K9oKeepCoreFfiUniffi::KeepCore.new(config)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Load a static ruleset bundled with your gem (Mode-A path: provenance is
|
|
45
|
+
# vouched for by your package, so signature verification is skipped — the
|
|
46
|
+
# core still enforces anti-rollback, never loading a version <= the current
|
|
47
|
+
# one). +rules+ = an array of {id:, pattern:, severity:} (severity one of
|
|
48
|
+
# low|medium|high|critical; string or symbol keys both accepted). Returns
|
|
49
|
+
# the accepted version.
|
|
50
|
+
def load_ruleset(ruleset_version, rules)
|
|
51
|
+
blob = K9oKeepCoreFfiUniffi::KeepRulesetBlob.new(
|
|
52
|
+
ruleset_version: ruleset_version,
|
|
53
|
+
rules: rules.map { |r| build_rule(r) }
|
|
54
|
+
)
|
|
55
|
+
begin
|
|
56
|
+
@core.load_ruleset_unsigned(blob)
|
|
57
|
+
rescue StandardError => e
|
|
58
|
+
raise self.class.to_kerror(e)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Load a Barbican key manifest (compact JWS, +typ k9o.barbican.keys.v1+). The
|
|
63
|
+
# core checks it against the root key compiled into it and, only if it
|
|
64
|
+
# verifies, REPLACES the trusted ruleset-signing keys with the ones it lists.
|
|
65
|
+
# A refusal (wrong signer, rollback, a key changing its public key, a
|
|
66
|
+
# malformed entry) raises +K9O_BARBICAN_RULESET_INVALID+ with
|
|
67
|
+
# +context[:stage] == 'key_manifest'+ and leaves the trusted keys unchanged.
|
|
68
|
+
# Returns the manifest +sequence+.
|
|
69
|
+
def load_key_manifest(jws, now_secs = nil)
|
|
70
|
+
@core.load_key_manifest(jws, now_secs || Time.now.to_i)
|
|
71
|
+
rescue StandardError => e
|
|
72
|
+
raise self.class.to_kerror(e, 'key_manifest')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Verify a ruleset manifest (compact JWS) under a trusted key and return its
|
|
76
|
+
# authenticated fields (+ruleset_version+ / +signing_key_kid+ /
|
|
77
|
+
# +artifact_hash+ / +artifact_url+ / +valid_until+).
|
|
78
|
+
def verify_manifest(jws)
|
|
79
|
+
@core.verify_manifest(jws)
|
|
80
|
+
rescue StandardError => e
|
|
81
|
+
raise self.class.to_kerror(e)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Load a signed ruleset. The core verifies the Ed25519 signature ITSELF, over
|
|
85
|
+
# its own canonical bytes, under a key from the loaded key manifest: there is
|
|
86
|
+
# no key or verifier to pass. Any failure (no key manifest loaded, unknown
|
|
87
|
+
# key, bad or non-canonical signature, stale version, malformed rules) raises
|
|
88
|
+
# +K9O_BARBICAN_RULESET_INVALID+ with +context[:reason]+ and leaves the
|
|
89
|
+
# current ruleset running. +signature+ is the raw 64-byte binary String.
|
|
90
|
+
# Returns the accepted version.
|
|
91
|
+
def load_ruleset_signed(ruleset_version, rules, signing_key_kid, signature, created_at = 0)
|
|
92
|
+
@core.load_ruleset_signed(signed_blob(ruleset_version, rules, signing_key_kid, signature, created_at))
|
|
93
|
+
rescue StandardError => e
|
|
94
|
+
raise self.class.to_kerror(e)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Lowercase hex SHA-256 of a ruleset's canonical signing bytes — the value a
|
|
98
|
+
# manifest's +artifact_hash+ names. A digest only; it decides no trust.
|
|
99
|
+
def ruleset_digest(ruleset_version, rules, signing_key_kid, signature, created_at = 0)
|
|
100
|
+
@core.ruleset_digest(signed_blob(ruleset_version, rules, signing_key_kid, signature, created_at))
|
|
101
|
+
rescue StandardError => e
|
|
102
|
+
raise self.class.to_kerror(e)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# The +sequence+ of the key manifest in force (0 before one is loaded).
|
|
106
|
+
def key_manifest_sequence
|
|
107
|
+
@core.key_manifest_sequence
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# The highest VERIFIED ruleset version loaded (0 = none): the anti-rollback floor for signed updates. A refresh
|
|
111
|
+
# compares a published version against this, not the version in force.
|
|
112
|
+
def signed_floor
|
|
113
|
+
@core.signed_floor
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Whether the ruleset in force came from a verified load. +false+ when none is loaded, or when +load_ruleset+
|
|
117
|
+
# (unsigned, host-vouched) replaced a verified one.
|
|
118
|
+
def active_ruleset_is_signed?
|
|
119
|
+
@core.active_ruleset_is_signed
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# The signing kids the loaded key manifest currently trusts, sorted.
|
|
123
|
+
def trusted_kids
|
|
124
|
+
@core.trusted_kids
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# The trusted kids the key manifest flags deprecated, sorted.
|
|
128
|
+
def deprecated_kids
|
|
129
|
+
@core.deprecated_kids
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# +false+ on every shipped build. +true+ means this binding trusts the
|
|
133
|
+
# PUBLISHED TEST root and must never be used outside tests.
|
|
134
|
+
def self.uses_test_trust_root?
|
|
135
|
+
ensure_native!
|
|
136
|
+
K9oKeepCoreFfiUniffi.uses_test_trust_root
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Inspect an input (normalize -> deny -> local verdict). Obfuscation is
|
|
140
|
+
# peeled BEFORE matching, so static deny-lists aren't defeated by trivial
|
|
141
|
+
# tricks. +waypoint_class+ is the manifest's meter hint — it NEVER gates the
|
|
142
|
+
# decision. Returns the verdict object (+decision+ / +reason+ / +matched+ /
|
|
143
|
+
# +schema_valid+ / +waypoint_class_hint+ / +fail_mode+ / +ruleset_version+ /
|
|
144
|
+
# +core_version+).
|
|
145
|
+
def inspect(text, waypoint_class: nil)
|
|
146
|
+
@core.inspect_input(text, waypoint_class)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Local L3 stand-in classification ("clear"|"suspicious"|"malicious"). No
|
|
150
|
+
# receipt — a classification is not an enforcement decision.
|
|
151
|
+
def classify(text)
|
|
152
|
+
@core.classify_local(text)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Open an output stream-filter bound to the active ruleset's exfil markers.
|
|
156
|
+
def create_output_filter
|
|
157
|
+
OutputFilter.new(@core.output_filter)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# The bound core's semver (audit anchor; rides every verdict too).
|
|
161
|
+
def core_version
|
|
162
|
+
@core.core_version
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Guard: raise a clear KError if the native lib is absent (evaluated BEFORE
|
|
166
|
+
# any reference to the +K9oKeepCoreFfiUniffi+ namespace, which may be
|
|
167
|
+
# undefined).
|
|
168
|
+
def self.ensure_native!
|
|
169
|
+
return if NATIVE_AVAILABLE
|
|
170
|
+
|
|
171
|
+
raise K9o::KError.new(
|
|
172
|
+
code: 'K9O_BARBICAN_WASM_ERROR',
|
|
173
|
+
message: 'barbican native library not available for this platform/Ruby; install the platform-specific k9o gem.'
|
|
174
|
+
)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Map the bound core's error -> +K9o::KError+. +KeepError::RulesetInvalid+
|
|
178
|
+
# is the only typed variant (bad/stale/malformed ruleset) — its reason token
|
|
179
|
+
# (+version_stale+ / +signature_invalid+ / +malformed+ / an unknown-severity
|
|
180
|
+
# message) rides in +context[:reason]+. Anything else from the native layer
|
|
181
|
+
# (e.g. a Rust panic surfaced as +InternalError+) maps to the generic code.
|
|
182
|
+
def self.to_kerror(e, stage = 'ruleset')
|
|
183
|
+
if e.respond_to?(:reason)
|
|
184
|
+
K9o::KError.new(
|
|
185
|
+
code: 'K9O_BARBICAN_RULESET_INVALID',
|
|
186
|
+
message: e.to_s,
|
|
187
|
+
context: { reason: e.reason, stage: stage }
|
|
188
|
+
)
|
|
189
|
+
else
|
|
190
|
+
K9o::KError.new(code: 'K9O_BARBICAN_WASM_ERROR', message: e.to_s)
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Accept string or symbol keys ({"id" => ..} or {id: ..}) for ergonomics.
|
|
195
|
+
def build_rule(r)
|
|
196
|
+
K9oKeepCoreFfiUniffi::KeepRule.new(
|
|
197
|
+
id: r[:id] || r['id'],
|
|
198
|
+
pattern: r[:pattern] || r['pattern'],
|
|
199
|
+
severity: r[:severity] || r['severity']
|
|
200
|
+
)
|
|
201
|
+
end
|
|
202
|
+
private :build_rule
|
|
203
|
+
|
|
204
|
+
def signed_blob(ruleset_version, rules, signing_key_kid, signature, created_at)
|
|
205
|
+
K9oKeepCoreFfiUniffi::KeepSignedRulesetBlob.new(
|
|
206
|
+
ruleset_version: ruleset_version,
|
|
207
|
+
rules: rules.map { |r| build_rule(r) },
|
|
208
|
+
signing_key_kid: signing_key_kid,
|
|
209
|
+
signature: signature.b,
|
|
210
|
+
created_at: created_at
|
|
211
|
+
)
|
|
212
|
+
end
|
|
213
|
+
private :signed_blob
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# A streaming output redactor. Buffer-and-scan-before-flush: never emits a
|
|
217
|
+
# byte the core has not cleared (no RST-after-leak).
|
|
218
|
+
class OutputFilter
|
|
219
|
+
def initialize(handle)
|
|
220
|
+
@handle = handle
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# Feed a chunk; returns the cleared (redacted) prefix safe to emit now.
|
|
224
|
+
def push(chunk)
|
|
225
|
+
@handle.push(chunk)
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# Flush the residual buffer (also scanned) at end of stream.
|
|
229
|
+
def finish
|
|
230
|
+
@handle.finish
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# Leak report (counts only — never the leaked values): an object with
|
|
234
|
+
# +emails+ / +secrets+ / +markers+ / +total+.
|
|
235
|
+
def report
|
|
236
|
+
@handle.report
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
end
|