Browse Source

Make S3 response pattern matching more flexible (so it also works on Scaleway)

master
JustAnotherArchivist 2 years ago
parent
commit
95988466ec
1 changed files with 5 additions and 1 deletions
  1. +5
    -1
      s3-bucket-list

+ 5
- 1
s3-bucket-list View File

@@ -3,12 +3,16 @@ import html
import http.client import http.client
import json import json
import os import os
import re
import shlex import shlex
import ssl import ssl
import sys import sys
import urllib.parse import urllib.parse




RESPONSE_PATTERN = re.compile(r'''^<\?xml version=(["'])1\.0\1 encoding=(["'])UTF-8\2\?>''' '\n?' r'''<ListBucketResult xmlns=(["'])http://(?:s3\.amazonaws\.com/doc/2006-03-01/|doc\.s3\.amazonaws\.com/2006-03-01)\3>'''.encode('ascii'))


# Arguments # Arguments
i = 1 i = 1
withListUrls = False withListUrls = False
@@ -79,7 +83,7 @@ while True:
break break
attempt += 1 attempt += 1
continue continue
if not body.startswith(b'<?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">') and not body.startswith(b"<?xml version='1.0' encoding='UTF-8'?><ListBucketResult xmlns='http://doc.s3.amazonaws.com/2006-03-01'>"):
if not RESPONSE_PATTERN.match(body):
raise RuntimeError(f'Invalid body: {body[:200]}...') raise RuntimeError(f'Invalid body: {body[:200]}...')


if b'<Marker></Marker>' in body[:200] and 'marker' in params: if b'<Marker></Marker>' in body[:200] and 'marker' in params:


Loading…
Cancel
Save