pellegrinimarcos / plsql-utils

Automatically exported from code.google.com/p/plsql-utils
0 stars 0 forks source link

AMAZON_AWS_S3_PKG - add Delete Bucket function (enhancement) #14

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This allows the caller to delete a bucket.

One thing I found when testing was that if the bucket is not in the US standard 
region, Amazon seems to respond with a TemporaryRedirect error. If the same 
request is re-requested to the indicated URL it works. To implement this, I 
made a small change to check_for_errors (both versions) - refer to the code 
between the "jkemp" comments.

--SPEC--

  procedure delete_bucket (p_bucket_name in varchar2);

--BODY--

  e_TemporaryRedirect      EXCEPTION;

procedure check_for_errors (p_clob in clob)
as
  l_xml xmltype;
begin

  /*

  Purpose:   check for errors (clob)

  Remarks:

  Who     Date        Description
  ------  ----------  -------------------------------------
  MBR     15.01.2011  Created

  */

  if (p_clob is not null) and (length(p_clob) > 0) then

    l_xml := xmltype (p_clob);

    if l_xml.existsnode('/Error') = 1 then

-- jkemp
      IF l_xml.extract('/Error/Code/text()').getStringVal = 'TemporaryRedirect' THEN
        debug_pkg.print('TemporaryRedirect');
        RAISE e_TemporaryRedirect;
      END IF;
-- jkemp

      raise_error (l_xml.extract('/Error/Message/text()').getstringval());
    end if;

  end if;

end check_for_errors;

procedure check_for_errors (p_xml in xmltype)
as
begin

  /*

  Purpose:   check for errors (XMLType)

  Remarks:

  Who     Date        Description
  ------  ----------  -------------------------------------
  MBR     15.01.2011  Created

  */

  if p_xml.existsnode('/Error') = 1 then

-- jkemp
    IF p_xml.extract('/Error/Code/text()').getStringVal = 'TemporaryRedirect' THEN
      debug_pkg.print('TemporaryRedirect');
      RAISE e_TemporaryRedirect;
    END IF;
-- jkemp

    raise_error (p_xml.extract('/Error/Message/text()').getstringval());
  end if;

end check_for_errors;

procedure delete_bucket (p_bucket_name in varchar2)
as

  l_clob                         clob;
  l_xml                          xmltype;

  l_date_str                     varchar2(255);
  l_auth_str                     varchar2(255);

  l_header_names                 t_str_array := t_str_array();
  l_header_values                t_str_array := t_str_array();

  l_endpoint                     VARCHAR2(255);

begin

  /*

  Purpose:   delete bucket

  Remarks:

  Who     Date        Description
  ------  ----------  -------------------------------------
  JKEMP   09.08.2012  Created

  */

  l_date_str := amazon_aws_auth_pkg.get_date_string;
  l_auth_str := amazon_aws_auth_pkg.get_auth_string ('DELETE' || chr(10) || chr(10) || chr(10) || l_date_str || chr(10) || '/' || p_bucket_name || '/');

  l_header_names.extend;
  l_header_names(1) := 'Host';
  l_header_values.extend;
  l_header_values(1) := get_host(p_bucket_name);

  l_header_names.extend;
  l_header_names(2) := 'Date';
  l_header_values.extend;
  l_header_values(2) := l_date_str;

  l_header_names.extend;
  l_header_names(3) := 'Authorization';
  l_header_values.extend;
  l_header_values(3) := l_auth_str;

  l_clob := make_request (get_url(p_bucket_name), 'DELETE', l_header_names, l_header_values);

  l_xml := xmltype (l_clob);
  check_for_errors (l_xml);

EXCEPTION
  WHEN e_TemporaryRedirect THEN

    l_endpoint := l_xml.extract('/Error/Endpoint/text()').getStringVal;

    l_clob := make_request ('http://' || l_endpoint || '/', 'DELETE', l_header_names, l_header_values);

    check_for_errors(l_clob);

end delete_bucket;

Original issue reported on code.google.com by jeffrey....@jk64.com on 16 Aug 2012 at 12:25

GoogleCodeExporter commented 8 years ago

Original comment by thehunge...@gmail.com on 16 Aug 2012 at 2:18

GoogleCodeExporter commented 8 years ago
Feature implemented in latest version of library.

Original comment by thehunge...@gmail.com on 17 Feb 2013 at 9:20