Class: WorkOS::AuditLogs

Inherits:
Object
  • Object
show all
Defined in:
lib/workos/audit_logs.rb

Defined Under Namespace

Classes: RetentionPeriod, RetentionPeriodInDays

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ AuditLogs

Returns a new instance of AuditLogs.



21
22
23
# File 'lib/workos/audit_logs.rb', line 21

def initialize(client)
  @client = client
end

Instance Method Details

#create_event(organization_id:, event:, request_options: {}) ⇒ WorkOS::AuditLogEventCreateResponse

Create Event

Parameters:

  • organization_id (String)

    The unique ID of the Organization.

  • event (WorkOS::AuditLogEvent)

    The audit log event to create.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/workos/audit_logs.rb', line 202

def create_event(
  organization_id:,
  event:,
  request_options: {}
)
  body = {
    "organization_id" => organization_id,
    "event" => event
  }
  response = @client.request(
    method: :post,
    path: "/audit_logs/events",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuditLogEventCreateResponse.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#create_export(organization_id:, range_start:, range_end:, actions: nil, actors: nil, actor_names: nil, actor_ids: nil, targets: nil, request_options: {}) ⇒ WorkOS::AuditLogExport

Create Export

Parameters:

  • organization_id (String)

    The unique ID of the Organization.

  • range_start (String)

    ISO-8601 value for start of the export range.

  • range_end (String)

    ISO-8601 value for end of the export range.

  • actions (Array<String>, nil) (defaults to: nil)

    List of actions to filter against.

  • actors (Array<String>, nil) (defaults to: nil)

    (deprecated) Deprecated. Use actor_names instead.

  • actor_names (Array<String>, nil) (defaults to: nil)

    List of actor names to filter against.

  • actor_ids (Array<String>, nil) (defaults to: nil)

    List of actor IDs to filter against.

  • targets (Array<String>, nil) (defaults to: nil)

    List of target types to filter against.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/workos/audit_logs.rb', line 234

def create_export(
  organization_id:,
  range_start:,
  range_end:,
  actions: nil,
  actors: nil,
  actor_names: nil,
  actor_ids: nil,
  targets: nil,
  request_options: {}
)
  body = {
    "organization_id" => organization_id,
    "range_start" => range_start,
    "range_end" => range_end,
    "actions" => actions,
    "actors" => actors,
    "actor_names" => actor_names,
    "actor_ids" => actor_ids,
    "targets" => targets
  }.compact
  response = @client.request(
    method: :post,
    path: "/audit_logs/exports",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuditLogExport.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#create_schema(action_name:, targets:, actor: nil, metadata: nil, request_options: {}) ⇒ WorkOS::AuditLogSchema

Create Schema

Parameters:

  • action_name (String)

    The name of the Audit Log action.

  • actor (WorkOS::AuditLogSchemaActorInput, nil) (defaults to: nil)

    The metadata schema for the actor.

  • targets (Array<WorkOS::AuditLogSchemaTargetInput>)

    The list of targets for the schema.

  • metadata (Hash{String => Object}, nil) (defaults to: nil)

    Optional JSON schema for event metadata.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/workos/audit_logs.rb', line 173

def create_schema(
  action_name:,
  targets:,
  actor: nil,
  metadata: nil,
  request_options: {}
)
  body = {
    "actor" => actor,
    "targets" => targets,
    "metadata" => 
  }.compact
  response = @client.request(
    method: :post,
    path: "/audit_logs/actions/#{WorkOS::Util.encode_path(action_name)}/schemas",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuditLogSchema.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#get_export(audit_log_export_id:, request_options: {}) ⇒ WorkOS::AuditLogExport

Get Export

Parameters:

  • audit_log_export_id (String)

    The unique ID of the Audit Log Export.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/workos/audit_logs.rb', line 271

def get_export(
  audit_log_export_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/audit_logs/exports/#{WorkOS::Util.encode_path(audit_log_export_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::AuditLogExport.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#get_organization_audit_logs_retention(id:, request_options: {}) ⇒ WorkOS::AuditLogsRetention

Get Retention

Parameters:

  • id (String)

    Unique identifier of the Organization.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/workos/audit_logs.rb', line 29

def get_organization_audit_logs_retention(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(id)}/audit_logs_retention",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::AuditLogsRetention.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#list_action_schemas(action_name:, before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::AuditLogSchema>

List Schemas

Parameters:

  • action_name (String)

    The name of the Audit Log action.

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • limit (Integer, nil) (defaults to: 10)

    Upper limit on the number of objects to return, between 1 and 100.

  • order (WorkOS::Types::PaginationOrder, nil) (defaults to: "desc")

    Order the results by the creation time.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/workos/audit_logs.rb', line 127

def list_action_schemas(
  action_name:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/audit_logs/actions/#{WorkOS::Util.encode_path(action_name)}/schemas",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_action_schemas(
      action_name: action_name,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::AuditLogSchema,
    filters: {action_name: action_name, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_actions(before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::AuditLogAction>

List Actions

Parameters:

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • limit (Integer, nil) (defaults to: 10)

    Upper limit on the number of objects to return, between 1 and 100.

  • order (WorkOS::Types::PaginationOrder, nil) (defaults to: "desc")

    Order the results by the creation time.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/workos/audit_logs.rb', line 82

def list_actions(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/audit_logs/actions",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_actions(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::AuditLogAction,
    filters: {before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#update_organization_audit_logs_retention(id:, retention:, request_options: {}) ⇒ WorkOS::AuditLogsRetention

Set Retention

Parameters:

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/workos/audit_logs.rb', line 49

def update_organization_audit_logs_retention(
  id:,
  retention:,
  request_options: {}
)
  body = {}
  case retention
  when WorkOS::AuditLogs::RetentionPeriod
    body["retention_period"] = retention.retention_period
  when WorkOS::AuditLogs::RetentionPeriodInDays
    body["retention_period_in_days"] = retention.retention_period_in_days
  else
    raise ArgumentError, "expected retention to be one of: WorkOS::AuditLogs::RetentionPeriod, WorkOS::AuditLogs::RetentionPeriodInDays, got #{retention.class}"
  end
  response = @client.request(
    method: :put,
    path: "/organizations/#{WorkOS::Util.encode_path(id)}/audit_logs_retention",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AuditLogsRetention.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end