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

Fix curl behind proxy2 proper withcurlproxy [dont merge, for review only] #160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ provisioner:
log_level: error
formula: linux
grains:
noservices: true
noservices: True
kitchen-test: True
state_top:
base:
"*":
Expand Down
32 changes: 29 additions & 3 deletions linux/system/repo.sls
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,47 @@ linux_repo_{{ name }}_pin:
{%- if repo.get('key') %} {# 2 #}

linux_repo_{{ name }}_key:
{% if grains['saltversioninfo'] < [2017, 7] %}
cmd.run:
- name: |
echo "{{ repo.key | indent(12) }}" | apt-key add -
{%- if not grains.get('kitchen-test') %}
{# omitted from tests, as behaves inconsistently across CI/platforms #}
- unless: |
apt-key finger --with-colons | grep -qF $(echo "{{ repo.key| indent(12) }}" | gpg --with-fingerprint --with-colons | grep -E '^fpr')
{%- endif %}
{%- else %}
module.run:
- name: pkg.add_repo_key
- text: |
{{ repo.key | indent(10) }}
{%- endif %}
- require_in:
{%- if repo.get('default', False) %}
- file: default_repo_list
{% else %}
- pkgrepo: linux_repo_{{ name }}
{% endif %}

{%- elif repo.key_url|default(False) %}
{# key_url fetch by curl when salt <2017.7, higher version of salt has fixed bug for using a proxy_host/port specified at minion.conf #}
{#
NOTE: curl/cmd.run usage to fetch gpg key has limited functionality behind proxy. Environments with salt >= 2017.7 should use
key_url specified at pkgrepo.manage state (which uses properly configured http_host at minion.conf). Older versions of
salt require to have proxy set at ENV and curl way to fetch gpg key here can have a sense for backward compatibility.

Be aware that as of salt 2018.3 no_proxy option is not implemented at all.
#}
{%- elif repo.key_url|default(False) and grains['saltversioninfo'] < [2017, 7] and not repo.key_url.startswith('salt://') %}

{% set _export_proxy = "export no_proxy=${no_proxy:-" + system.proxy.get('noproxy', []) |join(',') + "} http_proxy=${http_proxy:-" + system.proxy.get('http', '') + "} https_proxy=${https_proxy:-" + system.proxy.get('https', '') +"}; " %}

linux_repo_{{ name }}_key:
cmd.run:
- name: "curl -sL {{ repo.key_url }} | apt-key add -"
- unless: "apt-key finger --with-colons | grep -qF $(curl -sL {{ repo.key_url }} | gpg --with-fingerprint --with-colons | grep -E '^fpr')"
- name: "{{ _export_proxy }} curl -sL {{ repo.key_url }} | apt-key add -"
{%- if not grains.get('kitchen-test') %}
{# omitted from tests, as behaves inconsistently across CI/platforms #}
- unless: "apt-key finger --with-colons | grep -qF $({{ _export_proxy }} curl -sL {{ repo.key_url }} | gpg --with-fingerprint --with-colons | grep -E '^fpr')"
{%- endif %}
- require_in:
{%- if repo.get('default', False) %}
- file: default_repo_list
Expand Down Expand Up @@ -132,6 +155,9 @@ linux_repo_{{ name }}:
{%- if repo.key_server is defined %}
- keyserver: {{ repo.key_server }}
{%- endif %}
{%- if repo.key_url is defined and (grains['saltversioninfo'] >= [2017, 7] or repo.key_url.startswith('salt://')) %}
- key_url: {{ repo.key_url }}
{%- endif %}
- consolidate: {{ repo.get('consolidate', False) }}
- clean_file: {{ repo.get('clean_file', False) }}
- refresh_db: {{ repo.get('refresh_db', True) }}
Expand Down