vmware / govmomi

Go library for the VMware vSphere API
Apache License 2.0
2.26k stars 896 forks source link

api: add checksum validation in Content Library update session file API #3429

Closed dilyar85 closed 2 months ago

dilyar85 commented 2 months ago

Description

This PR updates the AddLibraryItemFileFromURI API with an optional LibraryItemFileChecksumInfo that the server can use to verify the uploaded library file content. It also updates the govc library.import command accordingly with the new checksum arguments (-c for checksum value & -a for checksum algorithm).

Type of change

How Has This Been Tested?

# No checksum specified:
$ govc library.import -pull checksum-test https://releases.ubuntu.com/14.04.6/ubuntu-14.04.6-server-amd64.iso

$ govc library.ls checksum-test/
/checksum-test/ubuntu-14.04.6-server-amd64

# Invalid checksum algorithm:
$ govc library.import -a=foo -pull checksum-test https://releases.ubuntu.com/14.04.6/ubuntu-14.04.6-server-amd64.iso
govc: invalid checksum algorithm: foo

# Invalid checksum value:
$ govc library.import -c=invalid -pull checksum-test https://releases.ubuntu.com/14.04.6/ubuntu-14.04.6-server-amd64.iso
govc: The import of library item 2a57efd7-32be-4aad-80f6-4212f123a82c has failed. Reason: Error transferring file ubuntu-14.04.6-server-amd64.iso from https://releases.ubuntu.com/14.04.6/ubuntu-14.04.6-server-amd64.iso. Reason: Checksum mismatch for endpoint https://releases.ubuntu.com/14.04.6/ubuntu-14.04.6-server-amd64.iso in item ubuntu-14.04.6-server-amd64.iso: [actual checksum = b17d7c1e9d0321ad5810ba77b69aef43f0f29a5422b08120e6ee0576c4527c0e; expected checksum = invalid].

# Valid checksum value and algorithm:
$ govc library.import -c=b17d7c1e9d0321ad5810ba77b69aef43f0f29a5422b08120e6ee0576c4527c0e -a=SHA256 -pull checksum-test https://releases.ubuntu.com/14.04.6/ubuntu-14.04.6-server-amd64.iso

$ govc library.ls checksum-test/
/checksum-test/ubuntu-14.04.6-server-amd64

Checklist: