-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the BucketHttpsConfig interface (#383)
- Loading branch information
1 parent
16b66c0
commit ed7d77b
Showing
7 changed files
with
221 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
import oss2 | ||
|
||
# Specify access information, such as AccessKeyId, AccessKeySecret, and Endpoint. | ||
# You can obtain access information from evironment variables or replace sample values in the code, such as <your AccessKeyId> with actual values. | ||
# | ||
# For example, if your bucket is located in the China (Hangzhou) region, you can set Endpoint to one of the following values: | ||
# http://oss-cn-hangzhou.aliyuncs.com | ||
# https://oss-cn-hangzhou.aliyuncs.com | ||
from oss2.models import BucketTlsVersion | ||
|
||
access_key_id = os.getenv('OSS_TEST_ACCESS_KEY_ID', '<yourAccessKeyId>') | ||
access_key_secret = os.getenv('OSS_TEST_ACCESS_KEY_SECRET', '<yourAccessKeySecret>') | ||
bucket_name = os.getenv('OSS_TEST_BUCKET', '<yourBucketName>') | ||
endpoint = os.getenv('OSS_TEST_ENDPOINT', '<yourEndpoint>') | ||
|
||
|
||
# Make sure that all parameters are correctly configured | ||
for param in (access_key_id, access_key_secret, bucket_name, endpoint): | ||
assert '<' not in param, 'Please set parameters:' + param | ||
|
||
|
||
# Create a bucket. You can use the bucket to call all object-related operations | ||
bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name) | ||
|
||
# Configure transfer acceleration for the bucket. | ||
# If enabled is set to true, transfer acceleration is enabled. If enabled is set to false, transfer acceleration is disabled. | ||
https_config = BucketTlsVersion(True, ['TLSv1.2', 'TLSv1.3']) | ||
bucket.put_bucket_https_config(https_config) | ||
|
||
# Query the transfer acceleration status of the bucket. | ||
# If the returned value is true, the transfer acceleration feature is enabled for the bucket. If the returned value is false, the transfer acceleration feature is disabled for the bucket. | ||
result = bucket.get_bucket_https_config() | ||
print("Return information on whether to enable TLS version settings: {0}".format(result.tls_enabled)) | ||
print("Return TLS version number: {0}".format(result.tls_version)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from oss2.models import BucketTlsVersion | ||
from .common import * | ||
|
||
class TestHttpsConfig(OssTestCase): | ||
def test_https_config_normal(self): | ||
https_config = BucketTlsVersion(True, ['TLSv1.2', 'TLSv1.3']) | ||
result = self.bucket.put_bucket_https_config(https_config) | ||
self.assertEqual(200, result.status) | ||
|
||
result2 = self.bucket.get_bucket_https_config() | ||
self.assertEqual(200, result2.status) | ||
self.assertEqual(result2.tls_enabled, True) | ||
self.assertListEqual(result2.tls_version, ['TLSv1.2', 'TLSv1.3']) | ||
|
||
https_config2 = BucketTlsVersion() | ||
result3 = self.bucket.put_bucket_https_config(https_config2) | ||
self.assertEqual(200, result3.status) | ||
|
||
result4 = self.bucket.get_bucket_https_config() | ||
self.assertEqual(200, result4.status) | ||
self.assertEqual(result4.tls_enabled, False) | ||
self.assertListEqual(result4.tls_version, []) | ||
|
||
|
||
def test_https_config_exception_1(self): | ||
try: | ||
https_config = BucketTlsVersion(True) | ||
self.bucket.put_bucket_https_config(https_config) | ||
self.assertTrue(False) | ||
except oss2.exceptions.ServerError as e: | ||
self.assertEqual(e.code, 'MalformedXML') | ||
|
||
def test_https_config_exception_2(self): | ||
try: | ||
https_config = BucketTlsVersion(True, ['aaa', 'bbb']) | ||
self.bucket.put_bucket_https_config(https_config) | ||
self.assertTrue(False) | ||
except oss2.exceptions.ServerError as e: | ||
self.assertEqual(e.code, 'MalformedXML') | ||
|
||
def test_https_config_exception_3(self): | ||
https_config = BucketTlsVersion(True, ['TLSv1.2', 'TLSv1.2']) | ||
result = self.bucket.put_bucket_https_config(https_config) | ||
self.assertEqual(200, result.status) | ||
|
||
result2 = self.bucket.get_bucket_https_config() | ||
self.assertEqual(200, result2.status) | ||
self.assertEqual(result2.tls_enabled, True) | ||
self.assertListEqual(result2.tls_version, ['TLSv1.2']) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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