How to use get_bucket_website method in localstack

Best Python code snippet using localstack_python

bucket_website.py

Source:bucket_website.py Github

copy

Full Screen

...28error_file = 'error.html'29# 以下代码展示只设置主页与404页面的静态网站托管30bucket.put_bucket_website(BucketWebsite(index_file, error_file))31# 获取website配置32result = bucket.get_bucket_website()33print('get_bucket_website without redirect:')34print('result index_file:', result.index_file)35print('result error_file:', result.error_file)36bucket.delete_bucket_website()37# 以下代码展示镜像回源的网站托管配置,采用主备模式或者多站点模式38# 设置匹配规则39include_header1= ConditionInlcudeHeader('host', 'test.oss-cn-beijing-internal.aliyuncs.com')40include_header2 = ConditionInlcudeHeader('host', 'test.oss-cn-shenzhen-internal.aliyuncs.com')41condition1 = Condition(key_prefix_equals='key1', 42 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])43condition2 = Condition(key_prefix_equals='key2', 44 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])45# 设置跳转规则,46mirror_headers_set_1 = MirrorHeadersSet("myheader-key5","myheader-value5")47mirror_headers_set_2 = MirrorHeadersSet("myheader-key6","myheader-value6")48set_list = [mirror_headers_set_1, mirror_headers_set_2]49pass_list = ['myheader-key1', 'myheader-key2']50remove_list = ['myheader-key3', 'myheader-key4']51mirror_header = RedirectMirrorHeaders(pass_all=True, pass_list=pass_list, remove_list=remove_list, set_list=set_list)52# 使用主备源站模式, 使用mirror_url_slave,mirror_url_probe参数53redirect1 = Redirect(redirect_type=REDIRECT_TYPE_MIRROR, pass_query_string=False, mirror_url='http://www.test.com/', 54 mirror_url_slave='http://www.slave.com/', mirror_url_probe='http://www.test.com/index.html', mirror_pass_query_string=False, 55 mirror_follow_redirect=True, mirror_check_md5=True, mirror_headers=mirror_header)56# 不指定备站57redirect2 = Redirect(redirect_type=REDIRECT_TYPE_MIRROR, mirror_url='http://www.test.com/',58 mirror_pass_query_string=True, mirror_follow_redirect=True, mirror_check_md5=False)59# 可以设置一条或多条,本示例展示设置多条60rule1 = RoutingRule(rule_num=1, condition=condition1, redirect=redirect1)61rule2 = RoutingRule(rule_num=2, condition=condition2, redirect=redirect2)62website_set = BucketWebsite(index_file, error_file, [rule1, rule2])63bucket.put_bucket_website(website_set)64# 获取website配置65website_get = bucket.get_bucket_website()66print('get_bucket_website mirror type:')67print('indext_file:', website_get.index_file)68print('error_file:', website_get.error_file)69print('rule sum:', len(website_get.rules))70bucket.delete_bucket_website() 71# 以下代码展示阿里云CDN跳转以及外部跳转或者内部跳转的设置72include_header1= ConditionInlcudeHeader('host', 'test.oss-cn-beijing-internal.aliyuncs.com')73include_header2 = ConditionInlcudeHeader('host', 'test.oss-cn-shenzhen-internal.aliyuncs.com')74condition1 = Condition(key_prefix_equals='key3', 75 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])76condition2 = Condition(key_prefix_equals='key4', 77 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])78condition3 = Condition(key_prefix_equals='key5',79 http_err_code_return_equals=404, include_header_list=[include_header1, include_header2])80# AliCDN 81redirect1 = Redirect(redirect_type=REDIRECT_TYPE_ALICDN, pass_query_string=True, 82 replace_key_with='${key}.suffix', proto='http', http_redirect_code=302)83# External84redirect2 = Redirect(redirect_type=REDIRECT_TYPE_EXTERNAL, pass_query_string=False, replace_key_prefix_with='abc', 85 proto='https', host_name='oss.aliyuncs.com', http_redirect_code=302)86# Internal87redirect3 = Redirect(redirect_type=REDIRECT_TYPE_INTERNAL, pass_query_string=False, replace_key_with='${key}.suffix')88# 可以设置一条或多条规则,本示例展示设置多条89rule1 = RoutingRule(rule_num=1, condition=condition1, redirect=redirect1)90rule2 = RoutingRule(rule_num=2, condition=condition2, redirect=redirect2)91rule3 = RoutingRule(rule_num=3, condition=condition3, redirect=redirect3)92website_set = BucketWebsite(index_file, error_file, [rule1, rule2, rule3])93bucket.put_bucket_website(website_set)94# 获取website配置95website_get = bucket.get_bucket_website()96print('get_bucket_website other type:')97print('indext_file:', website_get.index_file)98print('error_file:', website_get.error_file)99print('rule sum:', len(website_get.rules))100for rule in website_get.rules:101 print('rule_num:{}, redirect_type:{}'.format(rule.rule_num, rule.redirect.redirect_type))...

Full Screen

Full Screen

test_main.py

Source:test_main.py Github

copy

Full Screen

...13 except ClientError:14 return False15def get_website_information(bucket_name):16 try:17 response = s3_client.get_bucket_website(Bucket=bucket_name)18 return True, response['RedirectAllRequestsTo']['HostName']19 except ClientError:20 return False, None21def get_encryption_information(bucket_name):22 try:23 s3_client.get_bucket_encryption(Bucket=bucket_name)24 return True25 except ClientError:26 return False27class TestingMain(unittest.TestCase):28 def test_format_two_decimal_points(self):29 self.assertEqual('123.00', format_two_decimal_points(123))30 self.assertEqual('12345.68', format_two_decimal_points(12345.6789))31 def test_get_public_access_information(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful