summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/external/file/remote.rb
blob: 59bb3e8999e57a3a93f00c3cb75746fca0ae532c (plain)
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
# frozen_string_literal: true

module Gitlab
  module Ci
    module External
      module File
        class Remote < Base
          include Gitlab::Utils::StrongMemoize
          attr_reader :location

          def content
            return @content if defined?(@content)

            @content = strong_memoize(:content) do
              begin
                Gitlab::HTTP.get(location)
              rescue Gitlab::HTTP::Error, Timeout::Error, SocketError, Gitlab::HTTP::BlockedUrlError
                nil
              end
            end
          end

          def error_message
            "Remote file '#{location}' is not valid."
          end
        end
      end
    end
  end
end