logstruct 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -22
  3. data/README.md +25 -2
  4. data/lib/log_struct/boot_buffer.rb +28 -0
  5. data/lib/log_struct/builders/active_job.rb +84 -0
  6. data/lib/log_struct/concerns/configuration.rb +126 -13
  7. data/lib/log_struct/concerns/error_handling.rb +3 -7
  8. data/lib/log_struct/concerns/logging.rb +5 -5
  9. data/lib/log_struct/config_struct/filters.rb +18 -0
  10. data/lib/log_struct/config_struct/integrations.rb +16 -12
  11. data/lib/log_struct/configuration.rb +13 -0
  12. data/lib/log_struct/enums/event.rb +13 -0
  13. data/lib/log_struct/enums/log_field.rb +154 -0
  14. data/lib/log_struct/enums/source.rb +4 -1
  15. data/lib/log_struct/formatter.rb +29 -17
  16. data/lib/log_struct/integrations/action_mailer/error_handling.rb +3 -11
  17. data/lib/log_struct/integrations/action_mailer/event_logging.rb +22 -12
  18. data/lib/log_struct/integrations/active_job/log_subscriber.rb +52 -48
  19. data/lib/log_struct/integrations/active_model_serializers.rb +49 -0
  20. data/lib/log_struct/integrations/active_record.rb +35 -5
  21. data/lib/log_struct/integrations/active_storage.rb +59 -20
  22. data/lib/log_struct/integrations/ahoy.rb +54 -0
  23. data/lib/log_struct/integrations/carrierwave.rb +13 -16
  24. data/lib/log_struct/integrations/dotenv.rb +278 -0
  25. data/lib/log_struct/integrations/good_job/log_subscriber.rb +86 -136
  26. data/lib/log_struct/integrations/good_job/logger.rb +8 -10
  27. data/lib/log_struct/integrations/good_job.rb +5 -7
  28. data/lib/log_struct/integrations/host_authorization.rb +25 -4
  29. data/lib/log_struct/integrations/lograge.rb +20 -14
  30. data/lib/log_struct/integrations/puma.rb +482 -0
  31. data/lib/log_struct/integrations/rack_error_handler/middleware.rb +11 -18
  32. data/lib/log_struct/integrations/shrine.rb +44 -19
  33. data/lib/log_struct/integrations/sorbet.rb +48 -0
  34. data/lib/log_struct/integrations.rb +25 -0
  35. data/lib/log_struct/log/action_mailer/delivered.rb +99 -0
  36. data/lib/log_struct/log/action_mailer/delivery.rb +99 -0
  37. data/lib/log_struct/log/action_mailer.rb +30 -45
  38. data/lib/log_struct/log/active_job/enqueue.rb +125 -0
  39. data/lib/log_struct/log/active_job/finish.rb +130 -0
  40. data/lib/log_struct/log/active_job/schedule.rb +125 -0
  41. data/lib/log_struct/log/active_job/start.rb +130 -0
  42. data/lib/log_struct/log/active_job.rb +41 -54
  43. data/lib/log_struct/log/active_model_serializers.rb +94 -0
  44. data/lib/log_struct/log/active_storage/delete.rb +87 -0
  45. data/lib/log_struct/log/active_storage/download.rb +103 -0
  46. data/lib/log_struct/log/active_storage/exist.rb +93 -0
  47. data/lib/log_struct/log/active_storage/metadata.rb +93 -0
  48. data/lib/log_struct/log/active_storage/stream.rb +93 -0
  49. data/lib/log_struct/log/active_storage/upload.rb +118 -0
  50. data/lib/log_struct/log/active_storage/url.rb +93 -0
  51. data/lib/log_struct/log/active_storage.rb +32 -68
  52. data/lib/log_struct/log/ahoy.rb +88 -0
  53. data/lib/log_struct/log/carrierwave/delete.rb +115 -0
  54. data/lib/log_struct/log/carrierwave/download.rb +131 -0
  55. data/lib/log_struct/log/carrierwave/upload.rb +141 -0
  56. data/lib/log_struct/log/carrierwave.rb +37 -72
  57. data/lib/log_struct/log/dotenv/load.rb +76 -0
  58. data/lib/log_struct/log/dotenv/restore.rb +76 -0
  59. data/lib/log_struct/log/dotenv/save.rb +76 -0
  60. data/lib/log_struct/log/dotenv/update.rb +76 -0
  61. data/lib/log_struct/log/dotenv.rb +12 -0
  62. data/lib/log_struct/log/error.rb +58 -46
  63. data/lib/log_struct/log/good_job/enqueue.rb +126 -0
  64. data/lib/log_struct/log/good_job/error.rb +151 -0
  65. data/lib/log_struct/log/good_job/finish.rb +136 -0
  66. data/lib/log_struct/log/good_job/log.rb +131 -0
  67. data/lib/log_struct/log/good_job/schedule.rb +136 -0
  68. data/lib/log_struct/log/good_job/start.rb +136 -0
  69. data/lib/log_struct/log/good_job.rb +40 -141
  70. data/lib/log_struct/log/interfaces/additional_data_field.rb +1 -17
  71. data/lib/log_struct/log/interfaces/common_fields.rb +1 -39
  72. data/lib/log_struct/log/interfaces/public_common_fields.rb +4 -0
  73. data/lib/log_struct/log/interfaces/request_fields.rb +1 -33
  74. data/lib/log_struct/log/plain.rb +59 -34
  75. data/lib/log_struct/log/puma/shutdown.rb +80 -0
  76. data/lib/log_struct/log/puma/start.rb +120 -0
  77. data/lib/log_struct/log/puma.rb +10 -0
  78. data/lib/log_struct/log/request.rb +132 -48
  79. data/lib/log_struct/log/security/blocked_host.rb +141 -0
  80. data/lib/log_struct/log/security/csrf_violation.rb +131 -0
  81. data/lib/log_struct/log/security/ip_spoof.rb +141 -0
  82. data/lib/log_struct/log/security.rb +40 -70
  83. data/lib/log_struct/log/shared/add_request_fields.rb +1 -26
  84. data/lib/log_struct/log/shared/merge_additional_data_fields.rb +1 -25
  85. data/lib/log_struct/log/shared/serialize_common.rb +1 -33
  86. data/lib/log_struct/log/shared/serialize_common_public.rb +44 -0
  87. data/lib/log_struct/log/shrine/delete.rb +85 -0
  88. data/lib/log_struct/log/shrine/download.rb +90 -0
  89. data/lib/log_struct/log/shrine/exist.rb +90 -0
  90. data/lib/log_struct/log/shrine/metadata.rb +90 -0
  91. data/lib/log_struct/log/shrine/upload.rb +105 -0
  92. data/lib/log_struct/log/shrine.rb +10 -67
  93. data/lib/log_struct/log/sidekiq.rb +65 -26
  94. data/lib/log_struct/log/sql.rb +113 -106
  95. data/lib/log_struct/log.rb +31 -32
  96. data/lib/log_struct/multi_error_reporter.rb +80 -22
  97. data/lib/log_struct/param_filters.rb +50 -7
  98. data/lib/log_struct/rails_boot_banner_silencer.rb +123 -0
  99. data/lib/log_struct/railtie.rb +71 -0
  100. data/lib/log_struct/semantic_logger/formatter.rb +4 -2
  101. data/lib/log_struct/semantic_logger/setup.rb +34 -18
  102. data/lib/log_struct/shared/interfaces/additional_data_field.rb +22 -0
  103. data/lib/log_struct/shared/interfaces/common_fields.rb +39 -0
  104. data/lib/log_struct/shared/interfaces/public_common_fields.rb +29 -0
  105. data/lib/log_struct/shared/interfaces/request_fields.rb +39 -0
  106. data/lib/log_struct/shared/shared/add_request_fields.rb +28 -0
  107. data/lib/log_struct/shared/shared/merge_additional_data_fields.rb +27 -0
  108. data/lib/log_struct/shared/shared/serialize_common.rb +58 -0
  109. data/lib/log_struct/version.rb +1 -1
  110. data/lib/log_struct.rb +22 -4
  111. data/logstruct.gemspec +3 -0
  112. metadata +108 -5
  113. data/lib/log_struct/log/interfaces/message_field.rb +0 -20
  114. data/lib/log_struct/log_keys.rb +0 -102
