itory; edit this file to name it for gitweb.
summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/amazon_s3.pm
blob: 187700f30d911dee95009a7d2515ef3aca61e176 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::amazon_s3;
  3. use warnings;
  4. no warnings 'redefine';
  5. use strict;
  6. use IkiWiki 2.00;
  7. use IkiWiki::Render;
  8. use Net::Amazon::S3;
  9. # Store references to real subs before overriding them.
  10. our %subs;
  11. BEGIN {
  12. foreach my $sub (qw{IkiWiki::writefile IkiWiki::prune}) {
  13. $subs{$sub}=\&$sub;
  14. }
  15. };
  16. sub import { #{{{
  17. hook(type => "getopt", id => "amazon_s3", call => \&getopt);
  18. hook(type => "checkconfig", id => "amazon_s3", call => \&checkconfig);
  19. } # }}}
  20. sub getopt () { #{{{
  21. eval q{use Getopt::Long};
  22. error($@) if $@;
  23. Getopt::Long::Configure('pass_through');
  24. GetOptions("delete-bucket" => sub {
  25. my $bucket=getbucket();
  26. debug(gettext("deleting bucket.."));
  27. my $resp = $bucket->list_all or die $bucket->err . ": " . $bucket->errstr;
  28. foreach my $key (@{$resp->{keys}}) {
  29. debug("\t".$key->{key});
  30. $bucket->delete_key($key->{key}) or die $bucket->err . ": " . $bucket->errstr;
  31. }
  32. $bucket->delete_bucket or die $bucket->err . ": " . $bucket->errstr;
  33. debug(gettext("done"));
  34. exit(0);
  35. });
  36. } #}}}
  37. sub checkconfig { #{{{
  38. foreach my $field (qw{amazon_s3_key_id amazon_s3_key_file
  39. amazon_s3_bucket}) {
  40. if (! exists $config{$field} || ! defined $config{$field}) {
  41. error(sprintf(gettext("Must specify %s"), $field));
  42. }
  43. }
  44. if (! exists $config{amazon_s3_prefix} ||
  45. ! defined $config{amazon_s3_prefix}) {
  46. $config{amazon_s3_prefix}="wiki/";
  47. }
  48. } #}}}
  49. {
  50. my $bucket;