firetail-rails 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ce1eb2ebda2bffb7959cd23fe33e226a32cd39b103e74d09489d04f953f6992a
4
+ data.tar.gz: 3da8f3bbfbd4b3e838017c042c8bce17e4069e28f6510149ff354b6eb3fe1610
5
+ SHA512:
6
+ metadata.gz: 22f935be0e43e9e93d2d3ad81fad2c08445773e9d74674d813062407802c05727aab7aac4a407f8c29ad0e61a7d710e0d4d8c3d726196a67c9cb0ae38bacb9cc
7
+ data.tar.gz: 48281d84583cb5948aac646bd084d1ad7ce7ceac2fa50f4b3bb268be0d5efbd05270175d0501396ed8da2d70f5af9e886c1df2799e5513410c2aa060acfe5729
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.8
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at muhammad@taqisystems.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in firetail.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/LICENSE.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Firetail
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/firetail`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'firetail'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install firetail
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/firetail. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Firetail project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/firetail/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "firetail"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "firetail-rails/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "firetail-rails"
7
+ spec.version = Firetail::VERSION
8
+ spec.authors = ["Muhammad Nuzaihan"]
9
+ spec.email = ["zaihan@flitnetics.com"]
10
+
11
+ spec.summary = %q{Ruby On Rails library for firetail}
12
+ spec.description = %q{API security library that is designed for ruby}
13
+ spec.homepage = "https://www.firetail.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/firetail-io/ruby"
20
+ spec.metadata["changelog_uri"] = "https://github.com/firetail-io/ruby/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+
35
+ # These gems are needed for firetail in production
36
+ spec.add_dependency "async", "~> 1.30.3"
37
+ end
@@ -0,0 +1,29 @@
1
+ class CustomPost < Net::HTTP::Post
2
+ def initialize_http_header(headers)
3
+ @header = {}
4
+ headers.each { |k, v| @header[k.to_s] = [v] }
5
+ end
6
+
7
+ def [](name)
8
+ _k, val = header_insensitive_match name
9
+ val
10
+ end
11
+
12
+ def []=(name, val)
13
+ key, _val = header_insensitive_match name
14
+ key = name if key.nil?
15
+ if val
16
+ @header[key] = [val]
17
+ else
18
+ @header.delete(key)
19
+ end
20
+ end
21
+
22
+ def capitalize(name)
23
+ name
24
+ end
25
+
26
+ def header_insensitive_match(name)
27
+ @header.find { |key, _value| key.match Regexp.new(name.to_s, Regexp::IGNORECASE) }
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Firetail
2
+ VERSION = "0.0.0"
3
+ end
@@ -0,0 +1,212 @@
1
+ require "firetail/version"
2
+ require "rack"
3
+ require 'objspace'
4
+ require 'yaml'
5
+ require 'json'
6
+ require 'net/http'
7
+ require 'case_sensitive_headers' # a hack because firetail API headers is case-sensitive
8
+ require "async"
9
+
10
+ module Firetail
11
+ class Error < StandardError; end
12
+
13
+ class Run
14
+ MAX_BULK_SIZE_IN_BYTES = 1 * 1024 * 1024 # 1 MB
15
+
16
+ def initialize app
17
+ @app = app
18
+ @reqres ||= [] # request data in stored in array memory
19
+ @init_time ||= Time.now # initialize time
20
+ end
21
+
22
+ def call(env)
23
+ # This block initialises the configuration and checks
24
+ # sets the values for certain necessary configuration
25
+ # If it is Rails
26
+ if defined?(Rails)
27
+ begin
28
+ default_location = File.join(Rails.root, "config/firetail.yml")
29
+ config = YAML.load_file(default_location)
30
+ rescue Errno::ENOENT
31
+ # error message if firetail is not installed
32
+ puts ""
33
+ puts "Please run 'rails generate firetail:install' first"
34
+ puts ""
35
+ end
36
+ else # other frameworks
37
+ config = YAML.load_file("firetail.yml")
38
+ end
39
+
40
+ raise Error.new "Please run 'rails generate firetail:install' first" if config.nil?
41
+ raise Error.new "Token is missing from firetail.yml configuration" if config['token'].nil?
42
+ raise Error.new "API Key is missing from firetail.yml configuration" if config['api_key'].nil?
43
+
44
+ @token = config['token']
45
+ @api_key = config['api_key']
46
+ @url = config['url'] ? config['url'] : "https://ingest.eu-west-1.dev.firetail.app/ingest/request" # default goes to dev
47
+ @log_drains_timeout = config['log_drains_timeout'] ? config['log_drains_timeout'] : 5
48
+ @network_timeout = config['network_timeout'] ? config['network_timeout'] : 10
49
+ @number_of_retries = config['number_of_retries'] ? config['number_of_retries'] : 4
50
+ @retry_timeout = config['retry_timeout'] ? config['retry_timeout'] : 2
51
+ # End of configuration initialization
52
+
53
+ # Gets the rack middleware requests
54
+ request = Rack::Request.new(env)
55
+ started_on = Time.now
56
+ begin
57
+ status, res_headers, body = response = @app.call(env)
58
+ log(env, response, status, res_headers, body, started_on, Time.now)
59
+ rescue Exception => exception
60
+ log(env, response, status, res_headers, body, started_on, Time.now, exception)
61
+ raise exception
62
+ end
63
+
64
+ response
65
+ end
66
+
67
+ def log(env,
68
+ response,
69
+ status,
70
+ res_headers,
71
+ body,
72
+ started_on,
73
+ ended_on,
74
+ exception = nil)
75
+
76
+ # request values
77
+ req_url = env['REQUEST_URI']
78
+ req_path = env['PATH_INFO']
79
+ time_spent = ended_on - started_on
80
+ req_user_agent = env['HTTP_USER_AGENT']
81
+ req_ip = defined?(Rails) ? env['action_dispatch.remote_ip'].calculate_ip : env['REMOTE_ADDR']
82
+ req_method = env['REQUEST_METHOD']
83
+ req_http_host = env['HTTP_HOST']
84
+ req_http_version = env['HTTP_VERSION']
85
+ req_http_encoding = env['HTTP_ACCEPT_ENCODING']
86
+ req_http_accept = env['HTTP_ACCEPT']
87
+ req_query_string = env['QUERY_STRING']
88
+ req_path = env['REQUEST_PATH']
89
+ req_uri = env['REQUEST_URI']
90
+ req_server_software = env['SERVER_SOFTWARE']
91
+ req_server_port = env['SERVER_PORT']
92
+ req_gateway_interface = env['GATEWAY_INTERFACE']
93
+ req_http_connection = env['HTTP_CONNECTION']
94
+
95
+ # get the request "HTTP_" headers
96
+ req_headers = env.select {|k,v| k.start_with? 'HTTP_'}
97
+ .collect {|key, val| [key.sub(/^HTTP_/, ''), val]}
98
+ .collect {|key, val| "#{key}: #{val}<br>"}
99
+ .sort
100
+
101
+ # add the request and response data
102
+ # to array of data for batching up
103
+ @reqres.push({
104
+ version: "1.1",
105
+ dateCreated: Time.now.utc.to_i,
106
+ execution_time: time_spent,
107
+ #dateCreated: 1663763942581,
108
+ #execution_time: 3.74,
109
+ req: {
110
+ httpProtocol: req_http_version,
111
+ headers: req_headers.to_s,
112
+ path: req_path,
113
+ method: req_method,
114
+ oPath: req_path,
115
+ fPath: req_path,
116
+ args: req_query_string,
117
+ ip: req_ip,
118
+ pathParams: req_path,
119
+ user_agent: req_user_agent # maybe need this?
120
+ },
121
+ resp: {
122
+ status_code: status,
123
+ content_len: res_headers['Content-Length'],
124
+ content_enc: res_headers['Content-Encoding'],
125
+ body: body ? body.body : body[0],
126
+ headers: res_headers.to_s,
127
+ content_type: res_headers['Content-Type'],
128
+ error_type: exception&.class&.name, # maybe need this?
129
+ error_message: exception&.message # maybe need this? can be removed
130
+ }
131
+ })
132
+
133
+ # the time we calculate if request that is
134
+ # buffered max is 120 seconds
135
+ current_time = Time.now
136
+ # duration in millseconds
137
+ duration = (current_time - @init_time) * 1000.0
138
+
139
+ #Firetail.logger.debug "size in bytes #{ObjectSpace.memsize_of(@request_data.to_s)}"
140
+ #request data size in bytes
141
+ #request_data_size = ObjectSpace.memsize_of(@request_data.to_s)
142
+ # It is difficult to calculate the object size in bytes,
143
+ # seems to not return the accurate values
144
+
145
+ # This will send the data we need in batches of 5 requests or when it is more than 120 seconds
146
+ # if there are more than 5 requests or is more than
147
+ # 2 minutes, then send to backend - this is for testing
148
+ if @reqres.length >= 5 || duration > 120
149
+ #Firetail.logger.debug "request data #{@request_data.length}"
150
+ payload = "" # begin of data will have a newline
151
+ @reqres.each do |data|
152
+ # append string in-place
153
+ json = data.to_json
154
+ payload = json + "\n"
155
+ end
156
+
157
+ #puts "Our data: #{payload}"
158
+ # send the data to backend API
159
+ # This is an async task
160
+ Async do |task|
161
+ task.async do
162
+ send_to_backend(payload)
163
+ end
164
+ end
165
+
166
+ # reset back tohe conditions
167
+ payload = nil
168
+ @reqres = []
169
+ @init_time = Time.now
170
+ end
171
+ rescue Exception => exception
172
+ Firetail.logger.error(exception.message)
173
+ end
174
+
175
+ def send_to_backend(payload)
176
+ #Firetail.logger.debug datas.to_json
177
+ # Parse it as URI
178
+ uri = URI(@url)
179
+
180
+ # Send the request
181
+ http = Net::HTTP.new(uri.hostname, uri.port)
182
+ #http.set_debug_output($stdout)
183
+ http.use_ssl = true
184
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
185
+
186
+ # Create a new request
187
+ req = CustomPost.new(uri.path,
188
+ {
189
+ 'Content-Type': 'text/plain',
190
+ 'x-api-key': @api_key,
191
+ 'X-FT-API-KEY': @token
192
+ })
193
+
194
+ # debug code
195
+ #req.body = "{\"version\": \"1.1\", \"dateCreated\": 1663763942581, \"execution_time\": 3.74, \"req\": {}, \"resp\": {}}"
196
+ #req.body = '{"version": "1.1", "dateCreated": 1663763942581, "execution_time": 3.74, "req": {}, "resp": {}}\n{"version": "1.1", "dateCreated": 1663763942581, "execution_time": 3.74, "req": {}, "resp": {}}'
197
+ req.body = payload
198
+
199
+ res = http.request(req)
200
+
201
+ Firetail.logger.debug "response from firetail: #{res}"
202
+ end
203
+ end
204
+
205
+ def self.logger
206
+ @@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
207
+ end
208
+
209
+ def self.logger=(logger)
210
+ @@logger = logger
211
+ end
212
+ end
@@ -0,0 +1,12 @@
1
+ ====================================================================================
2
+
3
+ Thank you for installing Firetail!
4
+
5
+ Before you start using firetail, please edit the file in "config/firetail.yml"
6
+ with your API Key, Token and URL first before running your Rails app.
7
+
8
+ The middleware is already configured in "config/application.rb" (you can check that)
9
+
10
+ Happy coding!
11
+
12
+ - From the team at Firetail
@@ -0,0 +1,3 @@
1
+ api_key: yourfiretailapikey
2
+ token: yourfiretailtoken
3
+ url: https://ingest.eu-west-1.dev.firetail.app/ingest/request
@@ -0,0 +1,22 @@
1
+ module Firetail
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../install/templates", __FILE__)
5
+
6
+ desc "create firetail configuration template to config/firetail.yml and add middleware"
7
+ def add_firetail_configuration
8
+ template "firetail.yml", File.join("config", "firetail.yml")
9
+ application "config.middleware.use Firetail::Run"
10
+ end
11
+
12
+ desc "add firetail middleware to rails application.rb"
13
+ def add_firetail_middleware
14
+ application "config.middleware.use Firetail::Run"
15
+ end
16
+
17
+ def show_readme
18
+ readme "README" if behavior == :invoke
19
+ end
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firetail-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Muhammad Nuzaihan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: async
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.30.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.30.3
69
+ description: API security library that is designed for ruby
70
+ email:
71
+ - zaihan@flitnetics.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - firetail-rails.gemspec
88
+ - lib/case_sensitive_headers.rb
89
+ - lib/firetail-rails.rb
90
+ - lib/firetail-rails/version.rb
91
+ - lib/generators/firetail/install/templates/README
92
+ - lib/generators/firetail/install/templates/firetail.yml
93
+ - lib/generators/firetail/install_generator.rb
94
+ homepage: https://www.firetail.io
95
+ licenses:
96
+ - MIT
97
+ metadata:
98
+ allowed_push_host: https://rubygems.org
99
+ homepage_uri: https://www.firetail.io
100
+ source_code_uri: https://github.com/firetail-io/ruby
101
+ changelog_uri: https://github.com/firetail-io/ruby/CHANGELOG.md
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.0.8
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Ruby On Rails library for firetail
121
+ test_files: []