Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer Authentication: Add support for bearer, gitlab-oauth, gitlab-token, github-oauth and bitbucket-oauth principles #1413

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions group_vars/all/helpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ cron_enabled: "{{ site_env.disable_wp_cron and (not item.value.multisite.enabled
sites_use_ssl: "{{ wordpress_sites.values() | map(attribute='ssl') | selectattr('enabled') | list | count > 0 }}"

composer_authentications: "{{ vault_wordpress_sites[site].composer_authentications | default([]) }}"
# Default `type` is `http-basic`.
composer_authentications_using_basic_auth: "{{ composer_authentications | rejectattr('type', 'defined') | union( composer_authentications | selectattr('type', 'defined') | selectattr('type', 'equalto', 'http-basic') ) }}"
composer_authentications_using_bitbucket_oauth: "{{ composer_authentications | selectattr('type', 'defined') | selectattr('type', 'equalto', 'bitbucket-oauth') }}"
composer_authentications_using_other_token: "{{ composer_authentications | selectattr('type', 'defined') | rejectattr('type', 'equalto', 'http-basic') | rejectattr('type', 'equalto', 'bitbucket-oauth') }}"
42 changes: 35 additions & 7 deletions roles/deploy/hooks/build-after.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,48 @@
msg: "Unable to find a `composer.json` file in the root of '{{ deploy_helper.new_release_path }}'. Make sure your repo has a `composer.json` file in its root or edit `repo_subtree_path` for '{{ site }}' in `wordpress_sites.yml` so it points to the directory with a `composer.json` file."
when: not composer_json.stat.exists

- name: Setup composer authentications
- name: Setup composer authentications (HTTP Basic)
composer:
command: config
arguments: --auth http-basic.{{ composer_authentication.hostname | quote }} {{ composer_authentication.username | quote }} {{ composer_authentication.password | default("") | quote }}
arguments: --auth http-basic.{{ item.hostname | quote }} {{ item.username | quote }} {{ item.password | default("") | quote }}
working_dir: "{{ deploy_helper.new_release_path }}"
no_log: true
changed_when: false
when:
- composer_authentication.hostname is defined and composer_authentication.hostname != ""
- composer_authentication.username is defined and composer_authentication.username != ""
loop: "{{ composer_authentications | default([]) }}"
- item.hostname is defined and item.hostname != ""
- item.username is defined and item.username != ""
loop: "{{ composer_authentications_using_basic_auth }}"
loop_control:
loop_var: composer_authentication
label: "{{ composer_authentication.hostname }}"
label: "{{ item.type | default('default-type') }}.{{ item.hostname }}"

- name: Setup composer authentications (BitBucket OAuth)
composer:
command: config
arguments: --auth bitbucket-oauth.{{ item.hostname | quote }} {{ item.consumer_key | quote }} {{ item.consumer_secret | quote }}
working_dir: "{{ deploy_helper.new_release_path }}"
no_log: true
changed_when: false
when:
- item.hostname is defined and item.hostname != ""
- item.consumer_key is defined and item.consumer_key != ""
- item.consumer_secret is defined and item.consumer_secret != ""
loop: "{{ composer_authentications_using_bitbucket_oauth }}"
loop_control:
label: "{{ item.type }}.{{ item.hostname }}"

- name: Setup composer authentications (Other Tokens)
composer:
command: config
arguments: --auth {{ item.type | quote }}.{{ item.hostname | quote }} {{ item.token | quote }}
working_dir: "{{ deploy_helper.new_release_path }}"
no_log: true
changed_when: false
when:
- item.hostname is defined and item.hostname != ""
- item.token is defined and item.token != ""
loop: "{{ composer_authentications_using_other_token }}"
loop_control:
label: "{{ item.type }}.{{ item.hostname }}"

- name: Run composer check
composer:
Expand Down
42 changes: 35 additions & 7 deletions roles/wordpress-install/tasks/composer-authentications.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
---
- name: "Setup composer authentications - {{ site }}"
- name: "Setup composer authentications (HTTP Basic) - {{ site }}"
composer:
command: config
arguments: --auth http-basic.{{ composer_authentication.hostname | quote }} {{ composer_authentication.username | quote }} {{ composer_authentication.password | default("") | quote }}
arguments: --auth http-basic.{{ item.hostname | quote }} {{ item.username | quote }} {{ item.password | default("") | quote }}
working_dir: "{{ working_dir }}"
no_log: true
changed_when: false
when:
- composer_authentication.hostname is defined and composer_authentication.hostname != ""
- composer_authentication.username is defined and composer_authentication.username != ""
loop: "{{ composer_authentications | default([]) }}"
- item.hostname is defined and item.hostname != ""
- item.username is defined and item.username != ""
loop: "{{ composer_authentications_using_basic_auth }}"
loop_control:
loop_var: composer_authentication
label: "{{ composer_authentication.hostname }}"
label: "{{ item.type | default('default-type') }}.{{ item.hostname }}"

- name: "Setup composer authentications (BitBucket OAuth) - {{ site }}"
composer:
command: config
arguments: --auth bitbucket-oauth.{{ item.hostname | quote }} {{ item.consumer_key | quote }} {{ item.consumer_secret | quote }}
working_dir: "{{ working_dir }}"
no_log: true
changed_when: false
when:
- item.hostname is defined and item.hostname != ""
- item.consumer_key is defined and item.consumer_key != ""
- item.consumer_secret is defined and item.consumer_secret != ""
loop: "{{ composer_authentications_using_bitbucket_oauth }}"
loop_control:
label: "{{ item.type }}.{{ item.hostname }}"

- name: "Setup composer authentications (Other Tokens) - {{ site }}"
composer:
command: config
arguments: --auth {{ item.type | quote }}.{{ item.hostname | quote }} {{ item.token | quote }}
working_dir: "{{ working_dir }}"
no_log: true
changed_when: false
when:
- item.hostname is defined and item.hostname != ""
- item.token is defined and item.token != ""
loop: "{{ composer_authentications_using_other_token }}"
loop_control:
label: "{{ item.type }}.{{ item.hostname }}"