Module: HookSniff

Defined in:
lib/hooksniff/util.rb,
lib/hooksniff.rb,
lib/hooksniff/errors.rb,
lib/hooksniff/api/sso.rb,
lib/hooksniff/options.rb,
lib/hooksniff/version.rb,
lib/hooksniff/webhook.rb,
lib/hooksniff/api/team.rb,
lib/hooksniff/internal.rb,
lib/hooksniff/api/alert.rb,
lib/hooksniff/api_error.rb,
lib/hooksniff/hooksniff.rb,
lib/hooksniff/paginator.rb,
lib/hooksniff/api/health.rb,
lib/hooksniff/api/portal.rb,
lib/hooksniff/api/schema.rb,
lib/hooksniff/api/search.rb,
lib/hooksniff/api/stream.rb,
lib/hooksniff/api/api_key.rb,
lib/hooksniff/api/billing.rb,
lib/hooksniff/api/inbound.rb,
lib/hooksniff/api/message.rb,
lib/hooksniff/api/routing.rb,
lib/hooksniff/api/endpoint.rb,
lib/hooksniff/api/template.rb,
lib/hooksniff/api/analytics.rb,
lib/hooksniff/api/audit_log.rb,
lib/hooksniff/api/connector.rb,
lib/hooksniff/webhook_event.rb,
lib/hooksniff/api/event_type.rb,
lib/hooksniff/api/playground.rb,
lib/hooksniff/api/rate_limit.rb,
lib/hooksniff/api/statistics.rb,
lib/hooksniff/http_error_out.rb,
lib/hooksniff/api/application.rb,
lib/hooksniff/api/environment.rb,
lib/hooksniff/api/integration.rb,
lib/hooksniff/models/event_in.rb,
lib/hooksniff/models/ordering.rb,
lib/hooksniff/api/notification.rb,
lib/hooksniff/models/event_out.rb,
lib/hooksniff/validation_error.rb,
lib/hooksniff/api/custom_domain.rb,
lib/hooksniff/api/service_token.rb,
lib/hooksniff/models/message_in.rb,
lib/hooksniff/response_metadata.rb,
lib/hooksniff/api/authentication.rb,
lib/hooksniff/api/message_poller.rb,
lib/hooksniff/models/endpoint_in.rb,
lib/hooksniff/models/message_out.rb,
lib/hooksniff/api/background_task.rb,
lib/hooksniff/api/message_attempt.rb,
lib/hooksniff/models/endpoint_out.rb,
lib/hooksniff/models/event_type_in.rb,
lib/hooksniff/hooksniff_http_client.rb,
lib/hooksniff/hooksniff_http_client.rb,
lib/hooksniff/hooksniff_http_client.rb,
lib/hooksniff/http_validation_error.rb,
lib/hooksniff/models/endpoint_patch.rb,
lib/hooksniff/models/event_type_out.rb,
lib/hooksniff/models/message_status.rb,
lib/hooksniff/models/endpoint_update.rb,
lib/hooksniff/api/operational_webhook.rb,
lib/hooksniff/models/event_type_patch.rb,
lib/hooksniff/models/event_type_update.rb,
lib/hooksniff/models/status_code_class.rb,
lib/hooksniff/models/endpoint_headers_in.rb,
lib/hooksniff/models/endpoint_secret_out.rb,
lib/hooksniff/models/message_attempt_log.rb,
lib/hooksniff/models/message_attempt_out.rb,
lib/hooksniff/models/message_status_text.rb,
lib/hooksniff/models/endpoint_headers_out.rb,
lib/hooksniff/models/message_endpoint_out.rb,
lib/hooksniff/models/endpoint_created_event.rb,
lib/hooksniff/models/endpoint_deleted_event.rb,
lib/hooksniff/models/endpoint_enabled_event.rb,
lib/hooksniff/models/endpoint_updated_event.rb,
lib/hooksniff/models/endpoint_disabled_event.rb,
lib/hooksniff/models/aggregate_event_types_out.rb,
lib/hooksniff/models/endpoint_headers_patch_in.rb,
lib/hooksniff/models/endpoint_secret_rotate_in.rb,
lib/hooksniff/models/list_response_message_out.rb,
lib/hooksniff/models/message_attempt_log_event.rb,
lib/hooksniff/models/list_response_endpoint_out.rb,
lib/hooksniff/models/endpoint_created_event_data.rb,
lib/hooksniff/models/endpoint_deleted_event_data.rb,
lib/hooksniff/models/endpoint_enabled_event_data.rb,
lib/hooksniff/models/endpoint_updated_event_data.rb,
lib/hooksniff/models/message_attempt_failed_data.rb,
lib/hooksniff/models/endpoint_disabled_event_data.rb,
lib/hooksniff/models/list_response_event_type_out.rb,
lib/hooksniff/models/message_attempt_trigger_type.rb,
lib/hooksniff/models/message_attempt_failing_event.rb,
lib/hooksniff/models/message_attempt_exhausted_event.rb,
lib/hooksniff/models/message_attempt_recovered_event.rb,
lib/hooksniff/models/list_response_message_attempt_out.rb,
lib/hooksniff/models/message_attempt_failing_event_data.rb,
lib/hooksniff/models/message_attempt_exhausted_event_data.rb,
lib/hooksniff/models/message_attempt_recovered_event_data.rb

Overview

This file is @generated

Defined Under Namespace

