Class: Vanagon::Component::Source
- Inherits:
-
Object
- Object
- Vanagon::Component::Source
- Defined in:
- lib/vanagon/component/source.rb,
lib/vanagon/component/source/git.rb,
lib/vanagon/component/source/http.rb,
lib/vanagon/component/source/local.rb,
lib/vanagon/component/source/rewrite.rb
Defined Under Namespace
Classes: Git, Http, Local, Rewrite
Constant Summary collapse
- SUPPORTED_PROTOCOLS =
%w[file http https git].freeze
Class Method Summary collapse
- .determine_source_type(uri) ⇒ Object
-
.source(uri, **options) ⇒ Vanagon::Component::Source
Basic factory to hand back the correct Source subtype to the component.
Class Method Details
.determine_source_type(uri) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vanagon/component/source.rb', line 62 def determine_source_type(uri) # if source_type isn't specified, let's try to figure out what we have # order of precedence for this is git, then http, then local # Add a 5 second timeout for the `git remote-ls` execution to deal with # URLs that incorrectly respond to git queries timeout = 5 if Vanagon::Component::Source::Git.valid_remote?(uri, timeout) if uri =~ /^http/ VanagonLogger.info "Passing git URLs as http(s) addresses is deprecated! Please prefix your source URL with `git:`" end return :git end if Vanagon::Component::Source::Http.valid_url?(uri) return :http end if Vanagon::Component::Source::Local.valid_file?(uri) return :local end return :unknown end |
.source(uri, **options) ⇒ Vanagon::Component::Source
Basic factory to hand back the correct Vanagon::Component::Source subtype to the component
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vanagon/component/source.rb', line 19 def source(uri, **) # rubocop:disable Metrics/AbcSize # Sometimes the uri comes in as a string, but sometimes it's already been # coerced into a URI object. The individual source providers will turn # the passed uri into a URI object if needed, but for this method we # want to work with the uri as a string. uri = uri.to_s if uri.start_with?('git') source_type = :git # when using an http(s) source for a git repo, you should prefix the # url with `git:`, so something like `git:https://github.com/puppetlabs/vanagon` # strip the leading `git:` so we have a valid uri uri.sub!(/^git:http/, 'http') else source_type = determine_source_type(uri) end if source_type == :git return Vanagon::Component::Source::Git.new uri, sum: [:sum], ref: [:ref], workdir: [:workdir], dirname: [:dirname], clone_options: [:clone_options] end if source_type == :http return Vanagon::Component::Source::Http.new uri, sum: [:sum], workdir: [:workdir], # Default sum_type is md5 if unspecified: sum_type: [:sum_type] || "md5" end if source_type == :local return Vanagon::Component::Source::Local.new uri, workdir: [:workdir] end # Unknown source type! raise Vanagon::Error, "Unknown file type: '#{uri}'; cannot continue" end |