Class: Cadenya::Resources::APIKeys

Inherits:
Object
  • Object
show all
Defined in:
lib/cadenya/resources/api_keys.rb,
sig/cadenya/resources/api_keys.rbs

Overview

Issue, rotate, disable, and revoke a workspace's API keys. Every key belongs to exactly one workspace; the system-managed global account key is managed via GlobalAPIKeyService instead.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ APIKeys

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of APIKeys.

Parameters:



259
260
261
# File 'lib/cadenya/resources/api_keys.rb', line 259

def initialize(client:)
  @client = client
end

Instance Method Details

#create(workspace_id, metadata:, spec:, request_options: {}) ⇒ Cadenya::Models::APIKey

Some parameter documentations has been truncated, see Models::APIKeyCreateParams for more details.

Creates a new API key in the workspace.

Parameters:

Returns:

See Also:



27
28
29
30
31
32
33
34
35
36
# File 'lib/cadenya/resources/api_keys.rb', line 27

def create(workspace_id, params)
  parsed, options = Cadenya::APIKeyCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/workspaces/%1$s/api_keys", workspace_id],
    body: parsed,
    model: Cadenya::APIKey,
    options: options
  )
end

#delete(id, workspace_id:, request_options: {}) ⇒ nil

Deletes an API key.

Parameters:

  • id (String)

    The API key to delete.

  • workspace_id (String)

    The workspace the API key belongs to (path).

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/cadenya/resources/api_keys.rb', line 156

def delete(id, params)
  parsed, options = Cadenya::APIKeyDeleteParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["v1/workspaces/%1$s/api_keys/%2$s", workspace_id, id],
    model: NilClass,
    options: options
  )
end

#disable(id, workspace_id:, request_options: {}) ⇒ Cadenya::Models::APIKey

Disables an API key. While disabled, presenting the key's token fails authentication on every endpoint; the key is retained. Idempotent.

Parameters:

  • id (String)

    The API key to disable.

  • workspace_id (String)

    The workspace the API key belongs to (path).

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/cadenya/resources/api_keys.rb', line 184

def disable(id, params)
  parsed, options = Cadenya::APIKeyDisableParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["v1/workspaces/%1$s/api_keys/%2$s:disable", workspace_id, id],
    model: Cadenya::APIKey,
    options: options
  )
end

#enable(id, workspace_id:, request_options: {}) ⇒ Cadenya::Models::APIKey

Re-enables a disabled API key so its token authenticates again. Idempotent.

Parameters:

  • id (String)

    The API key to enable.

  • workspace_id (String)

    The workspace the API key belongs to (path).

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/cadenya/resources/api_keys.rb', line 211

def enable(id, params)
  parsed, options = Cadenya::APIKeyEnableParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["v1/workspaces/%1$s/api_keys/%2$s:enable", workspace_id, id],
    model: Cadenya::APIKey,
    options: options
  )
end

#list(workspace_id, cursor: nil, include_info: nil, labels: nil, limit: nil, prefix: nil, query: nil, sort_order: nil, request_options: {}) ⇒ Cadenya::Internal::CursorPagination<Cadenya::Models::APIKey>

Some parameter documentations has been truncated, see Models::APIKeyListParams for more details.

Lists the workspace's API keys.

Parameters:

  • workspace_id (String)

    The workspace whose API keys will be listed (path).

  • cursor (String)

    Pagination cursor from previous response.

  • include_info (Boolean)

    When true, included info fields are populated. Requests with this

  • labels (String)

    Filters by metadata labels. Comma-separated key=value pairs,

  • limit (Integer)

    Maximum number of results to return.

  • prefix (String)

    Filter by ID prefix.

  • query (String)

    Free-form search query.

  • sort_order (String)

    Sort order for results (asc or desc by creation time).

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/cadenya/resources/api_keys.rb', line 130

def list(workspace_id, params = {})
  parsed, options = Cadenya::APIKeyListParams.dump_request(params)
  query = Cadenya::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["v1/workspaces/%1$s/api_keys", workspace_id],
    query: query.transform_keys(include_info: "includeInfo", sort_order: "sortOrder"),
    page: Cadenya::Internal::CursorPagination,
    model: Cadenya::APIKey,
    options: options
  )
end

#retrieve(id, workspace_id:, request_options: {}) ⇒ Cadenya::Models::APIKey

Retrieves an API key by ID.

Parameters:

  • id (String)

    The API key to retrieve.

  • workspace_id (String)

    The workspace the API key belongs to (path).

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cadenya/resources/api_keys.rb', line 51

def retrieve(id, params)
  parsed, options = Cadenya::APIKeyRetrieveParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["v1/workspaces/%1$s/api_keys/%2$s", workspace_id, id],
    model: Cadenya::APIKey,
    options: options
  )
end

#rotate(id, workspace_id:, request_options: {}) ⇒ Cadenya::Models::APIKey

Some parameter documentations has been truncated, see Models::APIKeyRotateParams for more details.

Rotates an API key and returns a new token. All previous tokens for this key are invalidated.

Parameters:

  • id (String)

    The API key to rotate. A new token is issued and any existing token is

  • workspace_id (String)

    The workspace the API key belongs to (path).

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/cadenya/resources/api_keys.rb', line 242

def rotate(id, params)
  parsed, options = Cadenya::APIKeyRotateParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["v1/workspaces/%1$s/api_keys/%2$s:rotate", workspace_id, id],
    model: Cadenya::APIKey,
    options: options
  )
end

#update(id, workspace_id:, metadata: nil, spec: nil, update_mask: nil, request_options: {}) ⇒ Cadenya::Models::APIKey

Some parameter documentations has been truncated, see Models::APIKeyUpdateParams for more details.

Updates an API key.

Parameters:

  • id (String)

    Path param: The API key to update.

  • workspace_id (String)

    Path param: The workspace the API key belongs to (path).

  • metadata (Cadenya::Models::APIKeyUpdateParams::Metadata)

    Body param: UpdateAccountResourceMetadata contains the user-provided fields for

  • spec (Cadenya::Models::APIKeySpec)

    Body param: Configuration for an API key.

  • update_mask (String)

    Body param: Fields to update.

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/cadenya/resources/api_keys.rb', line 87

def update(id, params)
  parsed, options = Cadenya::APIKeyUpdateParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :patch,
    path: ["v1/workspaces/%1$s/api_keys/%2$s", workspace_id, id],
    body: parsed,
    model: Cadenya::APIKey,
    options: options
  )
end