Class: Gitlab::Ci::Build::Artifacts::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/build/artifacts/metadata.rb,
lib/gitlab/ci/build/artifacts/metadata/entry.rb

Defined Under Namespace

Classes: Entry, ParserError

Constant Summary collapse

VERSION_PATTERN =
/^[\w\s]+(\d+\.\d+\.\d+)/
INVALID_PATH_PATTERN =
%r{(^\.?\.?/)|(/\.?\.?/)}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, path, **opts) ⇒ Metadata


16
17
18
19
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 16

def initialize(file, path, **opts)
  @file, @path, @opts = file, path, opts
  @full_version = read_version
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file


14
15
16
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 14

def file
  @file
end

#full_versionObject (readonly)

Returns the value of attribute full_version


14
15
16
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 14

def full_version
  @full_version
end

#pathObject (readonly)

Returns the value of attribute path


14
15
16
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 14

def path
  @path
end

Instance Method Details

#errorsObject


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 25

def errors
  gzip do |gz|
    read_string(gz) # version
    errors = read_string(gz)
    raise ParserError, 'Errors field not found!' unless errors

    begin
      JSON.parse(errors)
    rescue JSON::ParserError
      raise ParserError, 'Invalid errors field!'
    end
  end
end

#find_entries!Object


39
40
41
42
43
44
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 39

def find_entries!
  gzip do |gz|
    2.times { read_string(gz) } # version and errors fields
    match_entries(gz)
  end
end

#to_entryObject


46
47
48
49
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 46

def to_entry
  entries = find_entries!
  Entry.new(@path, entries)
end

#versionObject


21
22
23
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 21

def version
  @full_version.match(VERSION_PATTERN)[1]
end