Skip to content

feat: Add the Ruby SDK - #1

Merged
nderjung merged 30 commits into
prod-stagingfrom
nderjung/feat/init
Nov 25, 2026
Merged

nderjung merged 30 commits into
prod-stagingfrom
nderjung/feat/init

Conversation

@nderjung

@nderjung nderjung commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Adds the official Ruby SDK for Unikraft Cloud, unikraft-cloud. It is a port of the JS SDK with the same two layers:

  • Plumbing: generated from the OpenAPI specs with openapi-gen. One class per resource, methods named after their operationId, and the raw response envelope is returned.
  • Porcelain: a hand-written, Ruby-style client covering instances, volumes, services, certificates and users. It fans out across metros, pages automatically, and returns handles you can chain.
Unikraft::Cloud.open do |ukc|
  ukc.metro(:fra).instances
     .create(image: "nginx:latest", autostart: true)
     .wait(state: :running, within: 30)
end

The SDK has no runtime dependencies beyond Ruby's standard library. It needs Ruby 3.3 or later. Connections are reused, and a request is never retried.

CI runs lint and tests on Ruby 3.3, 3.4 and 4.0. Releases go to RubyGems through trusted publishing, versioned from the commit history like the JS SDK.

Sandboxes follow in a stacked PR. The end-to-end tests (rake test:e2e) have not been run against a live account yet.

Run the shared actionlint action on pull requests that change a
workflow, as the other SDK repositories do.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Run the shared commit and title checks, RuboCop on one Ruby, the unit
tests on Ruby 3.3, 3.4 and 4.0, and build and load the packaged gem on
the oldest and the newest supported Ruby.

Signed-off-by: Alexander Jung <alex@unikraft.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical active finding shows that configured tokens are sent as the literal masked value, causing real requests to be unauthenticated and overriding per-call Authorization headers.

1 open issue
What changed in this PR

Adds the initial unikraft-cloud Ruby SDK for Unikraft Cloud, including generated OpenAPI clients, Ruby-style resource APIs, sandbox support, testing, packaging, and CI/release automation.

Changes:

  • Adds generated Platform and Control Plane API clients and models.
  • Adds resource handles for instances, volumes, services, certificates, users, and sandboxes.
  • Adds HTTP transport, pooling, metro fan-out, pagination, readiness polling, patching, examples, tests, and workflows.
  • Review follow-ups include correcting bearer-token transmission, cleaning up fan-out workers on errors, validating positional references, propagating sandbox timeouts, and reconciling stale-connection retries with the documented no-retry behavior.
