-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic functionality for Upload API (#380)
Summary: Pull Request resolved: #380 * Add an `upload_file` API to storage service. * Add an optional metadata param to upload APIs in all relevant interfaces. Most cloud providers support metadata param in their upload APIs, so it should be a fairly generic feature. Some rationales behind these changes: * Since object metadata is a generic feature provided by cloud providers, it makes sense to enable it in storage servic e layer * It does not really make sense to add object metadata in the `copy` API, because we normally don't expect the files to be changed during copying * So I'm adding a new upload_file to support this. We should be calling this API directly if we are specifically uploading files from local to the storage service. reference: relevant [boto3 docs](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html) for metadata **Next Step**: enable upload api with checksum associated with a file Differential Revision: D38120426 fbshipit-source-id: 2e86ec3083b7d1d7d9b7193d937f16b2cd510492
- Loading branch information
1 parent
6c81d67
commit 365ce5e
Showing
9 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
onedocker/tests/repository/test_onedocker_repository_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import unittest | ||
from datetime import datetime | ||
from unittest.mock import MagicMock, patch | ||
|
||
from onedocker.repository.onedocker_repository_service import OneDockerRepositoryService | ||
|
||
|
||
class TestOneDockerRepositoryService(unittest.TestCase): | ||
TEST_PACKAGE_PATH = "private_lift/lift" | ||
TEST_PACKAGE_NAME = TEST_PACKAGE_PATH.split("/")[-1] | ||
TEST_PACKAGE_VERSION = "latest" | ||
|
||
@patch( | ||
"onedocker.repository.onedocker_repository_service.OneDockerChecksumRepository" | ||
) | ||
@patch( | ||
"onedocker.repository.onedocker_repository_service.OneDockerPackageRepository" | ||
) | ||
@patch("fbpcp.service.storage_s3.S3StorageService") | ||
def setUp( | ||
self, mockStorageService, mockPackageRepoCall, mockChecksumRepoCall | ||
) -> None: | ||
package_repo_path = "/package_repo_path/" | ||
checksum_repo_path = "/checksum_repo_path/" | ||
self.package_repo = MagicMock() | ||
mockPackageRepoCall.return_value = self.package_repo | ||
self.repo_service = OneDockerRepositoryService( | ||
mockStorageService, package_repo_path, checksum_repo_path | ||
) | ||
|
||
def test_onedocker_repo_service_upload(self) -> None: | ||
# Arrange | ||
source_path = "test_source_path" | ||
today = datetime.today().strftime("%Y-%m-%d") | ||
metadata = {"upload_date": today} | ||
|
||
# Act | ||
self.repo_service.upload( | ||
self.TEST_PACKAGE_PATH, self.TEST_PACKAGE_VERSION, source_path | ||
) | ||
|
||
# Assert | ||
self.package_repo.upload.assert_called_with( | ||
self.TEST_PACKAGE_PATH, self.TEST_PACKAGE_VERSION, source_path, metadata | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters