Skip to content

Commit

Permalink
Use license last_validated_attributes in validation service
Browse files Browse the repository at this point in the history
In the previous commit, the "touches" behaviour from the validation service was moved into the License model.

This commit updates the ValidationService to use these new methods on the License model

Signed-off-by: Bodacious <[email protected]>
  • Loading branch information
Bodacious committed Jan 25, 2025
1 parent 9955953 commit 4302181
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions app/services/license_validation_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ def initialize(license:, scope: nil, skip_touch: false)
@license = license
@scope = scope
@skip_touch = skip_touch
@touches = {
last_validated_at: Time.current,
}
self.license.set_last_validated_attributes(last_validated_at: Time.current)
end

def call
Expand All @@ -24,8 +22,7 @@ def call
attr_reader :account,
:product,
:license,
:scope,
:touches
:scope

def skip_touch? = !!@skip_touch

Expand Down Expand Up @@ -230,8 +227,8 @@ def validate!
return [false, "checksum scope is not valid (does not match any accessible artifacts)", :CHECKSUM_SCOPE_MISMATCH]
end

touches[:last_validated_checksum] = checksum
touches[:last_validated_version] = artifact.version
license.set_last_validated_attributes(last_validated_checksum: checksum,
last_validated_version: artifact.version)
else
return [false, "checksum scope is required", :CHECKSUM_SCOPE_REQUIRED] if license.policy.require_checksum_scope?
end
Expand All @@ -247,8 +244,7 @@ def validate!
if release.nil?
return [false, "version scope is not valid (does not match any accessible releases)", :VERSION_SCOPE_MISMATCH]
end

touches[:last_validated_version] = release.version
license.set_last_validated_attributes(last_validated_version: release.version)
else
return [false, "version scope is required", :VERSION_SCOPE_REQUIRED] if license.policy.require_version_scope?
end
Expand Down Expand Up @@ -418,13 +414,8 @@ def validate!
end

def touch!
return if
skip_touch? || license.nil? || touches.empty?

# Attempt to store touches in database
TouchLicenseWorker.perform_async(license.id, touches.as_json)
return if skip_touch? || license.nil?

# Store in-memory for response
license.assign_attributes(**touches)
license.persist_last_validated_attributes!
end
end

0 comments on commit 4302181

Please sign in to comment.