File Description
unikraft-cloud.gemspec Defines gem metadata and dependencies.
test/​unit/​volumes_test.rb Tests volume operations.
test/​unit/​version_test.rb Tests version formatting.
test/​unit/​users_test.rb Tests user and quota behavior.
test/​unit/​session_test.rb Tests session reuse and discovery.
test/​unit/​service_groups_test.rb Tests service-group operations.
test/​unit/​ref_test.rb Tests resource references.
test/​unit/​ready_test.rb Tests readiness polling.
test/​unit/​pool_test.rb Tests connection pooling.
test/​unit/​plugin_transport_test.rb Tests sandbox plugin transport compatibility.
test/​unit/​patch_test.rb Tests patch construction and editing.
test/​unit/​model_test.rb Tests model conversion and serialization.
test/​unit/​fanout_test.rb Tests concurrent fan-out and pagination.
test/​unit/​errors_test.rb Tests SDK error behavior.
test/​unit/​client_test.rb Tests client construction and scoping.
test/​unit/​certificates_test.rb Tests certificate operations.
test/​unit/​base64_test.rb Tests Base64 helpers.
test/​unit/​api_test.rb Tests generated API behavior.
test/​test_helper.rb Configures the unit test environment.
test/​support/​fake_server.rb Provides an HTTP server test double.
test/​support/​fake_cloud.rb Provides an in-memory cloud test double.
test/​e2e/​sandbox_test.rb Adds sandbox end-to-end coverage.
test/​e2e/​live_test.rb Adds live platform end-to-end coverage.
templates/​resources.rb.tmpl Generates Ruby resource clients.
templates/​models.rb.tmpl Generates Ruby models and enums.
Rakefile Defines test, lint, build, and packaging tasks.
Makefile Provides generation and build commands.
LICENSE.md Adds the project license.
lib/​unikraft/​cloud/​version.rb Defines the SDK version.
lib/​unikraft/​cloud/​resources/​volumes.rb Implements volume resource operations.
lib/​unikraft/​cloud/​resources/​users.rb Implements user and quota operations.
lib/​unikraft/​cloud/​resources/​service_groups.rb Implements service-group operations.
lib/​unikraft/​cloud/​resources/​sandboxes/​files.rb Implements sandbox filesystem operations.
lib/​unikraft/​cloud/​resources/​sandboxes/​command.rb Implements sandbox command operations.
lib/​unikraft/​cloud/​resources/​instances.rb Implements instance lifecycle operations.
lib/​unikraft/​cloud/​resources/​certificates.rb Implements certificate operations.
lib/​unikraft/​cloud/​model.rb Provides shared model behavior.
lib/​unikraft/​cloud/​core/​url.rb Provides URL normalization and escaping.
lib/​unikraft/​cloud/​core/​session.rb Shares transports and discovery state.
lib/​unikraft/​cloud/​core/​response.rb Unwraps API response envelopes.
lib/​unikraft/​cloud/​core/​ref.rb Represents resource references.
lib/​unikraft/​cloud/​core/​ready.rb Implements readiness polling.
lib/​unikraft/​cloud/​core/​pool.rb Manages reusable HTTP connections.
lib/​unikraft/​cloud/​core/​patch.rb Implements staged resource patches.
lib/​unikraft/​cloud/​core/​pagination.rb Implements cursor pagination.
lib/​unikraft/​cloud/​core/​metro.rb Normalizes metros and endpoints.
lib/​unikraft/​cloud/​core/​handle.rb Implements lazy resource handles.
lib/​unikraft/​cloud/​core/​handle_set.rb Implements multi-resource handles.
lib/​unikraft/​cloud/​core/​fanout.rb Implements concurrent metro operations.
lib/​unikraft/​cloud/​core/​errors.rb Defines SDK and fan-out errors.
lib/​unikraft/​cloud/​core/​base64.rb Provides strict Base64 helpers.
lib/​unikraft/​cloud/​client.rb Implements the public client and scopes.
lib/​unikraft/​cloud/​api/​platform/​users.gen.rb Generated Platform user operations.
lib/​unikraft/​cloud/​api/​platform/​services.gen.rb Generated Platform service operations.
lib/​unikraft/​cloud/​api/​platform/​resources.gen.rb Loads generated Platform resources.
lib/​unikraft/​cloud/​api/​platform/​node.gen.rb Generated Platform node operations.
lib/​unikraft/​cloud/​api/​platform/​images.gen.rb Generated Platform image operations.
lib/​unikraft/​cloud/​api/​platform/​certificates.gen.rb Generated Platform certificate operations.
lib/​unikraft/​cloud/​api/​platform/​autoscale.gen.rb Generated autoscaling operations.
lib/​unikraft/​cloud/​api/​platform/​audit.gen.rb Generated audit operations.
lib/​unikraft/​cloud/​api/​platform.rb Configures the Platform API.
lib/​unikraft/​cloud/​api/​controlplane/​resources.gen.rb Loads generated Control Plane resources.
lib/​unikraft/​cloud/​api/​controlplane/​node_activation_service.gen.rb Generated node activation operations.
lib/​unikraft/​cloud/​api/​controlplane/​metros.gen.rb Generated metro discovery operations.
lib/​unikraft/​cloud/​api/​controlplane/​images.gen.rb Generated Control Plane image operations.
lib/​unikraft/​cloud/​api/​controlplane/​auth.gen.rb Generated authentication operations.
lib/​unikraft/​cloud/​api/​controlplane.rb Configures the Control Plane API.
lib/​unikraft/​cloud/​api.rb Exposes the raw API surfaces.
lib/​unikraft/​cloud.rb Loads and exposes the SDK.
Gemfile.lock Locks project dependencies.
Gemfile Declares development dependencies.
examples/​update.rb Demonstrates resource updates.
examples/​sandbox.rb Demonstrates sandbox workflows.
examples/​quickstart.rb Demonstrates basic SDK usage.
examples/​plumbing.rb Demonstrates raw API usage.
.rubocop.yml Configures Ruby linting.
.gitignore Defines repository ignore rules.
.github/​workflows/​sync.yaml Regenerates API clients from OpenAPI specifications.
.github/​workflows/​release.yaml Builds and publishes releases.
.github/​workflows/​promote.yaml Handles staging promotion automation.
.github/​workflows/​check-pr.yaml Runs lint, tests, and package checks.
.github/​workflows/​actionlint.yaml Validates workflow files.
.editorconfig Defines repository formatting rules.

