summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/config/external/file/remote.rb
blob: 291fe87849c1b83db874b23a1c229b076e98a546 (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
31
32
# frozen_string_literal: true

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

            def content
              strong_memoize(:content) { fetch_remote_content }
            end

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

            private

            def fetch_remote_content
              Gitlab::HTTP.get(location)
            rescue Gitlab::HTTP::Error, Timeout::Error, SocketError, Gitlab::HTTP::BlockedUrlError
              nil
            end
          end
        end
      end
    end
  end
end