Skip to content

Add tagging option to s3 commands#6079

Closed
vz10 wants to merge 1 commit into
aws:v2from
vz10:s3-tagging
Closed

Add tagging option to s3 commands#6079
vz10 wants to merge 1 commit into
aws:v2from
vz10:s3-tagging

Conversation

@vz10
Copy link
Copy Markdown
Contributor

@vz10 vz10 commented Apr 8, 2021

Issue #, if available:

Fixes #2458

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@vz10 vz10 requested review from kyleknap and stealthycoin April 8, 2021 20:48
@vz10 vz10 force-pushed the s3-tagging branch 2 times, most recently from b73e2ef to 925969e Compare April 9, 2021 12:09
@codecov-io
Copy link
Copy Markdown

codecov-io commented Apr 9, 2021

Codecov Report

Merging #6079 (925969e) into v2 (4c670bd) will increase coverage by 0.00%.
The diff coverage is 96.66%.

❗ Current head 925969e differs from pull request most recent head a631bec. Consider uploading reports for the commit a631bec to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##               v2    #6079   +/-   ##
=======================================
  Coverage   93.85%   93.85%           
=======================================
  Files         271      271           
  Lines       21550    21574   +24     
=======================================
+ Hits        20225    20248   +23     
- Misses       1325     1326    +1     
Impacted Files Coverage Δ
awscli/customizations/s3/subscribers.py 98.18% <96.15%> (-0.32%) ⬇️
awscli/customizations/s3/s3handler.py 97.78% <100.00%> (+0.01%) ⬆️
awscli/customizations/s3/subcommands.py 97.24% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c670bd...a631bec. Read the comment docs.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 19, 2021

Codecov Report

Merging #6079 (c573f2b) into v2 (51a9f77) will decrease coverage by 0.05%.
The diff coverage is 97.43%.

❗ Current head c573f2b differs from pull request most recent head 5beb9e3. Consider uploading reports for the commit 5beb9e3 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##               v2    #6079      +/-   ##
==========================================
- Coverage   94.20%   94.14%   -0.06%     
==========================================
  Files         273      271       -2     
  Lines       21780    21580     -200     
==========================================
- Hits        20518    20317     -201     
- Misses       1262     1263       +1     
Impacted Files Coverage Δ
awscli/customizations/s3/subscribers.py 98.21% <96.96%> (-0.32%) ⬇️
awscli/customizations/s3/s3handler.py 97.80% <100.00%> (+0.09%) ⬆️
awscli/customizations/s3/subcommands.py 97.24% <100.00%> (+0.01%) ⬆️
awscli/customizations/configure/list.py 91.93% <0.00%> (-1.62%) ⬇️
awscli/autoprompt/prompttoolkit.py 96.58% <0.00%> (-0.99%) ⬇️
awscli/utils.py 93.75% <0.00%> (-0.51%) ⬇️
awscli/formatter.py 95.75% <0.00%> (-0.48%) ⬇️
awscli/customizations/s3/transferconfig.py 98.11% <0.00%> (-0.46%) ⬇️
awscli/argprocess.py 94.28% <0.00%> (-0.07%) ⬇️
awscli/errorhandler.py 98.82% <0.00%> (-0.07%) ⬇️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 51a9f77...5beb9e3. Read the comment docs.

Copy link
Copy Markdown
Contributor

@kyleknap kyleknap left a comment

Choose a reason for hiding this comment

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

Looks like a good start. Just had some general comments/questions.