Review effort: Lite

Comment thread lib/unikraft/cloud/core/http.rb Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two critical defects remain: authentication sends a redacted placeholder instead of the caller’s bearer token, and resource searches can return an incomplete match without reporting failures from other metros.

2 open issues

Review effort: Lite

Comment thread lib/unikraft/cloud/core/resource.rb Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical, moderate, and documentation issues include producer-thread leaks on exceptions and failure results being returned as successful handles, so corrective changes are still needed.

4 open issues
2 resolved since last review

Review effort: Lite

Comment thread lib/unikraft/cloud/core/fanout.rb Resolved
Comment thread lib/unikraft/cloud/core/response.rb Resolved
Comment thread lib/unikraft/cloud/core/resource.rb Resolved
Comment thread lib/unikraft/cloud/core/http.rb Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical lookup bug can misclassify not-found resources as present and create false ambiguity, while handle operations silently discard invalid call options instead of validating them.

2 open issues
4 resolved since last review

Review effort: Lite

Comment thread lib/unikraft/cloud/core/resource.rb Resolved
Comment thread lib/unikraft/cloud/core/resource.rb Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Approval is blocked by three active critical issues: an unverified mutable release-tool download with publish permissions and inspection paths that can expose credentials and other secrets.

3 open issues
2 resolved since last review

Review effort: Lite

Comment thread .github/workflows/release.yaml Resolved
Comment thread lib/unikraft/cloud/core/handle.rb Resolved
Comment thread lib/unikraft/cloud/model.rb Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Approval is blocked by three unresolved critical issues: unpinned code generation, masked network failures, and incomplete recursive redaction of nested secrets.

3 open issues
3 resolved since last review

Review effort: Lite

Comment thread Makefile Resolved
Comment thread lib/unikraft/cloud/core/http.rb Resolved
Comment thread lib/unikraft/cloud/model.rb Resolved
@nderjung
nderjung force-pushed the nderjung/feat/init branch 2 times, most recently from 3cee9c6 to cc7ed4d Compare November 24, 2026 22:52
@nderjung
nderjung requested an adaptive review from Copilot November 24, 2026 22:55
Serve each connection on its own thread and keep it open across
requests, count accepted connections, and let a canned response close
the connection, drop it unanswered, or arrive late. The transport tests
need this to observe connection reuse.

Signed-off-by: Alexander Jung <alex@unikraft.com>
ApiClient opened a new connection for every call. Keep finished
connections in a per-client pool keyed by scheme, host, port and proxy,
checked out by one thread at a time, at most 8 idle per key and for at
most 5 seconds. Streams and bytes use it too. A connection that saw an
error, answered Connection: close, or carried a stream left early is
closed instead of returned. ApiClient#close closes the idle ones, and a
forked child drops the connections it inherited without closing them.

