From 502dcfbcb66c840a1e9656aaf096d5594a420558 Mon Sep 17 00:00:00 2001 From: Luciano Silva Date: Sun, 19 Feb 2017 15:52:16 -0500 Subject: [PATCH] Support for basic authentication --- README.md | 6 +++++- pipeline.yml | 10 ---------- test/test-check.sh | 19 +++++++++++++++++++ test/test-in.sh | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 96ad9fc..c31b218 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,14 @@ This is a useful resource for pipeline development time, while a required artifa ## Source Configuration -* `url`: *Required.* The url location of the file. It has to be publicly available, no user authentication supported in v0.0.1. +* `url`: *Required.* The url location of the file. * `filename`: *Optional.* The name of the file for the downloaded artifact to be save as. If not provided, the file will be saved using the full url string as its name. +* `username`: *Optional.* Username for accessing an authenticated repository. + +* `password`: *Optional.* Password for accessing an authenticated repository. + * `skip_ssl_verification`: *Optional.* Skips ssl verification if defined as `true`. Default is `false`. ### Example diff --git a/pipeline.yml b/pipeline.yml index 52fb04a..c569a5b 100644 --- a/pipeline.yml +++ b/pipeline.yml @@ -16,20 +16,12 @@ resources: source: url: https://raw.githubusercontent.com/pivotalservices/concourse-curl-resource/master/test/data/pivotal-1.0.0.txt filename: pivotal-1.0.0.txt -- name: my-file-requiring-auth - type: file-url - source: - url: https://auth-demo.aerobatic.io/protected-standard - filename: auth-request-response.txt - username: aerobatic - password: aerobatic jobs: - name: run-and-get-files plan: - get: my-file-with-last-modified-info - get: my-file-without-last-modified-info - - get: my-file-requiring-auth - task: run-and-get-file config: platform: linux @@ -41,11 +33,9 @@ jobs: inputs: - name: my-file-with-last-modified-info - name: my-file-without-last-modified-info - - name: my-file-requiring-auth run: path: sh args: - -exc - | find . - cat ./my-file-requiring-auth/auth-request-response.txt | grep expecting diff --git a/test/test-check.sh b/test/test-check.sh index 8d72c4b..ca53177 100755 --- a/test/test-check.sh +++ b/test/test-check.sh @@ -10,6 +10,9 @@ export FILE_URL_WITH_LAST_MODIFIED_INFO=https://s3-us-west-1.amazonaws.com/lsilv # set FILE_URL_WITHOUT_LAST_MODIFIED_INFO with a URL of a file whose HTTP HEADER info DOES NOT provide a Last-Modified entry # to check it do "curl -I -R " export FILE_URL_WITHOUT_LAST_MODIFIED_INFO=https://raw.githubusercontent.com/pivotalservices/concourse-curl-resource/master/test/data/pivotal-1.0.0.txt +# set FILE_URL_WITHOUT_LAST_MODIFIED_INFO with a URL of a file whose HTTP HEADER info DOES NOT provide a Last-Modified entry +# to check it do "curl -I -R " +export FILE_URL_BASIC_AUTH=https://auth-demo.aerobatic.io/protected-standard it_can_get_file_with_last_modified_info() { @@ -33,5 +36,21 @@ it_can_get_file_without_last_modified_info() { } +it_can_get_file_with_basic_auth() { + + echo $resource_dir + + jq -n "{ + source: { + url: $(echo $FILE_URL_BASIC_AUTH | jq -R .), + username: $(echo 'aerobatic' | jq -R .), + password: $(echo 'aerobatic' | jq -R .), + filename: $(echo 'basicauth.txt' | jq -R .) + } + }" | $resource_dir/check "$FILE_URL_BASIC_AUTH" | tee /dev/stderr + +} + run it_can_get_file_with_last_modified_info run it_can_get_file_without_last_modified_info +run it_can_get_file_with_basic_auth diff --git a/test/test-in.sh b/test/test-in.sh index 2d3da17..34d380c 100755 --- a/test/test-in.sh +++ b/test/test-in.sh @@ -13,6 +13,8 @@ export FILE_NAME_1=pcf-sandbox.json # to check it do "curl -I -R " export FILE_URL_WITHOUT_LAST_MODIFIED_INFO=https://raw.githubusercontent.com/pivotalservices/concourse-curl-resource/master/test/data/pivotal-1.0.0.txt export FILE_NAME_2=ivotal-1.0.0.txt +# set FILE_URL_BASIC_AUTH with a URL of a file that requires basic authentication +export FILE_URL_BASIC_AUTH=https://auth-demo.aerobatic.io/protected-standard it_can_get_file_with_date_info() { jq -n "{ @@ -24,4 +26,20 @@ it_can_get_file_with_date_info() { } +it_can_get_file_with_basic_auth() { + + echo "Source=[$src]" + + jq -n "{ + source: { + url: $(echo $FILE_URL_BASIC_AUTH | jq -R .), + username: $(echo 'aerobatic' | jq -R .), + password: $(echo 'aerobatic' | jq -R .), + filename: $(echo 'basicauth.txt' | jq -R .) + } + }" | $resource_dir/in "$src" | tee /dev/stderr + +} + run it_can_get_file_with_date_info +run it_can_get_file_with_basic_auth