-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
cloudfront create-invalidation --paths #1662
Merged
rayluo
merged 7 commits into
aws:develop
from
rayluo:cloudfront-create-invalidation-paths
Dec 8, 2015
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd0edd4
cloudfront create-invalidation --paths
rayluo 0fbdab2
Cloudfront is currently still in preview mode
rayluo 27bf7c2
Adjust documentation
rayluo 990e95e
Make the CallerReference random
rayluo 1546327
Improve documentation
rayluo d7c1095
Use mock.ANY in test
rayluo 4169450
Add CHANGELOG
rayluo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,51 @@ | ||
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
import time | ||
import random | ||
|
||
from awscli.arguments import CustomArgument | ||
from awscli.customizations.utils import validate_mutually_exclusive_handler | ||
|
||
|
||
def register(event_handler): | ||
"""Provides a simpler --paths for ``aws cloudfront create-invalidation``""" | ||
|
||
event_handler.register( | ||
'building-argument-table.cloudfront.create-invalidation', _add_paths) | ||
event_handler.register( | ||
'operation-args-parsed.cloudfront.create-invalidation', | ||
validate_mutually_exclusive_handler(['invalidation_batch'], ['paths'])) | ||
|
||
|
||
def _add_paths(argument_table, **kwargs): | ||
argument_table['invalidation-batch'].required = False | ||
argument_table['paths'] = PathsArgument() | ||
|
||
|
||
class PathsArgument(CustomArgument): | ||
|
||
def __init__(self): | ||
doc = ( | ||
'The space-separated paths to be invalidated.' | ||
' Note: --invalidation-batch and --paths are mututally exclusive.' | ||
) | ||
super(PathsArgument, self).__init__('paths', nargs='+', help_text=doc) | ||
|
||
def add_to_params(self, parameters, value): | ||
if value is not None: | ||
caller_reference = 'cli-%s-%s' % ( | ||
int(time.time()), random.randint(1, 1000000)) | ||
parameters['InvalidationBatch'] = { | ||
"CallerReference": caller_reference, | ||
"Paths": {"Quantity": len(value), "Items": value}, | ||
} |
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,52 @@ | ||
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
import mock | ||
|
||
from awscli.testutils import BaseAWSPreviewCommandParamsTest as \ | ||
BaseAWSCommandParamsTest | ||
|
||
|
||
class TestCreateInvalidation(BaseAWSCommandParamsTest): | ||
|
||
prefix = 'cloudfront create-invalidation --distribution-id my_id ' | ||
|
||
def test_invalidation_batch_only(self): | ||
batch = "Paths={Quantity=2,Items=[foo.txt,bar.txt]},CallerReference=ab" | ||
cmdline = self.prefix + '--invalidation-batch ' + batch | ||
result = { | ||
'DistributionId': 'my_id', | ||
'InvalidationBatch': { | ||
'Paths': {'Items': ['foo.txt', 'bar.txt'], 'Quantity': 2}, | ||
'CallerReference': 'ab', | ||
}, | ||
} | ||
self.assert_params_for_cmd(cmdline, result) | ||
|
||
def test_paths_only(self): | ||
cmdline = self.prefix + '--paths index.html foo.txt' | ||
result = { | ||
'DistributionId': 'my_id', | ||
'InvalidationBatch': { | ||
'Paths': {'Items': ['index.html', 'foo.txt'], 'Quantity': 2}, | ||
'CallerReference': mock.ANY, | ||
}, | ||
} | ||
self.run_cmd(cmdline) | ||
self.assertEqual(self.last_kwargs, result) | ||
|
||
def test_invalidation_batch_and_paths(self): | ||
cmdline = self.prefix + '--invalidation-batch {} --paths foo' | ||
self.run_cmd(cmdline, expected_rc=255) | ||
|
||
def test_neither_invalidation_batch_or_paths(self): | ||
self.run_cmd(self.prefix, expected_rc=255) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
PEP8. Use two blank lines.
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.
Thanks. Done.