A reused connection the server closed while idle fails before any
response arrives; only then, and only for an idempotent method, is the
request sent once more on a fresh connection. POST and PATCH are never
resent. Net::HTTP's own resend of idempotent requests, which also fired
on timeouts, is now off.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Core::Metro turns metro codes, URLs and scopes (Symbols or Strings,
:all) into Endpoints; KNOWN_METROS, DEFAULT_METRO and the control
plane URL live on Unikraft::Cloud. Core::Ref is a Data value holding
a name or a uuid, never both, optionally qualified with a metro that
never reaches the wire. Core::Response unwraps the envelope, reading
a per-entry failure out of a 200 error envelope as the JS SDK does.
Models gain deconstruct_keys, so results pattern-match with metro.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Core::Fanout runs per-metro work on threads. merge pushes items onto
a yielder in arrival order through a SizedQueue of about one item per
metro, so each metro fetches its next page only as the consumer uses
up the last. It drains every healthy metro before raising one
MetroFanoutError, and kills the metros still in flight when the
consumer leaves early. Every producer reports from ensure, so the
consumer never waits on a dead thread. all and settled run one call
per metro and keep the successes on the error as results. Only a
Unikraft::Cloud::Error is a metro failure; anything else, a bug or
an interrupt, is re-raised to the caller.
Core::Pagination follows the count/from cursor of the list endpoints.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Core::Session holds one client's credentials, the transports it
built (one per base URL) and the metro discovery, asked of the control
plane once and shared across threads; a failed discovery is not
cached. It turns a scope into endpoints, picks the one endpoint of a
create (the default metro under a wider scope, and a :config error
when a scope of named metros leaves the default out), and never
discovers or invents hostnames when a URL was named. close closes
every transport it built. The transport builder is injectable, which
test/support/fake_cloud.rb uses to route calls.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Core::Patch turns keyword arguments into the API's prop/op/value
triples: a value sets the property, nil removes it (JSON Merge
Patch), an omitted one is untouched, and raw triples still pass
through. Patch::Editor stages set, add and remove (the API's del) and
applies them as one request, chained or from a block.

Signed-off-by: Alexander Jung <alex@unikraft.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved issues can reject valid same-deployment volume operations, resolve multi-metro handles using incorrect authentication options, and leave billable instances running after a create response failure.

3 open issues
6 resolved since last review

Review effort: Balanced (adaptive)

Comment thread lib/unikraft/cloud/core/handle.rb Resolved
Comment thread lib/unikraft/cloud/resources/volumes.rb Resolved
Comment thread test/e2e/live_test.rb Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical gaps in propagating headers and timeouts can cause lookups, mutations, and reloads to use different credentials, risking cross-account operations and mixed account data.

3 open issues
3 resolved since last review

Review effort: Balanced (adaptive)

Comment thread lib/unikraft/cloud/core/handle.rb Resolved
Comment thread lib/unikraft/cloud/core/handle.rb Resolved
Comment thread lib/unikraft/cloud/core/handle_set.rb Resolved
Core::Resource holds a plumbing client for a metro scope and owns the
shared collection verbs: create in one metro (metro: routes it, and
keywords merge over a positional body), a lazy get, where for every
match, a paginated fan-out list that is also the Enumerable each, bulk
delete grouped per metro with the refs located concurrently, and
update/edit shorthands. list takes tags: only where the operation
does. It locates a ref only when the ref or the scope does not
already name the metro, raises AmbiguousRefError for a ref found in
several metros, and reports a resource missing everywhere as a 404
naming them.

Core::Handle reads lazily and memoizes, but runs mutations at once:
Ruby has no await, and a mutation nobody forced would never run. Each
returns a new handle on the endpoint's result at the same location,
so calls chain; a declared attribute that partial result leaves out
is read once on first use. headers: and timeout: are call options in
every form of update, never properties. Core::HandleSet is Enumerable
over the matches and runs each operation in every metro, keeping the
successes on a MetroFanoutError.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Unikraft::Cloud.new builds a Client from token:, metro:, metros:,
base_url:, control_plane_url:, headers:, timeout:, proxy_from_env:
and a transport builder, falling back to UKC_TOKEN and UKC_METRO. A
metro given as a URL is the only endpoint there is. ukc.metro(:fra)
gives a cached MetroScope with its own api; ukc.metros(:fra, :dal) a
Scope. ukc.api is the raw layer, ukc.available_metros the discovered
metros. The client is thread-safe and meant to be shared; close
closes its connections, and Unikraft::Cloud.open yields a client and
closes it after the block. ApiClient#inspect leaves out the token and
headers, so echoing the client, its api or a resource's api in IRB or
a log cannot leak them.

Signed-off-by: Alexander Jung <alex@unikraft.com>
ukc.instances adds bulk start, stop and suspend to the shared verbs,
and shorthands for wait, logs, metrics and history. InstanceHandle
reads each instance attribute lazily, answers running?, stopped? and
the other API states, and chains start, stop, suspend, wait, logs,
metrics and history. wait forwards state and within: (seconds) to
the server-side wait and stretches the read timeout to outlive it;
timeout: stays the HTTP timeout, as on every call. where(name:)
returns an InstanceSet that runs each of those in every metro holding
the name.

The tests port the JS SDK's client suite: fan-out merge and metro
tags, ambiguity of names and of uuids, partial failure, create in one
metro, bulk grouped per metro, patch triples, the editor, handles
running each step once, scope precedence and URL metros.

Signed-off-by: Alexander Jung <alex@unikraft.com>
ukc.volumes shares the collection verbs and adds attach and detach,
on a handle, as shorthands, and across every match of where. Their
keywords are the API's own (attach_to:, at:, readonly:, from:); the
instance ref in attach_to: or from: may be a Hash or a Ref, and only
its identifier reaches the wire.

Signed-off-by: Alexander Jung <alex@unikraft.com>
ukc.services covers service groups with the shared verbs: create,
get, where, list, update, edit and delete, each handle reading the
group's attributes lazily.

Signed-off-by: Alexander Jung <alex@unikraft.com>
ukc.certificates shares the collection verbs. A certificate is
replaced rather than patched, so update takes the new chain: and
pkey:, on a handle, as a shorthand and across a where, and there is
no edit.

Signed-off-by: Alexander Jung <alex@unikraft.com>
ukc.users.quotas reads the user's quotas (or, with uuid:, another
user's) in every metro in scope, tags each with its metro, and keeps
the successes on a MetroFanoutError when some metros fail.

Signed-off-by: Alexander Jung <alex@unikraft.com>
test/e2e/live_test.rb runs under rake test:e2e against the account in
UKC_TOKEN and the deployment in UKC_METRO (the internal staging one
by default, as in the JS SDK): it lists across the scope, reads
quotas, and takes an instance through create, wait, logs, get,
update and reload before deleting it.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Port the JS SDK's examples to Ruby: create in one metro and chain
wait and logs off the handle, update with keywords and staged edits
in block and chained form, and call the plumbing directly, aiming a
call at each discovered metro with base_url:.

Signed-off-by: Alexander Jung <alex@unikraft.com>
Port the JS SDK's README to Ruby: installation, quickstart, the
client options and its thread-safe, long-lived use with close and
Unikraft::Cloud.open, the two layers, metros and the fan-out rules,
names across metros, partial failure, lazy Enumerable lists, handles
and why mutations run at once, updating and staged edits, refs, the
idiomatic methods, errors and waiting, self-hosted deployments,
runtime support, proxy debugging through Net::HTTP and SSL_CERT_FILE,
contributing and the license.

Signed-off-by: Alexander Jung <alex@unikraft.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The method describes checkpoint history as state-change history, which could mislead callers expecting lifecycle transitions.

1 open issue
3 resolved since last review

Review effort: Balanced (adaptive)

@nderjung
nderjung merged commit 54d7453 into prod-staging Nov 25, 2026
9 checks passed
@nderjung
nderjung deleted the nderjung/feat/init branch November 25, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants