From cee645a6c983b994a3cb1b20baeac25f63dac8f8 Mon Sep 17 00:00:00 2001 From: Igor Mukhin Date: Mon, 11 Jan 2016 20:55:37 +0200 Subject: [PATCH] Added: Ability to provide HTTP Basic Auth credentials --- README.md | 15 +++++++++++++++ defaults/main.yml | 1 + tasks/{oauth.yml => auth_json.yml} | 2 +- tasks/main.yml | 2 +- templates/.composer/auth.json.j2 | 18 ++++++++++++++++-- tests/playbook.yml | 4 ++++ 6 files changed, 38 insertions(+), 4 deletions(-) rename tasks/{oauth.yml => auth_json.yml} (68%) diff --git a/README.md b/README.md index 7b53b1d..0c7271d 100755 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ You can also setup a global composer directory and make the bin directory availa composer_global_packages: phpunit/phpunit: "@stable" +## Auth.json + +### Github OAuth token + If your project use a lot of libraries from github, you may see next message during `composer install`: Could not fetch `...`, enter your GitHub credentials to go over the API rate limit @@ -35,6 +39,17 @@ To prevent that, you must configure github oauth token to go over the API rate l composer_github_oauth: f03401aae1e276abb073f987c08a32410f462e73 +### HTTP Basic auth + +You can provide HTTP Basic auth credentials to any repository like this: + +``` +composer_http_basic: + repo.magento.com: + username: 52fe41da9d8caa70538244c10f367d0a + password: 238fe32d374a2573c4527bd45a7e6f54 +``` + ## Example Playbook roles: diff --git a/defaults/main.yml b/defaults/main.yml index 935432f..b620694 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -12,3 +12,4 @@ composer_global_packages: {} # Visit https://github.com/settings/applications # and generate personal access token composer_github_oauth: false +composer_http_basic: false diff --git a/tasks/oauth.yml b/tasks/auth_json.yml similarity index 68% rename from tasks/oauth.yml rename to tasks/auth_json.yml index 84d4567..433b4b4 100644 --- a/tasks/oauth.yml +++ b/tasks/auth_json.yml @@ -4,4 +4,4 @@ template: src: ".composer/auth.json.j2" dest: "{{ composer_home_path|default('~/.composer') }}/auth.json" - when: composer_github_oauth != false + when: composer_github_oauth != false or composer_http_basic != false diff --git a/tasks/main.yml b/tasks/main.yml index 2edf365..69c2b49 100755 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,6 +3,6 @@ - include: install.yml - include: test.yml - include: configure.yml -- include: oauth.yml +- include: auth_json.yml - include: update.yml when: composer_update == true diff --git a/templates/.composer/auth.json.j2 b/templates/.composer/auth.json.j2 index 18bf4a1..7ff0344 100644 --- a/templates/.composer/auth.json.j2 +++ b/templates/.composer/auth.json.j2 @@ -1,5 +1,19 @@ { - "github-oauth": { - "github.com": "{{ composer_github_oauth }}" + {% if composer_http_basic %} + "http-basic": { + {% for repository,credentials in composer_http_basic.iteritems() %} + {% if loop.index0 %},{% endif %} + "{{ repository }}": { + "username": "{{ credentials.username }}", + "password": "{{ credentials.password }}" + } + {% endfor %} } + {% endif %} + {% if composer_http_basic and composer_http_basic %},{% endif %} + {% if composer_github_oauth %} + "github-oauth": { + "github.com": "{{ composer_github_oauth }}" + } + {% endif %} } diff --git a/tests/playbook.yml b/tests/playbook.yml index f861ee1..288566f 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -4,6 +4,10 @@ sudo: true vars: composer_github_oauth: f03401aae1e276abb073f987c08a32410f462e73 + composer_http_basic: + repo.magento.com: + username: 52fe41da9d8caa70538244c10f367d0a + password: 238fe32d374a2573c4527bd45a7e6f54 roles: - { role: common, tags: apt } - { role: ../../ansible-role-composer, tags: composer }