Class: WorkOS::AuditLogs

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ AuditLogs

Returns a new instance of AuditLogs.



9
10
11
# File 'lib/workos/audit_logs.rb', line 9

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:



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/workos/audit_logs.rb', line 184

def create_event(
  organization_id:,
  event:,
  request_options: {}
)
  body = {
    "organization_id" => organization_id,
    "event" => event
  }.compact
  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::AuditLogExportJson

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:



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/workos/audit_logs.rb', line 216

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::AuditLogExportJson.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::AuditLogSchemaJson

Create Schema

Parameters:

  • action_name (String)

    The name of the Audit Log action.

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

    The metadata schema for the actor.

  • targets (Array<WorkOS::AuditLogSchemaTarget>)

    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:



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/workos/audit_logs.rb', line 155

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::AuditLogSchemaJson.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::AuditLogExportJson

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:



253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/workos/audit_logs.rb', line 253

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::AuditLogExportJson.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::AuditLogsRetentionJson

Get Retention

Parameters:

  • id (String)

    Unique identifier of the Organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/workos/audit_logs.rb', line 17

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::AuditLogsRetentionJson.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: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::AuditLogSchemaJson>

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: nil)

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

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

    Order the results by the creation time.

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

    (see WorkOS::Types::RequestOptions)

Returns:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/workos/audit_logs.rb', line 109

def list_action_schemas(
  action_name:,
  before: nil,
  after: nil,
  limit: nil,
  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::AuditLogSchemaJson,
    filters: {action_name: action_name, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

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

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: nil)

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

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

    Order the results by the creation time.

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

    (see WorkOS::Types::RequestOptions)

Returns:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/workos/audit_logs.rb', line 64

def list_actions(
  before: nil,
  after: nil,
  limit: nil,
  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::AuditLogActionJson,
    filters: {before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#update_organization_audit_logs_retention(id:, retention_period_in_days:, request_options: {}) ⇒ WorkOS::AuditLogsRetentionJson

Set Retention

Parameters:

  • id (String)

    Unique identifier of the Organization.

  • retention_period_in_days (Integer)

    The number of days Audit Log events will be retained. Valid values are ‘30` and `365`.

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

    (see WorkOS::Types::RequestOptions)

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/workos/audit_logs.rb', line 37

def update_organization_audit_logs_retention(
  id:,
  retention_period_in_days:,
  request_options: {}
)
  body = {
    "retention_period_in_days" => retention_period_in_days
  }.compact
  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::AuditLogsRetentionJson.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