Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3-credentials list-buckets --details should show region and website URL, if configured #77

Closed
simonw opened this issue Aug 12, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Aug 12, 2022

Could also return that URL from the s3-credentials list-buckets --details command - which would then also need to be able to figure out what region the bucket is in.

Originally posted by @simonw in #21 (comment)

@simonw
Copy link
Owner Author

simonw commented Aug 12, 2022

Prototype:

@@ -730,6 +755,9 @@ def list_buckets(buckets, details, nl, csv, tsv, **boto_options):
                     ).items()
                     if key != "ResponseMetadata"
                 )
+                region = s3.get_bucket_location(Bucket=bucket["Name"])["LocationConstraint"]
                 try:
                     pab = s3.get_public_access_block(
                         Bucket=bucket["Name"],
@@ -746,6 +774,7 @@ def list_buckets(buckets, details, nl, csv, tsv, **boto_options):
                     )
                 except s3.exceptions.ClientError:
                     bucket_website = None
+                bucket["region"] = region
                 bucket["bucket_acl"] = bucket_acl
                 bucket["public_access_block"] = pab
                 bucket["bucket_website"] = bucket_website

I'm seeing null for my buckets. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.get_bucket_location explains why:

Buckets in Region us-east-1 have a LocationConstraint of null.

@simonw simonw closed this as completed in e9c2fb7 Aug 12, 2022
@simonw simonw added the enhancement New feature or request label Aug 12, 2022
simonw added a commit that referenced this issue Aug 12, 2022
@simonw
Copy link
Owner Author

simonw commented Aug 12, 2022

Example output:

% s3-credentials list-buckets sfms-history sfms-slides --details 
[
  {
    "Name": "sfms-history",
    "CreationDate": "2022-06-28 17:55:10+00:00",
    "region": "us-east-1",
    "bucket_acl": {
      "Owner": {
        "DisplayName": "swillison",
        "ID": "36b2eeee501c5952a8ac119f9e5212277a4c01eccfa8d6a9d670bba1e2d5f441"
      },
      "Grants": [
        {
          "Grantee": {
            "DisplayName": "swillison",
            "ID": "36b2eeee501c5952a8ac119f9e5212277a4c01eccfa8d6a9d670bba1e2d5f441",
            "Type": "CanonicalUser"
          },
          "Permission": "FULL_CONTROL"
        }
      ]
    },
    "public_access_block": null,
    "bucket_website": null
  },
  {
    "Name": "sfms-slides",
    "CreationDate": "2022-08-12 15:45:24+00:00",
    "region": "us-east-1",
    "bucket_acl": {
      "Owner": {
        "DisplayName": "swillison",
        "ID": "36b2eeee501c5952a8ac119f9e5212277a4c01eccfa8d6a9d670bba1e2d5f441"
      },
      "Grants": [
        {
          "Grantee": {
            "DisplayName": "swillison",
            "ID": "36b2eeee501c5952a8ac119f9e5212277a4c01eccfa8d6a9d670bba1e2d5f441",
            "Type": "CanonicalUser"
          },
          "Permission": "FULL_CONTROL"
        }
      ]
    },
    "public_access_block": null,
    "bucket_website": {
      "IndexDocument": {
        "Suffix": "index.html"
      },
      "ErrorDocument": {
        "Key": "error.html"
      },
      "url": "http://sfms-slides.s3-website.us-east-1.amazonaws.com/"
    }
  }
]

simonw added a commit that referenced this issue Aug 12, 2022
The number of API calls increased with:
- #77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant