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

Constant Summary collapse

ParserError =
Class.new(StandardError)
InvalidStreamError =
Class.new(StandardError)
VERSION_PATTERN =
/^[\w\s]+(\d+\.\d+\.\d+)/.freeze
INVALID_PATH_PATTERN =
%r{(^\.?\.?/)|(/\.?\.?/)}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Metadata.


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

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

Instance Attribute Details

#full_versionObject (readonly)

Returns the value of attribute full_version


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

def full_version
  @full_version
end

#pathObject (readonly)

Returns the value of attribute path


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

def path
  @path
end

#streamObject (readonly)

Returns the value of attribute stream


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

def stream
  @stream
end

Instance Method Details

#errorsObject


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

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

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

#find_entries!Object


42
43
44
45
46
47
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 42

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

#to_entryObject


49
50
51
52
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 49

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

#versionObject


24
25
26
# File 'lib/gitlab/ci/build/artifacts/metadata.rb', line 24

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