-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2587 from DataDog/move-events-to-appsec-specific-…
…namespace Move events to appsec specific namespace
- Loading branch information
Showing
5 changed files
with
95 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# typed: false | ||
# frozen_string_literal: true | ||
|
||
require_relative '../identity' | ||
|
||
module Datadog | ||
module Kit | ||
module AppSec | ||
# Tracking events | ||
module Events | ||
LOGIN_SUCCESS_EVENT = 'users.login.success' | ||
LOGIN_FAILURE_EVENT = 'users.login.failure' | ||
|
||
# Attach login success event information to the trace | ||
# | ||
# This method is experimental and may change in the future. | ||
# | ||
# @param trace [TraceOperation] Trace to attach data to. | ||
# @param user [Hash<Symbol, String>] User information to pass to | ||
# Datadog::Kit::Identity.set_user. Must contain at least :id as key. | ||
# @param others [Hash<String || Symbol, String>] Additional free-form | ||
# event information to attach to the trace. | ||
def self.track_login_success(trace, user:, **others) | ||
track(LOGIN_SUCCESS_EVENT, trace, **others) | ||
|
||
user_options = user.dup | ||
user_id = user.delete(:id) | ||
|
||
raise ArgumentError, 'missing required key: :user => { :id }' if user_id.nil? | ||
|
||
Kit::Identity.set_user(trace, id: user_id, **user_options) | ||
end | ||
|
||
# Attach login failure event information to the trace | ||
# | ||
# This method is experimental and may change in the future. | ||
# | ||
# @param trace [TraceOperation] Trace to attach data to. | ||
# @param user_id [String] User id that attempted login | ||
# @param user_exists [bool] Whether the user id that did a login attempt exists. | ||
# @param others [Hash<String || Symbol, String>] Additional free-form | ||
# event information to attach to the trace. | ||
def self.track_login_failure(trace, user_id:, user_exists:, **others) | ||
track(LOGIN_FAILURE_EVENT, trace, **others) | ||
|
||
raise ArgumentError, 'user_id cannot be nil' if user_id.nil? | ||
|
||
trace.set_tag('appsec.events.users.login.failure.usr.id', user_id) | ||
trace.set_tag('appsec.events.users.login.failure.usr.exists', user_exists) | ||
end | ||
|
||
# Attach custom event information to the trace | ||
# | ||
# This method is experimental and may change in the future. | ||
# | ||
# @param event [String] Mandatory. Event code. | ||
# @param trace [TraceOperation] Trace to attach data to. | ||
# @param others [Hash<Symbol, String>] Additional free-form | ||
# event information to attach to the trace. Key must not | ||
# be :track. | ||
def self.track(event, trace, **others) | ||
trace.set_tag("appsec.events.#{event}.track", 'true') | ||
|
||
others.each do |k, v| | ||
raise ArgumentError, 'key cannot be :track' if k.to_sym == :track | ||
|
||
trace.set_tag("appsec.events.#{event}.#{k}", v) unless v.nil? | ||
end | ||
|
||
trace.keep! | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Datadog | ||
module Kit | ||
module AppSec | ||
module Events | ||
LOGIN_SUCCESS_EVENT: ::String | ||
LOGIN_FAILURE_EVENT: ::String | ||
|
||
def self.track_login_success: (Datadog::Tracing::TraceOperation trace, user: Hash[::Symbol, ::String | nil], **::Hash[::Symbol, ::String | nil] others) -> void | ||
|
||
def self.track_login_failure: (Datadog::Tracing::TraceOperation trace, user_id: ::String, user_exists: bool, **::Hash[::Symbol, ::String | nil] others) -> void | ||
|
||
def self.track: (::String | ::Symbol event, Datadog::Tracing::TraceOperation trace, **::Hash[::Symbol, ::String | nil] others) -> void | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters