generated from mlibrary/python-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds a list barcodes in input bucket method to digifeeds cli
- Loading branch information
Showing
7 changed files
with
396 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import boto3 | ||
from aim.services import S | ||
|
||
|
||
def list_barcodes_in_bucket(): | ||
s3 = boto3.client( | ||
"s3", | ||
aws_access_key_id=S.digifeeds_s3_access_key, | ||
aws_secret_access_key=S.digifeeds_s3_secret_access_key, | ||
) | ||
prefix = S.digifeeds_s3_input_path + "/" | ||
response = s3.list_objects_v2( | ||
Bucket=S.digifeeds_s3_bucket, | ||
Prefix=prefix, | ||
Delimiter="/", | ||
) | ||
paths = [object["Prefix"] for object in response["CommonPrefixes"]] | ||
barcodes = [path.split("/")[1] for path in paths] | ||
return barcodes |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import boto3 | ||
from moto import mock_aws | ||
from aim.services import S | ||
from aim.digifeeds.list_barcodes_in_bucket import list_barcodes_in_bucket | ||
|
||
|
||
@mock_aws | ||
def test_list_barcodes_in_bucket(): | ||
conn = boto3.resource( | ||
"s3", | ||
aws_access_key_id=S.digifeeds_s3_access_key, | ||
aws_secret_access_key=S.digifeeds_s3_secret_access_key, | ||
) | ||
conn.create_bucket(Bucket=S.digifeeds_s3_bucket) | ||
|
||
barcode1 = conn.Object( | ||
S.digifeeds_s3_bucket, f"{S.digifeeds_s3_input_path}/barcode1/some_file.txt" | ||
) | ||
barcode1.put(Body="some text") | ||
barcode2 = conn.Object( | ||
S.digifeeds_s3_bucket, f"{S.digifeeds_s3_input_path}/barcode2/some_file.txt" | ||
) | ||
barcode2.put(Body="some text") | ||
|
||
result = list_barcodes_in_bucket() | ||
assert result == ["barcode1", "barcode2"] |