@@ -1,75 +1,159 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "interfaces/common_fields"
5
- require_relative "interfaces/request_fields"
6
- require_relative "shared/serialize_common"
7
- require_relative "shared/add_request_fields"
4
+ # AUTO-GENERATED: DO NOT EDIT
5
+ # Generated by scripts/generate_structs.rb
6
+ # Schemas dir: schemas/log_sources/
7
+ # Template: tools/codegen/templates/sorbet/event.rb.erb
8
+
9
+ require "log_struct/shared/interfaces/common_fields"
10
+ require "log_struct/shared/interfaces/additional_data_field"
11
+ require "log_struct/shared/interfaces/request_fields"
12
+ require "log_struct/shared/shared/serialize_common"
13
+ require "log_struct/shared/shared/merge_additional_data_fields"
14
+ require "log_struct/shared/shared/add_request_fields"
8
15
  require_relative "../enums/source"
9
16
  require_relative "../enums/event"
10
17
  require_relative "../enums/level"
11
- require_relative "../log_keys"
18
+ require_relative "../enums/log_field"
12
19
 
13
20
  module LogStruct
14
21
  module Log
15
- # Request log entry for structured logging
16
22
  class Request < T::Struct
17
- extend T::Sig
23
+ # typed: strict
24
+ # frozen_string_literal: true
18
25
 