Comment thread awscli/customizations/s3/subcommands.py Outdated
},
'help_text': (
'The tag-set for the result object. The tag-set must be encoded '
'as URL Query parameters. (For example, "Key1=Value1") '
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking at the code, it looks like we are already are handling the url encoding? It might make sense to change the wording here to The tag-set must be provided as a key-value pair (e.g. "Key1=Value1,Key2=Value2")

{
"type": "enhancement",
"category": "``s3``",
"description": "Add --tagging option to ``s3 cp`` and ``s3 sync`` commands"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also include the feature request: #2458 in the changelog so it is easy to trace back to which version it got installed in. Sort of similar to what we did in the 2.0.0 entry: https://github.com/aws/aws-cli/blob/v2/CHANGELOG.rst#200.

We should also include mention of the merge tagging feature to help trace that back too.

Comment thread awscli/customizations/s3/s3handler.py Outdated
if self._cli_params.get('is_move', False):
subscribers.append(DeleteCopySourceObjectSubscriber(
fileinfo.source_client))
if self._cli_params.get('tagging', False):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably checking on if tagging is None. Otherwise, I can see users trying to clear the tags using an empty dictionary and get confused why that does not clear the pre-existing tag set (even though they should probably just use --copy-props):

$ aws s3 cp s3://bucket/setup.py2 s3://bucket/setup.py3 --tagging "{}"
copy: s3://bucket/setup.py2 to s3://bucket/setup.py3
$ aws s3api get-object-tagging --bucket bucket --key setup.py3
{
    "TagSet": [
        {
            "Key": "MyKey",
            "Value": "foo"
        },
        {
            "Key": "MyKe0y",
            "Value": "val"
        }
    ]
}

Comment on lines +449 to +436
self._transfer_manager.client,
self._transfer_manager.config,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With the CRT updates, we may have to rework how we get the client and transfer config. The CRT Transfer manager does not dangle the client nor the config off of the TransferManager (e.g. it does not have a botocore client associated to it and has its config options specified directly in its transfer client). I'll see if I can come up with ideas on how to approach this later.

subscribers.append(DeleteCopySourceObjectSubscriber(
fileinfo.source_client))
if self._cli_params.get('tagging', False):
subscribers.append(SetTagsSubscriber(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like this only works for copies? I'd imagine we would want to introduce these subscribers for uploads as well?

Comment thread awscli/customizations/s3/subcommands.py Outdated


TAGGING_DIRECTIVE = {
'name': 'tagging-directive',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What was the rationale on moving away from --merge-tagging or --merge-tags and having that be a boolean flag? I'm a little hesitant in using --tagging-directive because it shadows the API parameter and has different value and semantics, which could be confusing to customers. Also the name --merge-tagging/--merge-tags does a better job of self-documenting what it does then --tagging-directive.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The main reason was to leave space for other merging strategies if we decide to add them

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah so I was thinking we would model it similar to --sse where at first it had an action of store_true and then expanded it to allow nargs of ?:

'name': 'sse', 'nargs': '?', 'const': 'AES256',
'choices': ['AES256', 'aws:kms'],
So for --merge-tagging it's presence would equate the logic for this parameter's merge. Then when we add other merge strategies, we would switch it to be nargs=? and have choices like this (we could figure out good names for them later when we implement them):

  1. override - This is the default value for --merge-tagging
    aws s3 cp s3://bucket/object s3://bucket/object2 --tagging Key=value --merge-tagging override
    
  2. only-missing - This would do the option of only adding tags that were missing from the source object
    aws s3 cp s3://bucket/object s3://bucket/object2 --tagging Key=value --merge-tagging only-missing
    
  3. only-existing - This would do the option of only updating tag values if the key exist
    aws s3 cp s3://bucket/object s3://bucket/object2 --tagging Key=value --merge-tagging only-existing
    

How does that sound?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good

for i, actual_subscriber in enumerate(actual_subscribers):
self.assertIsInstance(actual_subscriber, ref_subscribers[i])

def test_tagging_option_adds_set_tag_subscriber(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be nice if we can get functional tests for this feature as it would serve a nice safety net in case we ever refactor all of these abstractions. I'd say we can do something similar to what we did for copy props functional tests: https://github.com/aws/aws-cli/blob/v2/tests/functional/s3/test_cp_command.py#L1349

And I say at the very least we should have a case for:

  • When --tagging is provided for copies
  • When --tagging is provided for uploads (both small and multipart uploads)
  • When --merge-tagging and --tagging is provided

@vz10 vz10 force-pushed the s3-tagging branch 3 times, most recently from 895450b to d2482c6 Compare April 21, 2021 16:00
@kdaily kdaily added the contribution:core This is a PR that came from AWS. label Apr 22, 2021
@vz10 vz10 force-pushed the s3-tagging branch 2 times, most recently from 8790f79 to c573f2b Compare April 22, 2021 21:34
@willkara
Copy link
Copy Markdown

willkara commented Jun 3, 2021

Hello, any updates on merging this into the main branch for distribution? I can help test if needed.

@ReidWeb
Copy link
Copy Markdown

ReidWeb commented Jul 18, 2021

Would really appreciate if this were reviewed soon, linked issue details the use case. This has downstream impacts on CDK s3-deployment that I need to resolve.

@raelga
Copy link
Copy Markdown

raelga commented Apr 12, 2022

Any updates on this PR? Can we help in anyway to get this PR merged and close the #2458, opened half a decade ago?

@jbgomond
Copy link
Copy Markdown

Hi ! +1, any news ? :)

@kdaily kdaily linked an issue May 18, 2022 that may be closed by this pull request
@sammcj
Copy link
Copy Markdown

sammcj commented Oct 24, 2022

Any update on getting this merged in, we need to be able to create tags on objects at the time they're uploaded (cp).

@willkara
Copy link
Copy Markdown

@kyleknap / @justindho anything? It's been open for years and no one's touched it yet.

Why can't we get this merged in or reviewed?

@allan-simon
Copy link
Copy Markdown

@elysahall @kyleknap , is there anything I can do to help move this PR forward ? To have the ability to put tags direcly with s3 command is an important use case for us and this PR would help us a lot

@willkara
Copy link
Copy Markdown

@justindho any updates? This PR has been open for a while, not sure why it's taking so long?

@syed-farazahmed
Copy link
Copy Markdown

@kyleknap @stealthycoin hi guys, do we have any update on this PR approval?

@azhong-git
Copy link
Copy Markdown

+1 , any update on this

@willkara
Copy link
Copy Markdown

It's gotta be lazy devs, it's been open for a few years at this point and is a HUGE QoL change.

@kyleknap are you still on GitHub?

@tim-finnigan
Copy link
Copy Markdown
Contributor

Upon bringing this PR up for discussion with the team, the decision was made to close this as not planned at this time due to higher-priority issues involving S3 commands. The team is continuing to track the corresponding feature request (#2458) and may revisit the changes proposed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution:core This is a PR that came from AWS. ready-for-review s3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add tagging support to s3