1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# frozen_string_literal: true
module Packages
module Nuget
class Symbol < ApplicationRecord
include FileStoreMounter
include ShaAttribute
include Packages::Destructible
# Used in destroying stale symbols in worker
enum :status, default: 0, processing: 1, error: 3
belongs_to :package, -> { where(package_type: :nuget) }, inverse_of: :nuget_symbols
delegate :project_id, to: :package
validates :package, :file, :file_path, :signature, :object_storage_key, :size, presence: true
validates :signature, uniqueness: { scope: :file_path }
validates :object_storage_key, uniqueness: true
sha256_attribute :file_sha256
mount_file_store_uploader SymbolUploader
before_validation :set_object_storage_key, on: :create
scope :stale, -> { where(package_id: nil) }
scope :pending_destruction, -> { stale.default }
scope :with_file_name, ->(file_name) { where(file: file_name) }
scope :with_signature, ->(signature) { where(signature: signature) }
scope :with_file_sha256, ->(checksums) { where(file_sha256: checksums) }
private
def set_object_storage_key
return unless project_id && signature
self.object_storage_key = Gitlab::HashedPath.new(
'packages', 'nuget', package_id, 'symbols', OpenSSL::Digest::SHA256.hexdigest(signature),
root_hash: project_id
).to_s
end
end
end
end
|