-
Notifications
You must be signed in to change notification settings - Fork 27
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 conan.errors import ConanException | ||
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") | ||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will silently return if |
||
finally: | ||
shutil.move(new_path, args.path) | ||
if os.path.isfile(json_path): | ||
os.remove(json_path) |
There was a problem hiding this comment.
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?