19
- include Interfaces::CommonFields
20
- include Interfaces::RequestFields
21
- include SerializeCommon
22
- include AddRequestFields
26
+ extend T::Sig
23
27
 
24
- RequestEvent = T.type_alias {
25
- Event::Request
26
- }
28
+ extend T::Sig
27
29
 
28
- # Common fields
29
- const :source, Source::Rails, default: T.let(Source::Rails, Source::Rails)
30
- const :event, RequestEvent, default: T.let(Event::Request, RequestEvent)
30
+ # Shared/common fields
31
+ const :source, Source::Rails, default: Source::Rails
32
+ const :event, Event, default: Event::Request
31
33
  const :timestamp, Time, factory: -> { Time.now }
32
- const :level, Level, default: T.let(Level::Info, Level)
34
+ const :level, Level, default: Level::Info
33
35
 
34
- # Request-specific fields
35
- # NOTE: `method` is a reserved word, so we use `http_method`
36
- # prop while setting `method` in the serialized output
37
- const :http_method, T.nilable(String), default: nil
38
36
  const :path, T.nilable(String), default: nil
37
+ const :http_method, T.nilable(String), default: nil
38
+ const :source_ip, T.nilable(String), default: nil
39
+ const :user_agent, T.nilable(String), default: nil
40
+ const :referer, T.nilable(String), default: nil
41
+ const :request_id, T.nilable(String), default: nil
42
+
43
+ # Event-specific fields
39
44
  const :format, T.nilable(String), default: nil
40
45
  const :controller, T.nilable(String), default: nil
41
46
  const :action, T.nilable(String), default: nil
42
47
  const :status, T.nilable(Integer), default: nil
43
- const :duration, T.nilable(Float), default: nil
48
+ const :duration_ms, T.nilable(Float), default: nil
44
49
  const :view, T.nilable(Float), default: nil
45
- const :db, T.nilable(Float), default: nil
50
+ const :database, T.nilable(Float), default: nil
46
51
  const :params, T.nilable(T::Hash[Symbol, T.untyped]), default: nil
47
- const :source_ip, T.nilable(String), default: nil
48
- const :user_agent, T.nilable(String), default: nil
49
- const :referer, T.nilable(String), default: nil
50
- const :request_id, T.nilable(String), default: nil
51
52
 
52
- # Convert the log entry to a hash for serialization
53
- sig { override.params(strict: T::Boolean).returns(T::Hash[Symbol, T.untyped]) }
54
- def serialize(strict = true)
55
- hash = serialize_common(strict)
56
- add_request_fields(hash)
57
- hash[LOG_KEYS.fetch(:http_method)] = http_method if http_method
58
- hash[LOG_KEYS.fetch(:path)] = path if path
59
- hash[LOG_KEYS.fetch(:format)] = format if format
60
- hash[LOG_KEYS.fetch(:controller)] = controller if controller
61
- hash[LOG_KEYS.fetch(:action)] = action if action
62
- hash[LOG_KEYS.fetch(:status)] = status if status
63
- hash[LOG_KEYS.fetch(:duration)] = duration if duration
64
- hash[LOG_KEYS.fetch(:view)] = view if view
65
- hash[LOG_KEYS.fetch(:db)] = db if db
66
- hash[LOG_KEYS.fetch(:params)] = params if params
67
- hash[LOG_KEYS.fetch(:source_ip)] = source_ip if source_ip
68
- hash[LOG_KEYS.fetch(:user_agent)] = user_agent if user_agent
69
- hash[LOG_KEYS.fetch(:referer)] = referer if referer
70
- hash[LOG_KEYS.fetch(:request_id)] = request_id if request_id
53
+ # Additional data
54
+
55
+ # Request fields (optional)
56
+ include LogStruct::Log::Interfaces::RequestFields
57
+
58
+ # Serialize shared fields
59
+ include LogStruct::Log::Interfaces::CommonFields
60
+ include LogStruct::Log::Shared::SerializeCommon
61
+ include LogStruct::Log::Shared::AddRequestFields
62
+
63
+ sig {
64
+ params(path: T.untyped,
65
+ http_method: T.untyped,
66
+ source_ip: T.untyped,
67
+ user_agent: T.untyped,
68
+ referer: T.untyped,
69
+ request_id: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
70
+ }
71
+ def self.base_hash(path: nil,
72
+ http_method: nil,
73
+ source_ip: nil,
74
+ user_agent: nil,
75
+ referer: nil,
76
+ request_id: nil)
77
+ h = {}
78
+ h[LogField::Path] = path unless path.nil?
79
+ h[LogField::HttpMethod] = http_method unless http_method.nil?
80
+ h[LogField::SourceIp] = source_ip unless source_ip.nil?
81
+ h[LogField::UserAgent] = user_agent unless user_agent.nil?
82
+ h[LogField::Referer] = referer unless referer.nil?
83
+ h[LogField::RequestId] = request_id unless request_id.nil?
84
+ h
85
+ end
86
+
87
+ sig {
88
+ params(path: T.untyped,
89
+ http_method: T.untyped,
90
+ source_ip: T.untyped,
91
+ user_agent: T.untyped,
92
+ referer: T.untyped,
93
+ request_id: T.untyped,
94
+ format: T.untyped,
95
+ controller: T.untyped,
96
+ action: T.untyped,
97
+ status: T.untyped,
98
+ duration_ms: T.untyped,
99
+ view: T.untyped,
100
+ database: T.untyped,
101
+ params: T.untyped,
102
+ additional_data: T.untyped,
103
+ timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
104
+ }
105
+ def self.build(path: nil,
106
+ http_method: nil,
107
+ source_ip: nil,
108
+ user_agent: nil,
109
+ referer: nil,
110
+ request_id: nil,
111
+ format: nil,
112
+ controller: nil,
113
+ action: nil,
114
+ status: nil,
115
+ duration_ms: nil,
116
+ view: nil,
117
+ database: nil,
118
+ params: nil,
119
+ additional_data: nil,
120
+ timestamp: Time.now)
121
+ h = base_hash(path: path,
122
+ http_method: http_method,
123
+ source_ip: source_ip,
124
+ user_agent: user_agent,
125
+ referer: referer,
126
+ request_id: request_id)
127
+ h[LogField::Format] = format unless format.nil?
128
+ h[LogField::Controller] = controller unless controller.nil?
129
+ h[LogField::Action] = action unless action.nil?
130
+ h[LogField::Status] = status unless status.nil?
131
+ h[LogField::DurationMs] = duration_ms unless duration_ms.nil?
132
+ h[LogField::View] = view unless view.nil?
133
+ h[LogField::Database] = database unless database.nil?
134
+ h[LogField::Params] = params unless params.nil?
135
+ h
136
+ end
71
137
 
72
- hash
138
+ sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
139
+ def to_h
140
+ self.class.build(
141
+ path: path,
142
+ http_method: http_method,
143
+ source_ip: source_ip,
144
+ user_agent: user_agent,
145
+ referer: referer,
146
+ request_id: request_id,
147
+ format: format,
148
+ controller: controller,
149
+ action: action,
150
+ status: status,
151
+ duration_ms: duration_ms,
152
+ view: view,
153
+ database: database,
154
+ params: params,
155
+ timestamp: timestamp
156
+ )
73
157
  end
74
158
  end
75
159
  end
@@ -0,0 +1,141 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ # AUTO-GENERATED: DO NOT EDIT
5
+ # Generated by scripts/generate_structs.rb
6
+ # Schemas dir: schemas/log_sources/
7
+ # Template: tools/codegen/templates/sorbet/event.rb.erb
8
+
9
+ require "log_struct/shared/interfaces/common_fields"
10
+ require "log_struct/shared/interfaces/additional_data_field"
11
+ require "log_struct/shared/interfaces/request_fields"
12
+ require "log_struct/shared/shared/serialize_common"
13
+ require "log_struct/shared/shared/merge_additional_data_fields"
14
+ require "log_struct/shared/shared/add_request_fields"
15
+ require_relative "../../enums/source"
16
+ require_relative "../../enums/event"
17
+ require_relative "../../enums/level"
18
+ require_relative "../../enums/log_field"
19
+
20
+ module LogStruct
21
+ module Log
22
+ class Security
23
+ class BlockedHost < T::Struct
24
+ # typed: strict
25
+ # frozen_string_literal: true
26
+
27
+ extend T::Sig
28
+
29
+ extend T::Sig
30
+
31
+ # Shared/common fields
32
+ const :source, Source::Security, default: Source::Security
33
+ const :event, Event, default: Event::BlockedHost
34
+ const :timestamp, Time, factory: -> { Time.now }
35
+ const :level, Level, default: Level::Info
36
+
37
+ const :path, T.nilable(String), default: nil
38
+ const :http_method, T.nilable(String), default: nil
39
+ const :source_ip, T.nilable(String), default: nil
40
+ const :user_agent, T.nilable(String), default: nil
41
+ const :referer, T.nilable(String), default: nil
42
+ const :request_id, T.nilable(String), default: nil
43
+
44
+ # Event-specific fields
45
+ const :message, T.nilable(String), default: nil
46
+ const :blocked_host, T.nilable(String), default: nil
47
+ const :blocked_hosts, T.nilable(T::Array[String]), default: nil
48
+
49
+ # Additional data
50
+ include LogStruct::Log::Interfaces::AdditionalDataField
51
+ const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
52
+ include LogStruct::Log::Shared::MergeAdditionalDataFields
53
+
54
+ # Request fields (optional)
55
+ include LogStruct::Log::Interfaces::RequestFields
56
+
57
+ # Serialize shared fields
58
+ include LogStruct::Log::Interfaces::CommonFields
59
+ include LogStruct::Log::Shared::SerializeCommon
60
+ include LogStruct::Log::Shared::AddRequestFields
61
+
62
+ sig {
63
+ params(path: T.untyped,
64
+ http_method: T.untyped,
65
+ source_ip: T.untyped,
66
+ user_agent: T.untyped,
67
+ referer: T.untyped,
68
+ request_id: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
69
+ }
70
+ def self.base_hash(path: nil,
71
+ http_method: nil,
72
+ source_ip: nil,
73
+ user_agent: nil,
74
+ referer: nil,
75
+ request_id: nil)
76
+ h = {}
77
+ h[LogField::Path] = path unless path.nil?
78
+ h[LogField::HttpMethod] = http_method unless http_method.nil?
79
+ h[LogField::SourceIp] = source_ip unless source_ip.nil?
80
+ h[LogField::UserAgent] = user_agent unless user_agent.nil?
81
+ h[LogField::Referer] = referer unless referer.nil?
82
+ h[LogField::RequestId] = request_id unless request_id.nil?
83
+ h
84
+ end
85
+
86
+ sig {
87
+ params(path: T.untyped,
88
+ http_method: T.untyped,
89
+ source_ip: T.untyped,
90
+ user_agent: T.untyped,
91
+ referer: T.untyped,
92
+ request_id: T.untyped,
93
+ message: T.untyped,
94
+ blocked_host: T.untyped,
95
+ blocked_hosts: T.untyped,
96
+ additional_data: T.untyped,
97
+ timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
98
+ }
99
+ def self.build(path: nil,
100
+ http_method: nil,
101
+ source_ip: nil,
102
+ user_agent: nil,
103
+ referer: nil,
104
+ request_id: nil,
105
+ message: nil,
106
+ blocked_host: nil,
107
+ blocked_hosts: nil,
108
+ additional_data: nil,
109
+ timestamp: Time.now)
110
+ h = base_hash(path: path,
111
+ http_method: http_method,
112
+ source_ip: source_ip,
113
+ user_agent: user_agent,
114
+ referer: referer,
115
+ request_id: request_id)
116
+ h[LogField::Message] = message unless message.nil?
117
+ h[LogField::BlockedHost] = blocked_host unless blocked_host.nil?
118
+ h[LogField::BlockedHosts] = blocked_hosts unless blocked_hosts.nil?
119
+ h
120
+ end
121
+
122
+ sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
123
+ def to_h
124
+ self.class.build(
125
+ path: path,
126
+ http_method: http_method,
127
+ source_ip: source_ip,
128
+ user_agent: user_agent,
129
+ referer: referer,
130
+ request_id: request_id,
131
+ message: message,
132
+ blocked_host: blocked_host,
133
+ blocked_hosts: blocked_hosts,
134
+ additional_data: additional_data,
135
+ timestamp: timestamp
136
+ )
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,131 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ # AUTO-GENERATED: DO NOT EDIT
5
+ # Generated by scripts/generate_structs.rb
6
+ # Schemas dir: schemas/log_sources/
7
+ # Template: tools/codegen/templates/sorbet/event.rb.erb
8
+
9
+ require "log_struct/shared/interfaces/common_fields"
10
+ require "log_struct/shared/interfaces/additional_data_field"
11
+ require "log_struct/shared/interfaces/request_fields"
12
+ require "log_struct/shared/shared/serialize_common"
13
+ require "log_struct/shared/shared/merge_additional_data_fields"
14
+ require "log_struct/shared/shared/add_request_fields"
15
+ require_relative "../../enums/source"
16
+ require_relative "../../enums/event"
17
+ require_relative "../../enums/level"
18
+ require_relative "../../enums/log_field"
19
+
20
+ module LogStruct
21
+ module Log
22
+ class Security
23
+ class CSRFViolation < T::Struct
24
+ # typed: strict
25
+ # frozen_string_literal: true
26
+
27
+ extend T::Sig
28
+
29
+ extend T::Sig
30
+
31
+ # Shared/common fields
32
+ const :source, Source::Security, default: Source::Security
33
+ const :event, Event, default: Event::CSRFViolation
34
+ const :timestamp, Time, factory: -> { Time.now }
35
+ const :level, Level, default: Level::Info
36
+
37
+ const :path, T.nilable(String), default: nil
38
+ const :http_method, T.nilable(String), default: nil
39
+ const :source_ip, T.nilable(String), default: nil
40
+ const :user_agent, T.nilable(String), default: nil
41
+ const :referer, T.nilable(String), default: nil
42
+ const :request_id, T.nilable(String), default: nil
43
+
44
+ # Event-specific fields
45
+ const :message, T.nilable(String), default: nil
46
+
47
+ # Additional data
48
+ include LogStruct::Log::Interfaces::AdditionalDataField
49
+ const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
50
+ include LogStruct::Log::Shared::MergeAdditionalDataFields
51
+
52
+ # Request fields (optional)
53
+ include LogStruct::Log::Interfaces::RequestFields
54
+
55
+ # Serialize shared fields
56
+ include LogStruct::Log::Interfaces::CommonFields
57
+ include LogStruct::Log::Shared::SerializeCommon
58
+ include LogStruct::Log::Shared::AddRequestFields
59
+
60
+ sig {
61
+ params(path: T.untyped,
62
+ http_method: T.untyped,
63
+ source_ip: T.untyped,
64
+ user_agent: T.untyped,
65
+ referer: T.untyped,
66
+ request_id: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
67
+ }
68
+ def self.base_hash(path: nil,
69
+ http_method: nil,
70
+ source_ip: nil,
71
+ user_agent: nil,
72
+ referer: nil,
73
+ request_id: nil)
74
+ h = {}
75
+ h[LogField::Path] = path unless path.nil?
76
+ h[LogField::HttpMethod] = http_method unless http_method.nil?
77
+ h[LogField::SourceIp] = source_ip unless source_ip.nil?
78
+ h[LogField::UserAgent] = user_agent unless user_agent.nil?
79
+ h[LogField::Referer] = referer unless referer.nil?
80
+ h[LogField::RequestId] = request_id unless request_id.nil?
81
+ h
82
+ end
83
+
84
+ sig {
85
+ params(path: T.untyped,
86
+ http_method: T.untyped,
87
+ source_ip: T.untyped,
88
+ user_agent: T.untyped,
89
+ referer: T.untyped,
90
+ request_id: T.untyped,
91
+ message: T.untyped,
92
+ additional_data: T.untyped,
93
+ timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
94
+ }
95
+ def self.build(path: nil,
96
+ http_method: nil,
97
+ source_ip: nil,
98
+ user_agent: nil,
99
+ referer: nil,
100
+ request_id: nil,
101
+ message: nil,
102
+ additional_data: nil,
103
+ timestamp: Time.now)
104
+ h = base_hash(path: path,
105
+ http_method: http_method,
106
+ source_ip: source_ip,
107
+ user_agent: user_agent,
108
+ referer: referer,
109
+ request_id: request_id)
110
+ h[LogField::Message] = message unless message.nil?
111
+ h
112
+ end
113
+
114
+ sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
115
+ def to_h
116
+ self.class.build(
117
+ path: path,
118
+ http_method: http_method,
119
+ source_ip: source_ip,
120
+ user_agent: user_agent,
121
+ referer: referer,
122
+ request_id: request_id,
123
+ message: message,
124
+ additional_data: additional_data,
125
+ timestamp: timestamp
126
+ )
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,141 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ # AUTO-GENERATED: DO NOT EDIT
5
+ # Generated by scripts/generate_structs.rb
6
+ # Schemas dir: schemas/log_sources/
7
+ # Template: tools/codegen/templates/sorbet/event.rb.erb
8
+
9
+ require "log_struct/shared/interfaces/common_fields"
10
+ require "log_struct/shared/interfaces/additional_data_field"
11
+ require "log_struct/shared/interfaces/request_fields"
12
+ require "log_struct/shared/shared/serialize_common"
13
+ require "log_struct/shared/shared/merge_additional_data_fields"
14
+ require "log_struct/shared/shared/add_request_fields"
15
+ require_relative "../../enums/source"
16
+ require_relative "../../enums/event"
17
+ require_relative "../../enums/level"
18
+ require_relative "../../enums/log_field"
19
+
20
+ module LogStruct
21
+ module Log
22
+ class Security
23
+ class IPSpoof < T::Struct
24
+ # typed: strict
25
+ # frozen_string_literal: true
26
+
27
+ extend T::Sig
28
+
29
+ extend T::Sig
30
+
31
+ # Shared/common fields
32
+ const :source, Source::Security, default: Source::Security
33
+ const :event, Event, default: Event::IPSpoof
34
+ const :timestamp, Time, factory: -> { Time.now }
35
+ const :level, Level, default: Level::Info
36
+
37
+ const :path, T.nilable(String), default: nil
38
+ const :http_method, T.nilable(String), default: nil
39
+ const :source_ip, T.nilable(String), default: nil
40
+ const :user_agent, T.nilable(String), default: nil
41
+ const :referer, T.nilable(String), default: nil
42
+ const :request_id, T.nilable(String), default: nil
43
+
44
+ # Event-specific fields
45
+ const :message, T.nilable(String), default: nil
46
+ const :client_ip, T.nilable(String), default: nil
47
+ const :x_forwarded_for, T.nilable(String), default: nil
48
+
49
+ # Additional data
50
+ include LogStruct::Log::Interfaces::AdditionalDataField
51
+ const :additional_data, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]), default: nil
52
+ include LogStruct::Log::Shared::MergeAdditionalDataFields
53
+
54
+ # Request fields (optional)
55
+ include LogStruct::Log::Interfaces::RequestFields
56
+
57
+ # Serialize shared fields
58
+ include LogStruct::Log::Interfaces::CommonFields
59
+ include LogStruct::Log::Shared::SerializeCommon
60
+ include LogStruct::Log::Shared::AddRequestFields
61
+
62
+ sig {
63
+ params(path: T.untyped,
64
+ http_method: T.untyped,
65
+ source_ip: T.untyped,
66
+ user_agent: T.untyped,
67
+ referer: T.untyped,
68
+ request_id: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
69
+ }
70
+ def self.base_hash(path: nil,
71
+ http_method: nil,
72
+ source_ip: nil,
73
+ user_agent: nil,
74
+ referer: nil,
75
+ request_id: nil)
76
+ h = {}
77
+ h[LogField::Path] = path unless path.nil?
78
+ h[LogField::HttpMethod] = http_method unless http_method.nil?
79
+ h[LogField::SourceIp] = source_ip unless source_ip.nil?
80
+ h[LogField::UserAgent] = user_agent unless user_agent.nil?
81
+ h[LogField::Referer] = referer unless referer.nil?
82
+ h[LogField::RequestId] = request_id unless request_id.nil?
83
+ h
84
+ end
85
+
86
+ sig {
87
+ params(path: T.untyped,
88
+ http_method: T.untyped,
89
+ source_ip: T.untyped,
90
+ user_agent: T.untyped,
91
+ referer: T.untyped,
92
+ request_id: T.untyped,
93
+ message: T.untyped,
94
+ client_ip: T.untyped,
95
+ x_forwarded_for: T.untyped,
96
+ additional_data: T.untyped,
97
+ timestamp: T.untyped).returns(T::Hash[LogStruct::LogField, T.untyped])
98
+ }
99
+ def self.build(path: nil,
100
+ http_method: nil,
101
+ source_ip: nil,
102
+ user_agent: nil,
103
+ referer: nil,
104
+ request_id: nil,
105
+ message: nil,
106
+ client_ip: nil,
107
+ x_forwarded_for: nil,
108
+ additional_data: nil,
109
+ timestamp: Time.now)
110
+ h = base_hash(path: path,
111
+ http_method: http_method,
112
+ source_ip: source_ip,
113
+ user_agent: user_agent,
114
+ referer: referer,
115
+ request_id: request_id)
116
+ h[LogField::Message] = message unless message.nil?
117
+ h[LogField::ClientIp] = client_ip unless client_ip.nil?
118
+ h[LogField::XForwardedFor] = x_forwarded_for unless x_forwarded_for.nil?
119
+ h
120
+ end
121
+
122
+ sig { returns(T::Hash[LogStruct::LogField, T.untyped]) }
123
+ def to_h
124
+ self.class.build(
125
+ path: path,
126
+ http_method: http_method,
127
+ source_ip: source_ip,
128
+ user_agent: user_agent,
129
+ referer: referer,
130
+ request_id: request_id,
131
+ message: message,
132
+ client_ip: client_ip,
133
+ x_forwarded_for: x_forwarded_for,
134
+ additional_data: additional_data,
135
+ timestamp: timestamp
136
+ )
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end