mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Redact HTTPS Basic Auth data from remote URLs in comments and changes dict
This commit is contained in:
parent
eafeb6c7bf
commit
1f25a859bd
1 changed files with 19 additions and 3 deletions
|
@ -23,6 +23,8 @@ import os.path
|
|||
import shutil
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
import salt.utils.url
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -176,8 +178,22 @@ def latest(name,
|
|||
|
||||
if not target:
|
||||
return _fail(ret, '"target" option is required')
|
||||
|
||||
target = os.path.expanduser(target)
|
||||
|
||||
try:
|
||||
desired_fetch_url = salt.utils.url.add_http_basic_auth(
|
||||
name,
|
||||
https_user,
|
||||
https_pass,
|
||||
https_only=True
|
||||
)
|
||||
except ValueError as exc:
|
||||
return _fail(ret, exc.__str__())
|
||||
|
||||
redacted_fetch_url = \
|
||||
salt.utils.url.redact_http_basic_auth(desired_fetch_url)
|
||||
|
||||
run_check_cmd_kwargs = {'runas': user}
|
||||
if 'shell' in __grains__:
|
||||
run_check_cmd_kwargs['shell'] = __grains__['shell']
|
||||
|
@ -244,15 +260,15 @@ def latest(name,
|
|||
remote = __salt__['git.remote_get'](target,
|
||||
remote=remote_name,
|
||||
user=user)
|
||||
if remote is None or remote[0] != name:
|
||||
if remote is None or remote[0] != desired_fetch_url:
|
||||
__salt__['git.remote_set'](target,
|
||||
name=remote_name,
|
||||
url=name,
|
||||
url=desired_fetch_url,
|
||||
user=user,
|
||||
https_user=https_user,
|
||||
https_pass=https_pass)
|
||||
ret['changes']['remote/{0}'.format(remote_name)] = (
|
||||
"{0} => {1}".format(str(remote), name)
|
||||
"{0} => {1}".format(str(remote), redacted_fetch_url)
|
||||
)
|
||||
# Set to fetch later since we just added the remote and
|
||||
# need to get the refs
|
||||
|
|
Loading…
Add table
Reference in a new issue