Class: Tripwire::Server::ApiKeysResource

Inherits:
BaseResource show all
Defined in:
lib/tripwire/server/client.rb

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from Tripwire::Server::BaseResource

Instance Method Details

#create(organization_id, name:, type: nil, environment: nil, allowed_origins: nil, scopes: nil) ⇒ Object



224
225
226
227
228
229
230
231
232
233
# File 'lib/tripwire/server/client.rb', line 224

def create(organization_id, name:, type: nil, environment: nil, allowed_origins: nil, scopes: nil)
  payload = @client.request_json("POST", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys", body: compact({
    name: name,
    type: type,
    environment: environment,
    allowed_origins: allowed_origins,
    scopes: scopes
  }))
  payload[:data]
end

#list(organization_id, limit: nil, cursor: nil) ⇒ Object



235
236
237
238
239
240
241
# File 'lib/tripwire/server/client.rb', line 235

def list(organization_id, limit: nil, cursor: nil)
  payload = @client.request_json("GET", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys", query: {
    limit: limit,
    cursor: cursor
  })
  list_result(payload)
end

#revoke(organization_id, key_id) ⇒ Object



251
252
253
# File 'lib/tripwire/server/client.rb', line 251

def revoke(organization_id, key_id)
  @client.request_json("DELETE", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys/#{CGI.escape(key_id)}")[:data]
end

#rotate(organization_id, key_id) ⇒ Object



255
256
257
258
# File 'lib/tripwire/server/client.rb', line 255

def rotate(organization_id, key_id)
  payload = @client.request_json("POST", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys/#{CGI.escape(key_id)}/rotations")
  payload[:data]
end

#update(organization_id, key_id, name: nil, allowed_origins: nil, scopes: nil) ⇒ Object



243
244
245
246
247
248
249
# File 'lib/tripwire/server/client.rb', line 243

def update(organization_id, key_id, name: nil, allowed_origins: nil, scopes: nil)
  @client.request_json("PATCH", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys/#{CGI.escape(key_id)}", body: compact({
    name: name,
    allowed_origins: allowed_origins,
    scopes: scopes
  }))[:data]
end