Skip to content

Commit

Permalink
Use hashutils and stringutils for bytes to unicode conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryKuzmenko authored and dwoz committed Jul 30, 2020
1 parent f81383a commit 4960c90
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions salt/modules/artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals

import base64
import logging
import os

import salt.ext.six.moves.http_client # pylint: disable=import-error,redefined-builtin,no-name-in-module

# Import Salt libs
import salt.ext.six.moves.http_client # pylint: disable=import-error,redefined-builtin,no-name-in-module
import salt.utils.files
import salt.utils.hashutils
import salt.utils.stringutils
from salt.exceptions import CommandExecutionError
from salt.ext.six.moves import urllib # pylint: disable=no-name-in-module
Expand Down Expand Up @@ -100,12 +99,10 @@ def get_latest_snapshot(

headers = {}
if username and password:
data_string = "{0}:{1}".format(
username.replace("\n", ""), password.replace("\n", "")
)
data_bytes = data_string.encode("utf-8")
headers["Authorization"] = "Basic {0}".format(
base64.b64encode(data_bytes).decode("utf-8")
salt.utils.hashutils.base64_encodestring(
"{0}:{1}".format(username.replace("\n", ""), password.replace("\n", ""))
)
)
artifact_metadata = _get_artifact_metadata(
artifactory_url=artifactory_url,
Expand Down Expand Up @@ -186,12 +183,10 @@ def get_snapshot(
)
headers = {}
if username and password:
data_string = "{0}:{1}".format(
username.replace("\n", ""), password.replace("\n", "")
)
data_bytes = data_string.encode("utf-8")
headers["Authorization"] = "Basic {0}".format(
base64.b64encode(data_bytes).decode("utf-8")
salt.utils.hashutils.base64_encodestring(
"{0}:{1}".format(username.replace("\n", ""), password.replace("\n", ""))
)
)
snapshot_url, file_name = _get_snapshot_url(
artifactory_url=artifactory_url,
Expand Down Expand Up @@ -259,12 +254,10 @@ def get_latest_release(
)
headers = {}
if username and password:
data_string = "{0}:{1}".format(
username.replace("\n", ""), password.replace("\n", "")
)
data_bytes = data_string.encode("utf-8")
headers["Authorization"] = "Basic {0}".format(
base64.b64encode(data_bytes).decode("utf-8")
salt.utils.hashutils.base64_encodestring(
"{0}:{1}".format(username.replace("\n", ""), password.replace("\n", ""))
)
)
version = __find_latest_version(
artifactory_url=artifactory_url,
Expand Down Expand Up @@ -341,12 +334,10 @@ def get_release(
)
headers = {}
if username and password:
data_string = "{0}:{1}".format(
username.replace("\n", ""), password.replace("\n", "")
)
data_bytes = data_string.encode("utf-8")
headers["Authorization"] = "Basic {0}".format(
base64.b64encode(data_bytes).decode("utf-8")
salt.utils.hashutils.base64_encodestring(
"{0}:{1}".format(username.replace("\n", ""), password.replace("\n", ""))
)
)
release_url, file_name = _get_release_url(
repository,
Expand Down Expand Up @@ -722,8 +713,7 @@ def __save_artifact(artifact_url, target_file, headers):
checksum_url, headers
)
if checksum_success:
if isinstance(artifact_sum, bytes):
artifact_sum = artifact_sum.decode()
artifact_sum = salt.utils.stringutils.to_unicode(artifact_sum)
log.debug("Downloaded SHA1 SUM: %s", artifact_sum)
file_sum = __salt__["file.get_hash"](path=target_file, form="sha1")
log.debug("Target file (%s) SHA1 SUM: %s", target_file, file_sum)
Expand Down

0 comments on commit 4960c90

Please sign in to comment.