From 576335e53dc7721811a9dfe02b29a36ec7f27e56 Mon Sep 17 00:00:00 2001 From: Tristan de Cacqueray Date: Tue, 16 Jan 2018 15:37:50 +0000 Subject: [PATCH] Add GALAXY_TOKEN config option (#34621) This change lets user store token in configuration file or environment to prevent exposing the secret on the command line. --- lib/ansible/cli/galaxy.py | 9 ++++++--- lib/ansible/config/base.yml | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 6cec4eb222a..4b58e8a361f 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -545,14 +545,17 @@ class GalaxyCLI(CLI): """ # Authenticate with github and retrieve a token if self.options.token is None: - login = GalaxyLogin(self.galaxy) - github_token = login.create_github_token() + if C.GALAXY_TOKEN: + github_token = C.GALAXY_TOKEN + else: + login = GalaxyLogin(self.galaxy) + github_token = login.create_github_token() else: github_token = self.options.token galaxy_response = self.api.authenticate(github_token) - if self.options.token is None: + if self.options.token is None and C.GALAXY_TOKEN is None: # Remove the token we created login.remove_github_token() diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index a9f38658e32..52debdf1176 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -1230,6 +1230,13 @@ GALAXY_SERVER: ini: - {key: server, section: galaxy} yaml: {key: galaxy.server} +GALAXY_TOKEN: + default: null + description: "GitHub personnal access token" + env: [{name: ANSIBLE_GALAXY_TOKEN}] + ini: + - {key: token, section: galaxy} + yaml: {key: galaxy.token} HOST_KEY_CHECKING: name: Check host keys default: True