Skip to content

Commit

Permalink
fix initdb for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
alecmerdler authored and kleesc committed Jan 23, 2020
1 parent 1d6e415 commit b6d41de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
12 changes: 6 additions & 6 deletions initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@


def __gen_checksum(image_id):
csum = hashlib.md5(image_id)
csum = hashlib.md5(image_id.encode('utf-8'))
return "tarsum+sha256:" + csum.hexdigest() + csum.hexdigest()


def __gen_image_id(repo, image_num):
str_to_hash = "%s/%s/%s" % (repo.namespace_user.username, repo.name, image_num)
bytes_to_hash = ("%s/%s/%s" % (repo.namespace_user.username, repo.name, image_num)).encode("utf-8")

img_id = hashlib.md5(str_to_hash)
img_id = hashlib.md5(bytes_to_hash)
return img_id.hexdigest() + img_id.hexdigest()


def __gen_image_uuid(repo, image_num):
str_to_hash = "%s/%s/%s" % (repo.namespace_user.username, repo.name, image_num)
bytes_to_hash = ("%s/%s/%s" % (repo.namespace_user.username, repo.name, image_num)).encode("utf-8")

img_uuid = hashlib.md5(str_to_hash)
img_uuid = hashlib.md5(bytes_to_hash)
return UUID(bytes=img_uuid.digest())


Expand All @@ -128,7 +128,7 @@ def __create_subtree(with_storage, repo, structure, creator_username, parent, ta
new_image.storage.save()

# Write out a fake torrentinfo
model.storage.save_torrent_info(new_image.storage, 1, "deadbeef")
model.storage.save_torrent_info(new_image.storage, 1, b"deadbeef")

# Write some data for the storage.
if with_storage or os.environ.get("WRITE_STORAGE_FILES"):
Expand Down
9 changes: 7 additions & 2 deletions util/security/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ def convert_secret_key(config_secret_key):
secret_key = str(bytearray(list(map(ord, config_secret_key))))

# Otherwise, use the bytes directly.
assert len(secret_key)
return "".join(itertools.islice(itertools.cycle(secret_key), 32))
assert len(secret_key) > 0
print(secret_key)

# FIXME(alecmerdler): Testing
secret_key = b'\xa3l\x9d}%\xa90\xf4\xa5\x86=/\x8d\xc4\n\x83'

return b"".join(itertools.islice(itertools.cycle([bytes([b]) for b in secret_key]), 32))
6 changes: 4 additions & 2 deletions util/security/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ def encode_public_private_token(public_code, private_token, allow_public_only=Fa
return public_code

assert isinstance(private_token, str)
return base64.b64encode("%s%s%s" % (public_code, DELIMITER, private_token))
b = ("%s%s%s" % (public_code, DELIMITER, private_token)).encode("utf-8")

return base64.b64encode(b)


def decode_public_private_token(encoded, allow_public_only=False):
try:
decoded = base64.b64decode(encoded)
decoded = base64.b64decode(encoded).decode('utf-8')
except (ValueError, TypeError):
if not allow_public_only:
return None
Expand Down

0 comments on commit b6d41de

Please sign in to comment.