Class: Ci::SecureFile

Inherits:
ApplicationRecord show all
Includes:
FileStoreMounter, Limitable
Defined in:
app/models/ci/secure_file.rb

Constant Summary collapse

FILE_SIZE_LIMIT =
5.megabytes.freeze
CHECKSUM_ALGORITHM =
'sha256'
PARSABLE_EXTENSIONS =
%w[cer p12 mobileprovision].freeze

Constants included from Limitable

Limitable::GLOBAL_SCOPE

Constants included from FileStoreMounter

FileStoreMounter::ALLOWED_FILE_FIELDS

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Method Summary collapse

Methods included from Limitable

#exceeds_limits?

Methods inherited from ApplicationRecord

model_name, table_name_prefix

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Instance Method Details

#checksum_algorithmObject



34
35
36
# File 'app/models/ci/secure_file.rb', line 34

def checksum_algorithm
  CHECKSUM_ALGORITHM
end

#file_extensionObject



38
39
40
# File 'app/models/ci/secure_file.rb', line 38

def file_extension
  File.extname(name).delete_prefix('.').presence
end

#local?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/ci/secure_file.rb', line 73

def local?
  file_store == ObjectStorage::Store::LOCAL
end

#metadata_parsable?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/ci/secure_file.rb', line 42

def 
  PARSABLE_EXTENSIONS.include?(file_extension)
end

#metadata_parserObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/ci/secure_file.rb', line 46

def 
  return unless 

  case file_extension
  when 'cer'
    Gitlab::Ci::SecureFiles::Cer.new(file.read)
  when 'p12'
    Gitlab::Ci::SecureFiles::P12.new(file.read)
  when 'mobileprovision'
    Gitlab::Ci::SecureFiles::MobileProvision.new(file.read)
  end
end

#update_metadata!Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/ci/secure_file.rb', line 59

def update_metadata!
  return unless 

  begin
    parser = 
    self. = parser.
    self.expires_at = parser.[:expires_at]
    save!
  rescue StandardError => err
    Gitlab::AppLogger.error("Secure File Parser Failure (#{id}): #{err.message} - #{parser.error}.")
    nil
  end
end