API keys

Envless.keys.iterate

Stream API keys one at a time

def iterate(
  limit: nil,
  offset: nil,
  search: nil,
  order: nil,
  timeout: nil,
  &block
)

Returns an Enumerator that yields keys individually and fetches the next page only once the current one is drained. Breaking out of the loop stops the requests, which makes this the cheapest way to resolve a single prefix to a full row.

The Enumerator defaults to the maximum page size of 100 and clamps anything larger, so limit: only ever makes pages smaller. Since a workspace holds at most 100 live keys, one page normally covers everything.

Creating or revoking keys while you iterate changes the set that offsets are counted against, so a key can be skipped or repeated. Collect the ids you care about first, then act on them after the loop has finished.

Example

ruby
require "envless/sdk"

Envless.keys.iterate do |key|
  if key[:prefix] == "ev_sk_9fQ2xa"
    puts "#{key[:id]} #{key[:scopes]} #{key[:projectIds]}"
    break
  end
end

Parameters

ParameterTypeRequiredDescription
limit:IntegerNoPage size per request, capped at 100 and defaulting to 100.
offset:IntegerNoRow the walk starts at, advancing by the number of items each page returns.
search:String | SymbolNoCase insensitive substring match against name and prefix.
order:"name" | "asc" | "desc"NoDefaults to name, which sorts A to Z. Pass asc for oldest first or desc for newest first on createdAt.
timeout:Integer | Float | RationalNoSeconds each attempt of this call may take, redirects and the response body included, before it raises Envless::NetworkError with timeout? set. Overrides the client's timeout for this call, and 0 turns the limit off.

Returns

Enumerator[key_resource, nil] yielding one key per step.

Reads the keys collection. list returns one page as an Envless::Page with items and pagination, list_all collects every page into an array, and iterate yields one item at a time to a block, fetching the next page only when it gets there. Without a block, iterate returns an Enumerator.

Worth knowing

  • The Enumerator is lazy, so no request is sent until you start consuming it.
  • Yielded rows carry prefix and never secret, so scanning cannot recover a lost credential.

Required scopes

keys:read

Underlying endpoint

GET /keys

Request and response schema, every error code, and a live playground.

In TypeScript

envless.keys.iterate()

The same method in @goenvless/sdk, with the same request, retries and errors.