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:



267
268
269
# File 'lib/cadenya/resources/api_keys.rb', line 267

def initialize(client:)
  @client = client
end

Instance Method Details

#create(metadata:, spec:, workspace_id: nil, 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
37
38
39
40
# File 'lib/cadenya/resources/api_keys.rb', line 27

def create(params)
  parsed, options = Cadenya::APIKeyCreateParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @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: nil, 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:



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/cadenya/resources/api_keys.rb', line 164

def delete(id, params = {})
  parsed, options = Cadenya::APIKeyDeleteParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    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: nil, 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:



192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/cadenya/resources/api_keys.rb', line 192

def disable(id, params = {})
  parsed, options = Cadenya::APIKeyDisableParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    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: nil, 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:



219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/cadenya/resources/api_keys.rb', line 219

def enable(id, params = {})
  parsed, options = Cadenya::APIKeyEnableParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    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: nil, 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)

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

  • cursor (String)

    Query param: Pagination cursor from previous response.

  • include_info (Boolean)

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

  • labels (String)

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

  • limit (Integer)

    Query param: Maximum number of results to return.

  • prefix (String)

    Query param: Filter by ID prefix.

  • query (String)

    Query param: Free-form search query.

  • sort_order (String)

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

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

Returns:

See Also:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/cadenya/resources/api_keys.rb', line 134

def list(params = {})
  parsed, options = Cadenya::APIKeyListParams.dump_request(params)
  query = Cadenya::Internal::Util.encode_query_params(parsed)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @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: nil, 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:



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cadenya/resources/api_keys.rb', line 55

def retrieve(id, params = {})
  parsed, options = Cadenya::APIKeyRetrieveParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    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: nil, 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:



250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/cadenya/resources/api_keys.rb', line 250

def rotate(id, params = {})
  parsed, options = Cadenya::APIKeyRotateParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    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: nil, 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:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cadenya/resources/api_keys.rb', line 91

def update(id, params = {})
  parsed, options = Cadenya::APIKeyUpdateParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    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