Modules: DebugLogger Classes: AggregateEventTypesOut, Alert, Analytics, ApiError, ApiKey, Application, AttemptInfo, AuditLog, Authentication, AuthenticationError, BackgroundTask, BadGatewayError, BadRequestError, Billing, Client, ConflictError, Connector, CustomDomain, Endpoint, EndpointCreatedEvent, EndpointCreatedEventData, EndpointDeletedEvent, EndpointDeletedEventData, EndpointDisabledEvent, EndpointDisabledEventData, EndpointEnabledEvent, EndpointEnabledEventData, EndpointHeadersIn, EndpointHeadersOut, EndpointHeadersPatchIn, EndpointIn, EndpointOut, EndpointPatch, EndpointSecretOut, EndpointSecretRotateIn, EndpointUpdate, EndpointUpdatedEvent, EndpointUpdatedEventData, Environment, EventIn, EventOut, EventType, EventTypeIn, EventTypeOut, EventTypePatch, EventTypeUpdate, ForbiddenError, GatewayTimeoutError, GoneError, Health, HookSniffHttpClient, HookSniffOptions, Inbound, InsufficientStorageError, IntegrationApi, InternalServerError, LastAttemptInfo, ListResponseEndpointOut, ListResponseEventTypeOut, ListResponseMessageAttemptOut, ListResponseMessageOut, LoopDetectedError, Message, MessageAttempt, MessageAttemptExhaustedEvent, MessageAttemptExhaustedEventData, MessageAttemptFailedData, MessageAttemptFailingEvent, MessageAttemptFailingEventData, MessageAttemptLog, MessageAttemptLogEvent, MessageAttemptOut, MessageAttemptRecoveredEvent, MessageAttemptRecoveredEventData, MessageAttemptTriggerType, MessageEndpointOut, MessageIn, MessageOut, MessagePoller, MessageStatus, MessageStatusText, NetworkError, NotFoundError, NotImplementedError, Notification, OperationalWebhook, Options, Ordering, Paginator, PayloadTooLargeError, Playground, Portal, RateLimit, RateLimitError, RequestTimeoutError, ResponseMetadata, Routing, Schema, Search, ServiceToken, ServiceUnavailableError, Sso, Statistics, StatusCodeClass, StreamApi, Team, Template, TimeoutError, UnauthorizedError, UnprocessableEntityError, Webhook, WebhookEvent, WebhookSigningError, WebhookVerificationError

Constant Summary collapse

VERSION =
"1.3.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.last_responseObject

Returns the value of attribute last_response.



150
151
152
# File 'lib/hooksniff/hooksniff_http_client.rb', line 150

def last_response
  @last_response
end

Class Method Details

.create_error_from_status(status_code, response_headers: {}, response_body: nil) ⇒ Object

Create the appropriate error from a status code



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/hooksniff/errors.rb', line 167

def self.create_error_from_status(status_code, response_headers: {}, response_body: nil)
  case status_code
  when 400
    BadRequestError.new(response_headers: response_headers, response_body: response_body)
  when 401
    UnauthorizedError.new(response_headers: response_headers, response_body: response_body)
  when 403
    ForbiddenError.new(response_headers: response_headers, response_body: response_body)
  when 404
    NotFoundError.new(response_headers: response_headers, response_body: response_body)
  when 408
    RequestTimeoutError.new(response_headers: response_headers, response_body: response_body)
  when 409
    ConflictError.new(response_headers: response_headers, response_body: response_body)
  when 410
    GoneError.new(response_headers: response_headers, response_body: response_body)
  when 413
    PayloadTooLargeError.new(response_headers: response_headers, response_body: response_body)
  when 422
    UnprocessableEntityError.new(response_headers: response_headers, response_body: response_body)
  when 429
    retry_after = response_headers["retry-after"]&.to_i
    RateLimitError.new(retry_after: retry_after, response_headers: response_headers, response_body: response_body)
  when 500
    InternalServerError.new(response_headers: response_headers, response_body: response_body)
  when 501
    NotImplementedError.new(response_headers: response_headers, response_body: response_body)
  when 502
    BadGatewayError.new(response_headers: response_headers, response_body: response_body)
  when 503
    ServiceUnavailableError.new(response_headers: response_headers, response_body: response_body)
  when 504
    GatewayTimeoutError.new(response_headers: response_headers, response_body: response_body)
  when 507
    InsufficientStorageError.new(response_headers: response_headers, response_body: response_body)
  when 508
    LoopDetectedError.new(response_headers: response_headers, response_body: response_body)
  else
    ApiError.new(code: status_code, response_headers: response_headers, response_body: response_body)
  end
end

.deserialize_date(v) ⇒ Object



51
52
53
# File 'lib/hooksniff/util.rb', line 51

def deserialize_date(v)
  DateTime.rfc3339(v)
end

.fixed_length_secure_compare(a, b) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
# File 'lib/hooksniff/util.rb', line 12

def fixed_length_secure_compare(a, b)
  OpenSSL.fixed_length_secure_compare(a, b)
end

.secure_compare(a, b) ⇒ Object

Secure string comparison for strings of variable length.

While a timing attack would not be able to discern the content of a secret compared via secure_compare, it is possible to determine the secret length. This should be considered when using secure_compare to compare weak, short secrets to user input.



35
36
37
# File 'lib/hooksniff/util.rb', line 35

def secure_compare(a, b)
  a.length == b.length && fixed_length_secure_compare(a, b)
end

.serialize_primitive(v) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/hooksniff/util.rb', line 41

def serialize_primitive(v)
  if v.kind_of?(Time)
    v.utc.to_datetime.rfc3339
  else
    v
  end
end

.serialize_schema_ref(v) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/hooksniff/util.rb', line 57

def serialize_schema_ref(v)
  # Enums are a schema_ref but since we pass them around using the underlying value
  # we need to check if they have the serialize method before calling it
  if v.class.method_defined? :serialize
    v.serialize
  else
    v
  end
end