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

Support for air-gapped envs for backup sources #125

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
41 changes: 41 additions & 0 deletions extensions/commands/x/cmd_backups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import shutil
import json

from conan.api.output import ConanOutput
from conan.cli.command import conan_command
from conans.errors import ConanException
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
from conans.util.dates import timestamp_now
from conans.util.sha import sha256


@conan_command(group="Backup sources handling")
def backups(conan_api, parser, *args):
"""
This command will upload the backup sources of a package to the server.
"""
parser.add_argument("reference", help="Reference of the package to backup")
parser.add_argument("path", help="Path to source files for this reference")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide the possibility to download it too from a URL?

parser.add_argument("--url", help="Original URL of the file", default=None)
args = parser.parse_args(*args)

if not os.path.isfile(args.path):
raise ConanException(f"File not found: {args.path}")

with open(args.path, "rb") as f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say to include the checksum input and verification as well? Not just read the local one, could be tampered?

checksum = sha256(f.read())

ConanOutput().info(f"Calculated checksum: {checksum}")
new_path = os.path.join(os.path.dirname(args.path), checksum)
json_path = new_path + ".json"
shutil.move(args.path, new_path)
try:
with open(json_path, "w") as f:
json.dump({"references": {args.reference: [args.url] if args.url else []},
"timestamp": timestamp_now()}, f)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

conan_api.upload.upload_backup_sources([new_path, json_path])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will silently return if url = config.get("core.sources:upload_url", check_type=str) is not defined. Most likely we want to check this and error?

finally:
shutil.move(new_path, args.path)
if os.path.isfile(json_path):
os.remove(json_path)
Loading