Class: Cadenya::Resources::ApiKeys

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

Instance Method Summary collapse

Constructor Details

#initialize(core) ⇒ ApiKeys

Returns a new instance of ApiKeys.



8
9
10
# File 'lib/cadenya/resources/api_keys.rb', line 8

def initialize(core)
  @core = core
end

Instance Method Details

#create(metadata:, spec:, workspace_id: nil, request_options: nil) ⇒ Object

Create a new API key



62
63
64
65
66
67
68
69
70
71
# File 'lib/cadenya/resources/api_keys.rb', line 62

def create(metadata:, spec:, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/api_keys"
  _body = {
    "metadata" => .nil? ? nil : (->(_v) { Types.(_v) }).call(),
    "spec" => spec.nil? ? nil : (->(_v) { Types.encode_APIKeySpec(_v) }).call(spec),
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:post, _path, body: _body, request_options: request_options)
  Types::APIKey.from_json(_data)
end

#delete(id, workspace_id: nil, request_options: nil) ⇒ Object

Delete an API key



82
83
84
85
86
87
# File 'lib/cadenya/resources/api_keys.rb', line 82

def delete(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/api_keys/#{Util.path_param('id', id)}"
  @core.request(:delete, _path, expects_body: false, request_options: request_options)
  nil
end

#disable(id, workspace_id: nil, request_options: nil) ⇒ Object

Disable an API key



103
104
105
106
107
108
# File 'lib/cadenya/resources/api_keys.rb', line 103

def disable(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/api_keys/#{Util.path_param('id', id)}:disable"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::APIKey.from_json(_data)
end

#disable_global(request_options: nil) ⇒ Object

Disable the global API key



20
21
22
23
24
# File 'lib/cadenya/resources/api_keys.rb', line 20

def disable_global(request_options: nil)
  _path = "/v1/account/global_api_key:disable"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::APIKey.from_json(_data)
end

#enable(id, workspace_id: nil, request_options: nil) ⇒ Object

Enable an API key



111
112
113
114
115
116
# File 'lib/cadenya/resources/api_keys.rb', line 111

def enable(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/api_keys/#{Util.path_param('id', id)}:enable"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::APIKey.from_json(_data)
end

#enable_global(request_options: nil) ⇒ Object

Enable the global API key



27
28
29
30
31
# File 'lib/cadenya/resources/api_keys.rb', line 27

def enable_global(request_options: nil)
  _path = "/v1/account/global_api_key:enable"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::APIKey.from_json(_data)
end

#list(workspace_id: nil, limit: nil, cursor: nil, prefix: nil, query: nil, labels: nil, sort_order: nil, include_info: nil, request_options: nil) ⇒ Object

List API keys



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cadenya/resources/api_keys.rb', line 41

def list(workspace_id: nil, limit: nil, cursor: nil, prefix: nil, query: nil, labels: nil, sort_order: nil, include_info: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/api_keys"
  _query = {
    "limit" => limit,
    "cursor" => cursor,
    "prefix" => prefix,
    "query" => query,
    "labels" => labels,
    "sortOrder" => sort_order,
    "includeInfo" => include_info,
  }
  _data = @core.request(:get, _path, query: _query, request_options: request_options) || {}
  _items = (_data["items"] || []).map { |item| Types::APIKey.from_json(item) }
  _next_cursor = (((_data)["pagination"] || {}))["nextCursor"].to_s
  Page.new(_items, _next_cursor) do |_c|
    list(workspace_id: workspace_id, limit: limit, cursor: _c, prefix: prefix, query: query, labels: labels, sort_order: sort_order, include_info: include_info, request_options: request_options)
  end
end

#retrieve(id, workspace_id: nil, request_options: nil) ⇒ Object

Get an API key by ID



74
75
76
77
78
79
# File 'lib/cadenya/resources/api_keys.rb', line 74

def retrieve(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/api_keys/#{Util.path_param('id', id)}"
  _data = @core.request(:get, _path, request_options: request_options)
  Types::APIKey.from_json(_data)
end

#retrieve_global(request_options: nil) ⇒ Object

Get the global API key



13
14
15
16
17
# File 'lib/cadenya/resources/api_keys.rb', line 13

def retrieve_global(request_options: nil)
  _path = "/v1/account/global_api_key"
  _data = @core.request(:get, _path, request_options: request_options)
  Types::APIKey.from_json(_data)
end

#rotate(id, workspace_id: nil, request_options: nil) ⇒ Object

Rotate an API key



119
120
121
122
123
124
# File 'lib/cadenya/resources/api_keys.rb', line 119

def rotate(id, workspace_id: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/api_keys/#{Util.path_param('id', id)}:rotate"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::APIKey.from_json(_data)
end

#rotate_global(request_options: nil) ⇒ Object

Rotate the global API key



34
35
36
37
38
# File 'lib/cadenya/resources/api_keys.rb', line 34

def rotate_global(request_options: nil)
  _path = "/v1/account/global_api_key:rotate"
  _data = @core.request(:post, _path, request_options: request_options)
  Types::APIKey.from_json(_data)
end

#update(id, workspace_id: nil, metadata: nil, spec: nil, update_mask: nil, request_options: nil) ⇒ Object

Update an API key



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

def update(id, workspace_id: nil, metadata: nil, spec: nil, update_mask: nil, request_options: nil)
  workspace_id = @core.resolve_default("workspaceId", "CADENYA_WORKSPACE_ID", workspace_id)
  _path = "/v1/workspaces/#{Util.path_param('workspaceId', workspace_id)}/api_keys/#{Util.path_param('id', id)}"
  _body = {
    "metadata" => .nil? ? nil : (->(_v) { Types.(_v) }).call(),
    "spec" => spec.nil? ? nil : (->(_v) { Types.encode_APIKeySpec(_v) }).call(spec),
    "updateMask" => update_mask,
  }.reject { |_k, v| v.nil? }
  _data = @core.request(:patch, _path, body: _body, request_options: request_options)
  Types::APIKey.from_json(_data)
end