|
54 | 54 | get_object,
|
55 | 55 | upload_object,
|
56 | 56 | )
|
| 57 | +from linodecli.plugins.obj.website import ( |
| 58 | + disable_static_site, |
| 59 | + enable_static_site, |
| 60 | + static_site_info, |
| 61 | +) |
57 | 62 |
|
58 | 63 | try:
|
59 | 64 | import boto3
|
@@ -260,97 +265,6 @@ def set_acl(get_client, args):
|
260 | 265 | print("ACL updated")
|
261 | 266 |
|
262 | 267 |
|
263 |
| -def enable_static_site(get_client, args): |
264 |
| - """ |
265 |
| - Turns a bucket into a static website |
266 |
| - """ |
267 |
| - parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " ws-create")) |
268 |
| - |
269 |
| - parser.add_argument( |
270 |
| - "bucket", |
271 |
| - metavar="BUCKET", |
272 |
| - type=str, |
273 |
| - help="The bucket to turn into a static site", |
274 |
| - ) |
275 |
| - parser.add_argument( |
276 |
| - "--ws-index", |
277 |
| - metavar="INDEX", |
278 |
| - required=True, |
279 |
| - type=str, |
280 |
| - help="The file to serve as the index of the website", |
281 |
| - ) |
282 |
| - parser.add_argument( |
283 |
| - "--ws-error", |
284 |
| - metavar="ERROR", |
285 |
| - type=str, |
286 |
| - help="The file to serve as the error page of the website", |
287 |
| - ) |
288 |
| - |
289 |
| - parsed = parser.parse_args(args) |
290 |
| - client = get_client() |
291 |
| - bucket = parsed.bucket |
292 |
| - |
293 |
| - # make the site |
294 |
| - print(f"Setting bucket {bucket} access control to be 'public-read'") |
295 |
| - |
296 |
| - client.put_bucket_acl( |
297 |
| - Bucket=bucket, |
298 |
| - ACL="public-read", |
299 |
| - ) |
300 |
| - |
301 |
| - index_page = parsed.ws_index |
302 |
| - |
303 |
| - ws_config = {"IndexDocument": {"Suffix": index_page}} |
304 |
| - if parsed.ws_error: |
305 |
| - ws_config["ErrorDocument"] = {"Key": parsed.ws_error} |
306 |
| - |
307 |
| - client.put_bucket_website( |
308 |
| - Bucket=bucket, |
309 |
| - WebsiteConfiguration=ws_config, |
310 |
| - ) |
311 |
| - |
312 |
| - print( |
313 |
| - "Static site now available at " |
314 |
| - f"{BASE_WEBSITE_TEMPLATE.format(cluster=client.cluster, bucket=bucket)}" |
315 |
| - "\nIf you still can't access the website, please check the " |
316 |
| - "Access Control List setting of the website related objects (files) " |
317 |
| - "in your bucket." |
318 |
| - ) |
319 |
| - |
320 |
| - |
321 |
| -def static_site_info(get_client, args): |
322 |
| - """ |
323 |
| - Returns info about a configured static site |
324 |
| - """ |
325 |
| - parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " ws-info")) |
326 |
| - |
327 |
| - parser.add_argument( |
328 |
| - "bucket", |
329 |
| - metavar="BUCKET", |
330 |
| - type=str, |
331 |
| - help="The bucket to return static site information on.", |
332 |
| - ) |
333 |
| - |
334 |
| - parsed = parser.parse_args(args) |
335 |
| - client = get_client() |
336 |
| - |
337 |
| - bucket = parsed.bucket |
338 |
| - |
339 |
| - response = client.get_bucket_website(Bucket=bucket) |
340 |
| - |
341 |
| - index = response.get("IndexDocument", {}).get("Suffix", "Not Configured") |
342 |
| - error = response.get("ErrorDocument", {}).get("Key", "Not Configured") |
343 |
| - |
344 |
| - endpoint = BASE_WEBSITE_TEMPLATE.format( |
345 |
| - cluster=client.cluster, bucket=bucket |
346 |
| - ) |
347 |
| - |
348 |
| - print(f"Bucket {bucket}: Website configuration") |
349 |
| - print(f"Website endpoint: {endpoint}") |
350 |
| - print(f"Index document: {index}") |
351 |
| - print(f"Error document: {error}") |
352 |
| - |
353 |
| - |
354 | 268 | def show_usage(get_client, args):
|
355 | 269 | """
|
356 | 270 | Shows space used by all buckets in this cluster, and total space
|
@@ -437,30 +351,6 @@ def list_all_objects(get_client, args):
|
437 | 351 | sys.exit(0)
|
438 | 352 |
|
439 | 353 |
|
440 |
| -def disable_static_site(get_client, args): |
441 |
| - """ |
442 |
| - Disables static site for a bucket |
443 |
| - """ |
444 |
| - parser = inherit_plugin_args(ArgumentParser(PLUGIN_BASE + " du")) |
445 |
| - |
446 |
| - parser.add_argument( |
447 |
| - "bucket", |
448 |
| - metavar="BUCKET", |
449 |
| - type=str, |
450 |
| - nargs="?", |
451 |
| - help="The bucket to disable static site for.", |
452 |
| - ) |
453 |
| - |
454 |
| - parsed = parser.parse_args(args) |
455 |
| - client = get_client() |
456 |
| - |
457 |
| - bucket = parsed.bucket |
458 |
| - |
459 |
| - client.delete_bucket_website(Bucket=bucket) |
460 |
| - |
461 |
| - print(f"Website configuration deleted for {parsed.bucket}") |
462 |
| - |
463 |
| - |
464 | 354 | COMMAND_MAP = {
|
465 | 355 | "mb": create_bucket,
|
466 | 356 | "rb": delete_bucket,
|
|
0 commit comments