Skip to content

Commit

Permalink
Support authenticated HTTP URLs
Browse files Browse the repository at this point in the history
Software `source` method now supports the `authorization` option.
This allows the user to supply an HTTP Authorization header which will
be passed to the source URL.

For the common case of basic authentication, that looks like this:

```
require 'base64'

username = 'XXX'
password = 'YYY'
credentials = Base64.encode64("#{username}:#{password}")

version 'the_version' do
  source url: 'https://example.com/path/to/the/file',
         authorization: "Basic #{credentials}",
         ...
end
```

Signed-off-by: Lee Green <[email protected]>
  • Loading branch information
LeeXGreen authored and Lee Green committed Apr 5, 2019
1 parent 7ad3279 commit 55018e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/omnibus/fetchers/net_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def download

# Set the cookie if one was given
options["Cookie"] = source[:cookie] if source[:cookie]
options["Authorization"] = source[:authorization] if source[:authorization]

download_file!(download_url, downloaded_file, options)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/omnibus/software.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def dependency(val)
#
# @option val [String] :cookie (nil)
# a cookie to set
# @option val [String] :authorization (nil)
# an authorization header to set
# @option val [String] :warning (nil)
# a warning message to print when downloading
# @option val [Symbol] :extract (nil)
Expand Down Expand Up @@ -294,7 +296,7 @@ def source(val = NULL)
extra_keys = val.keys - [
:git, :file, :path, :url, # fetcher types
:md5, :sha1, :sha256, :sha512, # hash type - common to all fetchers
:cookie, :warning, :unsafe, :extract, :cached_name, # used by net_fetcher
:cookie, :warning, :unsafe, :extract, :cached_name, :authorization, # used by net_fetcher
:options, # used by path_fetcher
:submodules # used by git_fetcher
]
Expand Down

0 comments on commit 55018e8

Please sign in to comment.