Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
orenc17 committed Oct 19, 2024
1 parent bb40d32 commit c01966d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
19 changes: 10 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ def parse_responses(responses: list, s3_client: botocore.client.BaseClient, buck
return sorted(contents_list, key=lambda x: x.type, reverse=True)


def list_objects(s3_client: botocore.client.BaseClient, bucket_name: str, path: str, delimiter: str = ''):
def list_objects(s3_client: botocore.client.BaseClient, bucket_name: str, path: str, delimiter: str = "") -> list[dict]:
responses = []
list_params = {'Bucket': bucket_name, 'Prefix': path}
list_params = {"Bucket": bucket_name, "Prefix": path}
if delimiter:
list_params['Delimiter'] = '/'
list_params["Delimiter"] = "/"

while True:
response = s3_client.list_objects_v2(**list_params)
responses.append(response)
if response['IsTruncated']:
list_params['ContinuationToken'] = response['NextContinuationToken']
if response["IsTruncated"]:
list_params["ContinuationToken"] = response["NextContinuationToken"]
else:
break

Expand All @@ -111,7 +111,7 @@ def search_bucket(bucket_name: str, path: str) -> str:
responses = []
try:
responses.extend(list_objects(s3_client, bucket_name, path))
responses.extend(list_objects(s3_client, bucket_name, path, '/'))
responses.extend(list_objects(s3_client, bucket_name, path, "/"))
except botocore.exceptions.ClientError as e:
match e.response["Error"]["Code"]:
case "AccessDenied":
Expand All @@ -126,7 +126,8 @@ def search_bucket(bucket_name: str, path: str) -> str:
except Exception as e: # noqa: BLE001
return render_template("error.html", error=f"An unknown error occurred: {e}")

search_param = request.args['search'] if 'search' in request.args else ''

search_param = request.args.get("search", "")
contents = parse_responses(responses, s3_client, bucket_name, search_param)
return render_template(
"bucket_contents.html",
Expand All @@ -143,7 +144,7 @@ def view_bucket(bucket_name: str, path: str) -> str:
s3_client = boto3.client("s3", **AWS_KWARGS)
responses = []
try:
responses.extend(list_objects(s3_client, bucket_name, path, '/'))
responses.extend(list_objects(s3_client, bucket_name, path, "/"))
except botocore.exceptions.ClientError as e:
match e.response["Error"]["Code"]:
case "AccessDenied":
Expand All @@ -158,7 +159,7 @@ def view_bucket(bucket_name: str, path: str) -> str:
except Exception as e: # noqa: BLE001
return render_template("error.html", error=f"An unknown error occurred: {e}")

search_param = request.args['search'] if 'search' in request.args else ''
search_param = request.args.get("search", "")
contents = parse_responses(responses, s3_client, bucket_name, search_param)
return render_template(
"bucket_contents.html",
Expand Down
12 changes: 5 additions & 7 deletions templates/bucket_contents.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@
<button class="btn waves-effect waves-light" type="submit" name="action">
Search
</button>
</form>
<h4>Contents of {{ bucket_name }}</h4>
<a href="{{ url_for('index') }}" class="btn-small blue">Back to Buckets</a>
{% if path %}
<a
href="{{ url_for('view_bucket', bucket_name=bucket_name, path=path.rstrip('/').rsplit('/', 1)[0] if '/' in path.rstrip('/') else '') }}"
<a href="{{ url_for('view_bucket', bucket_name=bucket_name, path=path.rstrip('/').rsplit('/', 1)[0] if '/' in path.rstrip('/') else '') }}"
class="btn-small">Go Up</a>
{% endif %}
<ul class="collection">
{% for item in contents %}
<li class="collection-item">
{% if item.type == "folder" %}
<a
href="{{ url_for('view_bucket', bucket_name=bucket_name, path=item.name) }}">{{
item.name }}</a>
{% else %} {{ item.date_modified }} | {{ item.size }} | <a
href="{{ item.url }}" target="_blank">{{ item.name }}</a>
<a href="{{ url_for('view_bucket', bucket_name=bucket_name, path=item.name) }}">{{ item.name }}</a>
{% else %}
{{ item.date_modified }} | {{ item.size }} | <a href="{{ item.url }}" target="_blank">{{ item.name }}</a>
{% endif %}
</li>
{% endfor %}
Expand Down

0 comments on commit c01966d

Please sign in to comment.