Class: Cadenya::Resources::APIKeys::Access

Inherits:
Object
  • Object
show all
Defined in:
lib/cadenya/resources/api_keys/access.rb

Overview

Issue, rotate, and revoke API keys for the account, and grant or revoke each key’s access to individual workspaces.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Access

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 Access.

Parameters:



94
95
96
# File 'lib/cadenya/resources/api_keys/access.rb', line 94

def initialize(client:)
  @client = client
end

Instance Method Details

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

Grants this API key access to the specified workspace. Idempotent — adding an already-associated workspace is a no-op. Returns the updated API key with refreshed workspace preview and total.

Parameters:

  • id (String)

    The API key being granted workspace access.

  • workspace_id (String)

    The workspace to grant access to.

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

Returns:

See Also:



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

def add(id, params = {})
  parsed, options = Cadenya::APIKeys::AccessAddParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["v1/account/api_keys/%1$s/workspaces", id],
    body: parsed,
    model: Cadenya::APIKey,
    options: options
  )
end

#list(id, cursor: nil, limit: nil, request_options: {}) ⇒ Cadenya::Internal::CursorPagination<Cadenya::Models::Workspace>

Lists the workspaces this API key has access to. Cursor-paginated.

Parameters:

  • id (String)

    The API key whose workspace associations will be listed.

  • cursor (String)

    Pagination cursor from previous response.

  • limit (Integer)

    Maximum number of results to return.

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

Returns:

See Also:



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

def list(id, params = {})
  parsed, options = Cadenya::APIKeys::AccessListParams.dump_request(params)
  query = Cadenya::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["v1/account/api_keys/%1$s/workspaces", id],
    query: query,
    page: Cadenya::Internal::CursorPagination,
    model: Cadenya::Workspace,
    options: options
  )
end

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

Revokes this API key’s access to the specified workspace. Idempotent. A key may have zero workspaces and remains valid.

Parameters:

  • workspace_id (String)

    The workspace whose access is being revoked (path).

  • id (String)

    The API key losing workspace access (path).

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

Returns:

  • (nil)

See Also:



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cadenya/resources/api_keys/access.rb', line 77

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