Skip to content
Myr

[New] Add support for `NVM_AUTH_HEADER` env var

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Closes #3366

authored by David Welch · committed by Jordan Harband · parent 4c7d899 · Browse files · 3 files+38 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: David Welch <david@davidwelch.co>
  • Co-authored-by: Andre Kradolfer <narfdre@gmail.com>

Diff stats

3 files+38 added−4 removed

  • tests:+11 added−1 removed
  • other:+27 added−3 removed

3 files+38 added−4 removed

modified:test/fast/Unit tests/nvm_download+11 added-1 removed
1#!/bin/sh23cleanup () {4 unset -f die cleanup4 unset -f die cleanup NVM_AUTH_HEADER5 docker stop httpbin && docker rm httpbin6}7die () { echo "$@" ; cleanup ; exit 1; }89\. ../../../nvm.sh
5 unmodified lines
1516# nvm_download should fail to download wrong_install.sh17! nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/wrong_install.sh" >/dev/null || die "nvm_download should fail to download no existing file"1819# nvm_download should pass when calling with auth header20docker pull kennethreitz/httpbin && docker run --shell=bash -d --name httpbin -p 80:80 kennethreitz/httpbin21sleep 1 # wait for httpbin to start22NVM_AUTH_HEADER="Bearer test-token" nvm_download "http://127.0.0.1/bearer" > /dev/null || die 'nvm_download with auth header should send correctly'2324# nvm_download should fail when calling without auth header25nvm_download "http://127.0.0.1/bearer" > /dev/null && die 'nvm_download with no auth header should not send the header and should fail'26docker stop httpbin && docker rm httpbin2728cleanup
modified:nvm.sh+19 added-3 removed
114 unmodified lines
115 nvm_echo "${NVM_LATEST_URL##*/}"116}117118nvm_download() {119 local CURL_COMPRESSED_FLAG119 if nvm_has "curl"; then120 local CURL_COMPRESSED_FLAG=""121 local CURL_HEADER_FLAG=""122123 if [ -n "${NVM_AUTH_HEADER:-}" ]; then124 sanitized_header=$(nvm_sanitize_auth_header "${NVM_AUTH_HEADER}")125 CURL_HEADER_FLAG="--header \"Authorization: ${sanitized_header}\""126 fi127128 if nvm_curl_use_compression; then129 CURL_COMPRESSED_FLAG="--compressed"130 fi124 curl --fail ${CURL_COMPRESSED_FLAG:-} -q "$@"131 eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} $*"132 elif nvm_has "wget"; then133 # Emulate curl with wget134 ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \135 -e 's/--compressed //' \
3 unmodified lines
139 -e 's/-s /-q /' \140 -e 's/-sS /-nv /' \141 -e 's/-o /-O /' \142 -e 's/-C - /-c /')143144 if [ -n "${NVM_AUTH_HEADER:-}" ]; then145 ARGS="${ARGS} --header \"${NVM_AUTH_HEADER}\""146 fi147 # shellcheck disable=SC2086148 eval wget $ARGS149 fi150}151152nvm_sanitize_auth_header() {153 # Remove potentially dangerous characters154 nvm_echo "$1" | command sed 's/[^a-zA-Z0-9:;_. -]//g'155}156157nvm_has_system_node() {158 [ "$(nvm deactivate >/dev/null 2>&1 && command -v node)" != '' ]159}160
4212 unmodified lines
4373 nvm_print_default_alias nvm_print_formatted_alias nvm_resolve_local_alias \4374 nvm_sanitize_path nvm_has_colors nvm_process_parameters \4375 nvm_node_version_has_solaris_binary nvm_iojs_version_has_solaris_binary \4376 nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \4361 nvm_npmrc_bad_news_bears \4377 nvm_npmrc_bad_news_bears nvm_sanitize_auth_header \4378 nvm_get_colors nvm_set_colors nvm_print_color_code nvm_wrap_with_color_code nvm_format_help_message_colors \4379 nvm_echo_with_colors nvm_err_with_colors \4380 nvm_get_artifact_compression nvm_install_binary_extract nvm_extract_tarball \4381 nvm_process_nvmrc nvm_nvmrc_invalid_msg \
175 unmodified lines
modified:README.md+8 added
37 unmodified lines
38 - [Suppressing colorized output](#suppressing-colorized-output)39 - [Restoring PATH](#restoring-path)40 - [Set default node version](#set-default-node-version)41 - [Use a mirror of node binaries](#use-a-mirror-of-node-binaries)42 - [Pass Authorization header to mirror](#pass-authorization-header-to-mirror)43 - [.nvmrc](#nvmrc)44 - [Deeper Shell Integration](#deeper-shell-integration)45 - [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)46 - [bash](#bash)
483 unmodified lines
530```531532`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs. Note that using `nvm` in multiple shell tabs with this environment variable enabled can cause race conditions.533534#### Pass Authorization header to mirror535To pass an Authorization header through to the mirror url, set `$NVM_AUTH_HEADER`536537```sh538NVM_AUTH_HEADER="Bearer secret-token" nvm install node539```540541### .nvmrc542543You can create a `.nvmrc` file containing a node version number (or any other string that `nvm` understands; see `nvm --help` for details) in the project root directory (or any parent directory).544Afterwards, `nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will use the version specified in the `.nvmrc` file if no version is supplied on the command line.
537 unmodified lines