-
Notifications
You must be signed in to change notification settings - Fork 381
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 #2771 from DataDog/remote-populate-config-states
[APPSEC-8957] Populate remote client cached_target_files payload field
- Loading branch information
Showing
12 changed files
with
373 additions
and
88 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
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,60 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module Core | ||
module Remote | ||
class Configuration | ||
# Represent a list of Configuration::Digest | ||
class DigestList < Array | ||
class << self | ||
def parse(hash) | ||
new.concat(hash.map { |type, hexdigest| Digest.new(type, hexdigest) }) | ||
end | ||
end | ||
|
||
def check(content) | ||
map { |digest| digest.check(content) }.reduce(:&) | ||
end | ||
end | ||
|
||
# Stores and validates different cryptographic hash functions | ||
class Digest | ||
class InvalidHashTypeError < StandardError; end | ||
attr_reader :type, :hexdigest | ||
|
||
DIGEST_CHUNK = 1024 | ||
|
||
class << self | ||
def hexdigest(type, data) | ||
d = case type | ||
when :sha256 | ||
::Digest::SHA256.new | ||
when :sha512 | ||
::Digest::SHA512.new | ||
else | ||
raise InvalidHashTypeError, type | ||
end | ||
|
||
while (buf = data.read(DIGEST_CHUNK)) | ||
d.update(buf) | ||
end | ||
|
||
d.hexdigest | ||
ensure | ||
data.rewind | ||
end | ||
end | ||
|
||
def initialize(type, hexdigest) | ||
@type = type.to_sym | ||
@hexdigest = hexdigest | ||
end | ||
|
||
def check(content) | ||
content.hexdigest(@type) == hexdigest | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
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
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,30 @@ | ||
module Datadog | ||
module Core | ||
module Remote | ||
class Configuration | ||
class DigestList < Array[Digest] | ||
def self.parse: (::Hash[::String, untyped] hash) -> DigestList | ||
|
||
def check: (Datadog::Core::Remote::Configuration::Content content) -> bool | ||
end | ||
|
||
class Digest | ||
class InvalidHashTypeError < StandardError | ||
end | ||
|
||
DIGEST_CHUNK: 1024 | ||
|
||
attr_reader type: ::Symbol | ||
|
||
attr_reader hexdigest: ::String | ||
|
||
def self.hexdigest: (Symbol type, StringIO data) -> String | ||
|
||
def initialize: (::String type, ::String hexdigest) -> void | ||
|
||
def check: (Datadog::Core::Remote::Configuration::Content content) -> bool | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
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
Oops, something went wrong.